Package java.io

Examples of java.io.LineNumberReader


  public static final void main(String[] args)
  {
    try {
      String dir = args.length>0 ? args[0] : "./";
      SymbolTool n = new SymbolTool(dir);
      LineNumberReader reader =
        new LineNumberReader(new InputStreamReader(System.in));
      int count = 0;
      for(;;) {
        String line = reader.readLine();
        if (line == null) {
          break;
        }
        n.update(line.trim());
        count++;
View Full Code Here


        }
        return val;
    }

    public boolean readSettingsFile() {
        LineNumberReader settingsReader = null;
        String line;

        // maybe restore a .bak of the .ini file
        if (settingsFile.isFile() == false || settingsFile.length() == 0 ) {
            // try to restore .bak file
            final String configDirStr = getValue(SettingsClass.DIR_CONFIG);
            final File bakFile = new File(configDirStr + "frost.ini.bak");
            if( bakFile.isFile() && bakFile.length() > 0 ) {
                bakFile.renameTo(settingsFile);
            } else {
                return false;
            }
        }

        try {
            settingsReader = new LineNumberReader(new FileReader(settingsFile));
        } catch (final Exception e) {
            logger.warning(settingsFile.getName() + " does not exist, will create it");
            return false;
        }
        try {
            while ((line = settingsReader.readLine()) != null) {
                line = line.trim();
                if (line.length() != 0 && line.startsWith("#") == false) {
                    final StringTokenizer strtok = new StringTokenizer(line, "=");
                    String key = "";
                    String value = "";
                    Object objValue = value;
                    if (strtok.countTokens() >= 2) {
                        key = strtok.nextToken().trim();
                        value = strtok.nextToken().trim();
                        // to allow '=' in values
                        while (strtok.hasMoreElements()) {
                            value += "=" + strtok.nextToken();
                        }
                        if (value.startsWith("type.color(") && value.endsWith(")")) {
                            // this is a color
                            final String rgbPart = value.substring(11, value.length() - 1);
                            final StringTokenizer strtok2 = new StringTokenizer(rgbPart, ",");

                            if (strtok2.countTokens() == 3) {
                                try {
                                    int red, green, blue;
                                    red = Integer.parseInt(strtok2.nextToken().trim());
                                    green = Integer.parseInt(strtok2.nextToken().trim());
                                    blue = Integer.parseInt(strtok2.nextToken().trim());
                                    final Color c = new Color(red, green, blue);
                                    objValue = c;
                                } catch (final Exception ex) {
                                    objValue = null;
                                }
                            } else {
                                objValue = null; // dont insert in settings, use default instead
                            }
                        }
                        // scan all path config values and set correct system file separator
                        else if key.equals(SettingsClass.DIR_TEMP)
                                || key.equals(DIR_LOCALDATA)
                                || key.equals(DIR_STORE)
                                || key.equals(DIR_DOWNLOAD)
                                || key.equals(DIR_LAST_USED)) {
                            value = setSystemFileSeparator(value);
                            objValue = value;
                        } else {
                            // 'old' behaviour
                            objValue = value;
                        }
                        if (objValue != null) {
                            settingsHash.put(key, objValue);
                        }
                    }
                }
            }
        } catch (final Exception e) {
            logger.log(Level.SEVERE, "Exception thrown in readSettingsFile()", e);
        }
        try {
            settingsReader.close();
        } catch (final Exception e) {
            logger.log(Level.SEVERE, "Exception thrown in readSettingsFile()", e);
        }

        doCleanup();
View Full Code Here


    public void run()
    {
      try {
        LineNumberReader reader = new LineNumberReader(new InputStreamReader(_input));
        PrintStream out = new PrintStream(_output);
        out.println("** Anvil "+anvil.Version.getFullVersion());
        out.println("** Copyright (c) 1999-2002, Njet Communications ltd. All rights reserved.");
        out.println("** Type 'help' for help");
       
        _self = _server;
       
        while(true) {
          if (out.checkError()) {
            break;
          }
          out.print(prompt(_self));
          String line = reader.readLine();
          if (line == null) {
            break;
          }
          try {
            if (action(out, line)) {
View Full Code Here

   */
  private String extractLineContent(EvalError e)
  {
    String lineContent = "";

    LineNumberReader reader = null;

    try
    {
      reader = new LineNumberReader(new StringReader(bshScript));
      int lineNumber = e.getErrorLineNumber();
     
      for(int i = 0; i < lineNumber; i++)
      {
        lineContent = reader.readLine();
      }
    }
    catch(IOException ioe)
    {
    }
    finally
    {
      if (reader != null)
      {
        try
        {
          reader.close();
        }
        catch(IOException ioe)
        {
        }
      }
View Full Code Here

    File file = new File("/Users/xgu/lucene29test/keywords");
    try
    {
      FileInputStream fis = new FileInputStream("/Users/xgu/lucene29test/bbb");
      InputStreamReader isr = new InputStreamReader(fis);
      LineNumberReader reader = new LineNumberReader(isr);
      String line;
      while( (line=reader.readLine())!=null)
      {
        wordlist.add(line);
      }
      words = wordlist.toArray(new String[1]);
    } catch (Exception e)
View Full Code Here

    String sLine, sOpCode = null, sEntity = null;

    TreeMap oOpen  = new TreeMap();
    Integer oCount;

    LineNumberReader lnr;

    FileReader oReader = new FileReader(sFile);
    BufferedReader oBuffer = new BufferedReader(oReader);
    LineNumberReader oLines = new LineNumberReader(oBuffer);

    while ((sLine = oLines.readLine())!=null) {
      f = 0;
      s = -1;
      while ((s=sLine.indexOf(';',s+1))!=-1) {
        f++;
        switch (f) {
          case 2:
            sOpCode = sLine.substring(s, sLine.indexOf(';', s+1));
            break;
          case 4:
            sEntity = sLine.substring(s, sLine.indexOf(';', s+1));

            if (sOpCode.equals("ODBC") || sOpCode.equals("OJSP")) {
              oCount = (Integer) oOpen.get(sEntity);
              if (oCount==null) {
                oCount = new Integer(1);
                oOpen.put(sEntity, oCount);
              }
              else {
                oCount = new Integer(oCount.intValue()+1);
                oOpen.remove(sEntity);
                oOpen.put(sEntity, oCount);
              }
            } // fi (sOpCode==ODBC)
            else if (sOpCode.equals("CDBC") || sOpCode.equals("CJSP")) {
              oCount = (Integer) oOpen.get(sEntity);
              if (oCount==null) {
                oCount = new Integer(-1);
                oOpen.put(sEntity, oCount);
              }
              else {
                oCount = new Integer(oCount.intValue()-1);
                oOpen.remove(sEntity);
                oOpen.put(sEntity, oCount);
              }
            }
            break;
        } // switch(f)
      } // wend
      if (f%10==0) System.out.print('.');
    } // wend

    System.out.print("\n");

    oReader.close();
    oLines.close();
    oBuffer.close();

    Iterator oKeys = oOpen.keySet().iterator();

    while (oKeys.hasNext()) {
View Full Code Here

     
      Map<String, String> map = new HashMap<String, String>();
      mimeTypeMap = Collections.unmodifiableMap(map);
     
      InputStreamReader isr = null;
      LineNumberReader lnr = null;
      try {
        isr = new InputStreamReader(ServerUtils.class.getResourceAsStream("/org/xsocket/connection/http/server/mime.types"));
        if (isr != null) {
          lnr = new LineNumberReader(isr);
          String line = null;
          do {
            line = lnr.readLine();
            if (line != null) {
              line = line.trim();
              if (!line.startsWith("#")) {
                StringTokenizer st = new StringTokenizer(line);
                if (st.hasMoreTokens()) {
                  String mimeType = st.nextToken();
                  while (st.hasMoreTokens()) {
                    String extension = st.nextToken();
                    map.put(extension, mimeType);
                     
                    if (LOG.isLoggable(Level.FINER)) {
                      LOG.finer("mapping " + extension + " -> " + mimeType + " added");
                    }
                  }
                } else {
                  if (LOG.isLoggable(Level.FINE)) {
                    LOG.fine("line " + line + "ignored");
                 
                }
              }
            }
          } while (line != null);
   
          lnr.close();
        }
      } catch (IOException ioe) {
        if (LOG.isLoggable(Level.FINE)) {
          LOG.fine("Error occured by reding version file " + ioe.toString());
        }
       
      } finally {
        try {
          if (lnr != null) {
            lnr.close();
          }
           
          if (isr != null) {
            isr.close();
          }
View Full Code Here

     
      Map<String, String> map = new HashMap<String, String>();
      mimeTypeMap = Collections.unmodifiableMap(map);
     
      InputStreamReader isr = null;
      LineNumberReader lnr = null;
      try {
        isr = new InputStreamReader(HttpUtils.class.getResourceAsStream("/org/xlightweb/mime.types"));
        if (isr != null) {
          lnr = new LineNumberReader(isr);
          String line = null;
          while (true) {
            line = lnr.readLine();
            if (line != null) {
              line = line.trim();
              if (!line.startsWith("#")) {
                StringTokenizer st = new StringTokenizer(line);
                if (st.hasMoreTokens()) {
                  String mimeType = st.nextToken();
                  while (st.hasMoreTokens()) {
                    String extension = st.nextToken();
                    map.put(extension, mimeType);
                     
                    if (LOG.isLoggable(Level.FINER)) {
                      LOG.finer("mapping " + extension + " -> " + mimeType + " added");
                    }
                  }
                } else {
                  if (LOG.isLoggable(Level.FINE)) {
                    LOG.fine("line " + line + "ignored");
                 
                }
              }
            } else {
              break;
            }
          }
   
          lnr.close();
        }
       
      } catch (Exception ioe) {
          // eat and log exception
        if (LOG.isLoggable(Level.FINE)) {
          LOG.fine("could not read mime.types. reason: " + ioe.toString());
        }       
       
      } finally {
        try {
          if (lnr != null) {
            lnr.close();
          }
           
          if (isr != null) {
            isr.close();
          }
View Full Code Here

   
    implementationVersion = "<unknown>";
    implementationDate = "<unknown>";
     
    InputStreamReader isr = null;
    LineNumberReader lnr = null;
   
    try {
      isr = new InputStreamReader(HttpUtils.class.getResourceAsStream("/org/xlightweb/version.txt"));
      if (isr != null) {
        lnr = new LineNumberReader(isr);
        String line = null;
   
        do {
          line = lnr.readLine();
          if (line != null) {
            if (line.startsWith("Implementation-Version=")) {
              implementationVersion = line.substring("Implementation-Version=".length(), line.length()).trim();
             
            } else if (line.startsWith("Implementation-Date=")) {
              implementationDate = line.substring("Implementation-Date=".length(), line.length()).trim();
             
            } else if (line.startsWith("Dependency.xSocket.Implementation-Version=")) {
                            xSocketImplementationVersion = line.substring("Dependency.xSocket.Implementation-Version=".length(), line.length()).trim();
                        }
          }
        } while (line != null);
       
        lnr.close();
      }
    } catch (Exception ioe) {
       
            implementationDate = "<unknown>";
            implementationVersion  = "<unknown>";
            xSocketImplementationVersion  = "<unknown>";
                   
      if (LOG.isLoggable(Level.FINE)) {
        LOG.fine("could not read version file. reason: " + ioe.toString());
      }       
     
    } finally {
      try {
        if (lnr != null) {
          lnr.close();
        }
         
        if (isr != null) {
          isr.close();
        }
View Full Code Here

      throw new IllegalArgumentException("base URI must not be 'null'");
    }

    rdfHandler.startRDF();

    lineReader = new LineNumberReader(reader);
    // Start counting lines at 1:
    lineReader.setLineNumber(1);

    // Allow at most 2 characters to be pushed back:
    this.reader = new PushbackReader(lineReader, 2);
View Full Code Here

TOP

Related Classes of java.io.LineNumberReader

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.