Package java.io

Examples of java.io.LineNumberReader


     
      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


   
    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

    FileChannel fc = raf.getChannel();
    response.getBody().transferTo(fc);
    fc.close();
    raf.close();

    LineNumberReader lnr = new LineNumberReader(new FileReader(file));
    String line = lnr.readLine();
   
    Assert.assertEquals("method= GET", line);
   
    file.delete();
    httpClient.close();
View Full Code Here

    // Start 'text' element, which the parser dispatch
    lexer.startElement("http://chaperon.sourceforge.net/schema/text/1.0", "text", "text",
                       new AttributesImpl());

    LineNumberReader reader =
      new LineNumberReader(new InputStreamReader(new FileInputStream(inFile)));

    String line;
    String newline = null;
    String separator = System.getProperty("line.separator");

    // Push text
    while (true)
    {
      if (newline==null)
        line = reader.readLine();
      else
        line = newline;

      if (line==null)
        break;

      newline = reader.readLine();

      line = (newline!=null) ? (line+separator) : line;

      locator.setLineNumber(reader.getLineNumber());
      locator.setColumnNumber(1);
      lexer.characters(line.toCharArray(), 0, line.length());

      if (newline==null)
        break;
    }

    reader.close();

    // End 'text' element
    lexer.endElement("http://chaperon.sourceforge.net/schema/text/1.0", "text", "text");

    // End document
View Full Code Here

    FileChannel fc = raf.getChannel();
    response.getBlockingBody().transferTo(fc);
    fc.close();
    raf.close();

    LineNumberReader lnr = new LineNumberReader(new FileReader(file));
    String line = lnr.readLine();
   
    Assert.assertEquals("method= GET", line);
   
    file.delete();
    httpClient.close();
View Full Code Here

           sb.append("name=" + name +"\r\n");
           sb.append("filename=" + filename +"\r\n");
           sb.append("contentType=" + contentType +"\r\n");
           sb.append("content=");
       
           LineNumberReader lnr = new LineNumberReader(new InputStreamReader(is));
           String line = null;
           try {
           do {
               line = lnr.readLine();
               if (line != null)  {
                   sb.append(line + "\r\n");
               }
           } while (line != null);
           } catch (IOException ioe) {
View Full Code Here

    void removeTest(String name) {

        File f    = new File(name);
        File fnew = new File(name + ".new");
       
        LineNumberReader read =  null;
        FileWriter write = null;

        try {
            read  = new LineNumberReader(new FileReader(f));
            write = new FileWriter(fnew);

            while (true) {
                String line = read.readLine();

                if (line == null) {
                    break;
                }

                if (line.startsWith("Profile.visit(")) {
                    int s = line.indexOf(';');

                    line = line.substring(s + 1);
                }

                write.write(line + ls);
            }

            read.close();
            read  = null;
            write.flush();
            write.close();
            write = null;

            File fbak = new File(name + ".bak");

            fbak.delete();
            f.renameTo(fbak);

            File fcopy = new File(name);

            fnew.renameTo(fcopy);
            fbak.delete();
        } catch (Exception e) {
            printError(e.getMessage());
        }
        finally {
            if(read != null) {
                try {
                    read.close();
                } catch (IOException e1) {
                }
            }
            if(write != null) {
                try {
View Full Code Here

        File   f    = new File(name);
        File   fnew = new File(name + ".new");
        String key  = name;

        key = key.replace('\\', '.');
        LineNumberReader read  = null;
        FileWriter       write    = null;

        try {
            read = new LineNumberReader(new FileReader(f));
            write    = new FileWriter(fnew);
            int              l        = 0;
            boolean          longline = false;

            while (true) {
                String line = read.readLine();

                if (line == null) {
                    break;
                }

                if (line.startsWith(" ")) {
                    int spaces = 0;

                    for (; spaces < line.length(); spaces++) {
                        if (line.charAt(spaces) != ' ') {
                            break;
                        }
                    }

                    if (spaces > 3 && testLine(line) &&!longline) {
                        line = "org.hsqldb.test.Profile.visit(\"" + key
                        + "\"," + l + "," + maxline + ");" + line;

                        l++;
                    } else if (isLongline(line)) {
                        longline = true;
                    } else {
                        longline = false;
                    }
                }

                write.write(line + ls);
            }

            read.close();
            read =  null;
            write.flush();
            write.close();
            write = null;

            File fbak = new File(name + ".bak");

            fbak.delete();
            f.renameTo(fbak);

            File fcopy = new File(name);

            fnew.renameTo(fcopy);
            fbak.delete();
        } catch (Exception e) {
            printError(e.getMessage());
        }
        finally {

            if(read != null) {
                try {
                    read.close();
                } catch (IOException e1) {
                }
            }
            if(write != null) {
                try {
View Full Code Here

     * @return
     */
    int testFile(String name) {

        File f = new File(name);
        LineNumberReader read = null;

        try {
            read = new LineNumberReader(new FileReader(f));
            int              l        = 1,
            maxline  = 0;
            boolean          longline = false;

            while (true) {
                String line = read.readLine();

                if (line == null) {
                    break;
                }

                if (line.length() > MAX_LINELENGTH
                        &&!line.startsWith("org.hsqldb.test.Profile.")) {
                    System.out.println("long line in " + name + " at line "
                            + l);
                }

                if (line.startsWith(" ")) {
                    int spaces = 0;

                    for (; spaces < line.length(); spaces++) {
                        if (line.charAt(spaces) != ' ') {
                            break;
                        }
                    }

                    if (spaces > 3 && testLine(line) &&!longline) {
                        maxline++;
                    } else if (isLongline(line)) {
                        longline = true;
                    } else {
                        longline = false;
                    }

                    String s = line.substring(spaces);

                    if (s.startsWith("if(")) {
                        if (!s.endsWith(" {")) {
                            System.out.println("if( without { in " + name
                                    + " at line " + l);
                        }
                    } else if (s.startsWith("} else if(")) {
                        if (!s.endsWith(" {")) {
                            System.out.println("} else if without { in "
                                    + name + " at line " + l);
                        }
                    } else if (s.startsWith("while(")) {
                        if (!s.endsWith(" {")) {
                            System.out.println("while( without { in " + name
                                    + " at line " + l);
                        }
                    } else if (s.startsWith("switch(")) {
                        if (!s.endsWith(" {")) {
                            System.out.println("switch( without { in " + name
                                    + " at line " + l);
                        }
                    } else if (s.startsWith("do ")) {
                        if (!s.endsWith(" {")) {
                            System.out.println("do without { in " + name
                                    + " at line " + l);
                        }
                    }
                }

                l++;
            }

            return maxline;
        } catch (Exception e) {
            printError(e.getMessage());
        }
        finally {

            if(read != null) {
                try {
                    read.close();
                } catch (IOException e1) {
                }
            }
        }

View Full Code Here

        }
    }

    static Vector getFileLines(File f) throws IOException {

        LineNumberReader read = null ;
        Vector           v    = new Vector();
        try {
            read = new LineNumberReader(new FileReader(f));

        for (;;) {
            String line = read.readLine();

            if (line == null) {
                break;
            }

            v.addElement(line);
        }
        }
        finally {
            if(read != null) {
                read.close();
            }
        }

        return v;
    }
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.