Package java.io

Examples of java.io.LineNumberReader


        }
        runFile(fileName);
    }

    private void runFile(String fileName) throws IOException {
        LineNumberReader reader = new LineNumberReader(new BufferedReader(
                new InputStreamReader(IOUtils.openFileInputStream(fileName))));
        while (true) {
            String line = reader.readLine();
            if (line == null) {
                break;
            }
            runLine(line.trim());
        }
        reader.close();
    }
View Full Code Here


           
            // a normal reply ... extract the file list
            String replyCode = lastValidReply.getReplyCode();
            if (!replyCode.equals("450") && !replyCode.equals("550") && !replyCode.equals("226")) {
                // get a character input stream to read data from .
                LineNumberReader in = null;
                 try {
                    in = new LineNumberReader(
                            new InputStreamReader(getInputStream(), controlEncoding));
   
                    // read a line at a time
                    String line = null;
                    while ((line = readLine(in)) != null && !cancelTransfer) {
                        if (lines != null)
                            lines.addElement(line);
                        if (lister != null) {
                            DirectoryListArgument arg = lister.listEntry(line);
                            if (arg != null && arg.isListingAborted()) {
                                log.warn("Aborting listing");
                                cancelTransfer = true;
                            }
                        }
                        log.log(Level.ALL, line, null);
                    }
                }
                catch (IOException ex) {
                    validateTransferOnError(ex);
                    throw ex;
                }
                finally {
                    try {
                        if (in != null)
                            in.close();
                    }
                    catch (IOException ex) {
                        log.error("Failed to close socket in dir()", ex);
                    }
                    closeDataSocket();
View Full Code Here

        }
        deleteDb("scriptSimple");
        reconnect();
        String inFile = "org/h2/test/testSimple.in.txt";
        InputStream is = getClass().getClassLoader().getResourceAsStream(inFile);
        LineNumberReader lineReader = new LineNumberReader(new InputStreamReader(is, "Cp1252"));
        ScriptReader reader = new ScriptReader(lineReader);
        while (true) {
            String sql = reader.readStatement();
            if (sql == null) {
                break;
View Full Code Here

        }
    }

    private void testFile(String inFile) throws Exception {
        InputStream is = getClass().getClassLoader().getResourceAsStream(inFile);
        in = new LineNumberReader(new InputStreamReader(is, "Cp1252"));
        StringBuilder buff = new StringBuilder();
        while (true) {
            String sql = readLine();
            if (sql == null) {
                break;
View Full Code Here

      InputStream inR = this.getClass().getClassLoader()
        .getResourceAsStream("weka/gui/beans/README_KnowledgeFlow");

      // end modifications
      StringBuffer helpHolder = new StringBuffer();
      LineNumberReader lnr = new LineNumberReader(new InputStreamReader(inR));

      String line;

      while ((line = lnr.readLine()) != null) {
        helpHolder.append(line+"\n");
      }

      lnr.close();
      final javax.swing.JFrame jf = new javax.swing.JFrame();
      jf.getContentPane().setLayout(new java.awt.BorderLayout());
      final JTextArea ta = new JTextArea(helpHolder.toString());
      ta.setFont(new Font("Monospaced", Font.PLAIN, 12));
      ta.setEditable(false);
View Full Code Here

    /**
     * Usage: java ThreadDumpFilter <log.txt >threadDump.txt
     * @param a ignored
     */
    public static void main(String... a) throws Exception {
        LineNumberReader in = new LineNumberReader(new InputStreamReader(System.in));
        for (String s; (s = in.readLine()) != null;) {
            if (s.startsWith("Full thread")) {
                do {
                    System.out.println(s);
                    s = in.readLine();
                } while(s != null && (s.length() == 0 || " \t\"".indexOf(s.charAt(0)) >= 0));
            }
        }
    }
View Full Code Here

  private void updateRAR(String raProperties, boolean updateA3servers) throws Exception {
    if (debug)
      System.out.println("RAConfig.updateRAR(" + raProperties + ")");

    FileReader file = new FileReader(raProperties);
    LineNumberReader lnr = new LineNumberReader(file);

    // get RAR name
    String line = lnr.readLine();
    while (line != null) {
      if (line.startsWith("RAR_NAME"))
        break;
      line = lnr.readLine();
    }
    int i = line.indexOf("RAR_NAME");
    String rarName = line.substring(i+"RAR_NAME".length()).trim();
    if (debug)
      System.out.println("RAConfig.updateRAR : rarName = " + rarName);
    else if (verbose)
      System.out.println("update rar \"" + rarName +
                         "\" with \"" + raProperties + "\"");

    // create Map of properties
    Map map = new Hashtable();
    Hashtable prop = null;
    String nodeName = null;
    line = lnr.readLine();
    while (line != null) {
      if (line.startsWith("[")) {
        prop = new Hashtable();
        nodeName = line.substring(line.indexOf("[")+1,line.indexOf("]"));
        map.put(nodeName.trim(),prop);
      } else {
        StringTokenizer st = new StringTokenizer(line);
        if (st.countTokens() == 2 && prop != null) {
          prop.put(st.nextToken(),st.nextToken());
        }
      }
      line = lnr.readLine();
    }
    file.close();

    if (debug)
      System.out.println("RAConfig.updateRAR : map = " + map);
View Full Code Here

    public Point getSelection(IDocument document) {
      return null;
    }
   
    public static String findCorrectionProposal(MarkerAnnotation markerAnnotation) {   
      LineNumberReader read = null;
      try {
        int linenumber = (Integer) markerAnnotation.getMarker().getAttribute(IMarker.LINE_NUMBER);
        File input = markerAnnotation.getMarker().getResource().getLocation().toFile();
       
        for (String encoding : encodingsToTest) {   
          read = new LineNumberReader(new InputStreamReader(new FileInputStream(input), encoding));
            String line;
            while ((line = read.readLine()) != null) {
              if (read.getLineNumber()-1 == linenumber) {
                break;
              }
            }
          if (line != null && !InvalidEncodingMarkingHandler.containsInvalidChar(line)) {
            return line;
          }                   
        }
      } catch (Exception e) {
      } finally {
        if (read != null) {
          try {
            read.close();
          } catch (IOException e) {
          }
        }
      }
      return null;
View Full Code Here

  public void createMarkers(IFile file, IDocument document) throws CoreException {
    file.deleteMarkers(MARKER_ID, true, IResource.DEPTH_ZERO);
    if (_provider != null && _provider instanceof FileDocumentProvider) {
      String encoding = file.getCharset(true);
      LineNumberReader read = null;
      try {
        read = new LineNumberReader(new InputStreamReader(new FileInputStream(file.getLocation().toFile()), encoding));
            String line;
            while ((line = read.readLine()) != null) {
             
              boolean invalidCharsFound = false;
              Map<String,Object> attributes = new HashMap<String, Object>();
              List<Character> invalidCharsInLine = new ArrayList<Character>();
             
                for (int i = 0; i < line.length(); i++) {
                    char c = line.charAt(i);
                    if (!Character.isLetterOrDigit(c) &&
                            !Character.isWhitespace(c) &&
                            !CURRENCY_SYMBOLS.contains(c) &&
                            ALLOWED_NONALPHANUMERIC.indexOf(c) == -1) {
                      invalidCharsFound = true;                 
                      invalidCharsInLine.add(c);
                    }
                }
               
                if (invalidCharsFound) {
                  // create marker
                  try {
                    IRegion lineInfo = document.getLineInformation(read.getLineNumber() - 1);
                    String lineContent = document.get(lineInfo.getOffset(), lineInfo.getLength());
                    int beginningSpaces = 0;
                    for (int i = 0; i < lineContent.length(); i++) {
                      char c = lineContent.charAt(i);
                      if (Character.isWhitespace(c)) {
                        beginningSpaces++;
                      } else {
                        break;
                      }
                    }
                    int trailingSpaces = 0;
                    for (int i = lineContent.length() - 1; i >= 0; i--) {
                      char c = lineContent.charAt(i);
                      if (Character.isWhitespace(c)) {
                        trailingSpaces++;
                      } else {
                        break;
                      }
                    }
              int charStart = lineInfo.getOffset() + beginningSpaces;             
              int charEnd = charStart + lineInfo.getLength() - beginningSpaces - trailingSpaces;

              Map<String,Object> map = new HashMap<String,Object>();

              MarkerUtilities.setLineNumber(map, read.getLineNumber()-1);
             
              MarkerUtilities.setCharStart(map, charStart);
              MarkerUtilities.setCharEnd(map, charEnd);
                             
              MarkerUtilities.setMessage(map, "Invalid characters found '" + WGUtils.serializeCollection(invalidCharsInLine, ",") + "' .");
             
              map.put(IMarker.LOCATION, file.getFullPath().toString());
             
              map.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_ERROR));
              if (attributes != null) {
                map.putAll(attributes);
              }

              MarkerUtilities.createMarker(file, map, MARKER_ID);

            } catch (BadLocationException e) {
            }
                 
                 
                   
                }
             
               
            }
      } catch (UnsupportedEncodingException e) {
      } catch (IOException e) {
      } finally {
        if (read != null) {
          try {
            read.close();
          } catch (IOException e) {
          }
        }
      }
    }
View Full Code Here

                }
            }
        };
        task.execute();
        InputStreamReader reader = new InputStreamReader(testIn);
        lineReader = new LineNumberReader(reader);
        read("");
        read("Welcome to H2 Shell");
        read("Exit with");
        if (!commandLineArgs) {
            read("[Enter]");
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.