Package org.apache.commons.io

Examples of org.apache.commons.io.LineIterator


            boolean ok = true;

            InputStream instream = requestEntity.getContent();
            try {
                LineIterator it = IOUtils.lineIterator(instream,
                        EntityUtils.getContentCharSet(requestEntity));
                int count = 0;
                while (it.hasNext()) {
                    String line = it.next();
                    int i = count % TEXT.length;
                    String expected = TEXT[i];
                    if (!line.equals(expected)) {
                        ok = false;
                        break;
View Full Code Here


    public static List<String> readLinesFromFile(
            String filename, String encoding
    ) throws IOException {
        List<String> lines = new ArrayList<String>();
        File file = new File(filename);
        LineIterator it = FileUtils.lineIterator(file, encoding);
        try {
            while (it.hasNext()) {
                String line = it.nextLine();
                lines.add(line);
            }
        } finally {
            it.close();
        }
        return lines;
    }
View Full Code Here

    ArrayList<String> result = new ArrayList<String>();
    for (File file : getCluster().getConfig().getLogDir().listFiles()) {
      // We want to grab the files called .out
      if (file.getName().contains(".out") && file.isFile() && file.canRead()) {
        LineIterator it = FileUtils.lineIterator(file, Constants.UTF8.name());
        try {
          while (it.hasNext()) {
            String line = it.nextLine();
            if (line.matches(".* \\[" + AuditedSecurityOperation.AUDITLOG + "\\s*\\].*")) {
              // Only include the message if startTimestamp is null. or the message occurred after the startTimestamp value
              if ((lastAuditTimestamp == null) || (line.substring(0, 23).compareTo(lastAuditTimestamp) > 0))
                result.add(line);
            }
View Full Code Here

    auditConnector.tableOperations().exportTable(OLD_TEST_TABLE_NAME, exportDir.toString());

    // We've exported the table metadata to the MiniAccumuloCluster root dir. Grab the .rf file path to re-import it
    File distCpTxt = new File(exportDir.toString() + "/distcp.txt");
    File importFile = null;
    LineIterator it = FileUtils.lineIterator(distCpTxt, Constants.UTF8.name());

    // Just grab the first rf file, it will do for now.
    String filePrefix = "file:";
    try {
      while (it.hasNext() && importFile == null) {
        String line = it.nextLine();
        if (line.matches(".*\\.rf")) {
          importFile = new File(line.replaceFirst(filePrefix, ""));
        }
      }
    } finally {
View Full Code Here

        state = State.SWEEPING;
        LOG.debug("Starting sweep phase of the garbage collector");

        ConcurrentLinkedQueue<String> exceptionQueue = new ConcurrentLinkedQueue<String>();

        LineIterator iterator =
                FileUtils.lineIterator(fs.getGcCandidates(), Charsets.UTF_8.name());
        List<String> ids = Lists.newArrayList();

        while (iterator.hasNext()) {
            ids.add(iterator.next());

            if (ids.size() > getBatchCount()) {
                count += ids.size();
                executor.execute(new Sweeper(ids, exceptionQueue));
                ids = Lists.newArrayList();
View Full Code Here

    if (!aReportFile.exists()) {
      // Ignore if the file is missing
      return;
    }

    LineIterator i = null;
    try {
      String clazz = null;
      i = IOUtils.lineIterator(new FileInputStream(aReportFile), encoding);
      while (i.hasNext()) {
        String line = i.next();
        // Report say there is no missing meta data
        if (line.startsWith(MARK_NO_MISSING_META_DATA)) {
          return;
        }
        // Line containing class name
View Full Code Here

        } else if (args[0].equals(SLEEP_WITH_TIMEOUT)) {
            doSleep();
            System.exit(0);
        } else if (READ_INPUT_LINES_AND_PRINT_THEM.equals(args[0])) {
            LineIterator iterator = IOUtils.lineIterator(System.in, "UTF-8");
            while (iterator.hasNext()) {
                String line = iterator.nextLine();
                System.out.println(line);

            }
        } else {
            System.out.println(args[0]);
View Full Code Here

    // No newLine
   
    String inputString = line1;   

    NewLineReader r = new NewLineReader(new StringReader(inputString));
    LineIterator i = r.iterateLines();
   
    Assert.assertTrue(i.hasNext());
    Assert.assertEquals(i.nextLine(), inputString);
    Assert.assertFalse(i.hasNext());
    Assert.assertNull(r.getInputNewLine());
    Assert.assertNull(r.getOutputNewLine());
    // Test the actual output
    r.reset();
    String out1 = IOUtil.toString(r);
    Assert.assertEquals(inputString, out1);
   
    // \n NewLine
   
    inputString = line1 + "\n" + line2;
   
    r = new NewLineReader(new StringReader(inputString));
    i = r.iterateLines();
    Assert.assertEquals(i.next(), line1);
    Assert.assertEquals(r.getInputNewLine(), "\n");
    Assert.assertEquals(r.getOutputNewLine(), "\n");
    Assert.assertEquals(i.next(), line2);
    Assert.assertFalse(i.hasNext());
    // Test the actual output
    r.reset();
    String out2 = IOUtil.toString(r);
    Assert.assertEquals(inputString, out2);
   
   
    // \r\n NewLine
   
    inputString = line1 + "\r\n" + line2 + "\r\n";
   
    r = new NewLineReader(new StringReader(inputString));
    i = r.iterateLines();
    Assert.assertEquals(i.next(), line1);
    Assert.assertEquals(r.getInputNewLine(), "\r\n");
    Assert.assertEquals(r.getOutputNewLine(), "\r\n");
    Assert.assertEquals(i.next(), line2);
    Assert.assertFalse(i.hasNext()); // Should not return another line (LineIterator behavior)
    // Test the actual output
    r.reset();
    String out3 = IOUtil.toString(r);
    Assert.assertEquals(inputString, out3);
  }
View Full Code Here

    // One character '\n'
   
    String inputString = line1 + "\r\n" + line2;   

    NewLineReader r = new NewLineReader(new StringReader(inputString), null, "\n");
    LineIterator i = r.iterateLines();
   
    Assert.assertEquals(i.nextLine(), line1);
    Assert.assertEquals(r.getInputNewLine(), "\r\n");
    Assert.assertEquals(r.getOutputNewLine(), "\n");
    Assert.assertEquals(i.nextLine(), line2);
    Assert.assertFalse(i.hasNext()); // Should not return another line (LineIterator behavior)
   
    // Test the actual output
    r.reset();
    String out = IOUtil.toString(r);
    Assert.assertEquals(line1 + "\n" + line2, out);
View Full Code Here

        } else if (args[0].equals(SLEEP_WITH_TIMEOUT)) {
            doSleep();
            System.exit(0);
        } else if (READ_INPUT_LINES_AND_PRINT_THEM.equals(args[0])) {
            LineIterator iterator = IOUtils.lineIterator(System.in, "UTF-8");
            while (iterator.hasNext()) {
                String line = iterator.nextLine();
                System.out.println(line);

            }
        } else {
            System.out.println(args[0]);
View Full Code Here

TOP

Related Classes of org.apache.commons.io.LineIterator

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.