Package org.apache.commons.io

Examples of org.apache.commons.io.LineIterator


        // maintain the ordering in the file. Line N in the host names file
        // should correspond to node ID N-1. Previously they were in hashed
        // order, so certain tools that auto-configure a cluster based on
        // this same hosts file were creating invalid configurations between
        // the cluster.xml and server.properties (node.id) files.
        LineIterator li = null;
        int lineNumber = 0;

        try {
            li = FileUtils.lineIterator(file);

            while(li.hasNext()) {
                String rawLine = String.valueOf(li.next()).trim();
                lineNumber++;

                // Strip comments
                int hashIndex = rawLine.indexOf("#");

                if(hashIndex != -1)
                    rawLine = rawLine.substring(0, hashIndex).trim();

                // Whitespace
                if(rawLine.length() == 0)
                    continue;

                String[] line = StringUtils.split(rawLine, " \t=:");

                if(line.length < 1 || line.length > 2) {
                    System.err.println("Invalid entry (line " + lineNumber + ") in "
                                       + file.getAbsolutePath() + ": " + rawLine);
                    System.exit(2);
                }

                String externalHostName = line[0];
                String internalHostName = line.length > 1 ? line[1] : externalHostName;
                hostNamePairs.add(new HostNamePair(externalHostName, internalHostName));
            }
        } catch(IOException e) {
            throw new RuntimeException(e);
        } finally {
            if(li != null)
                li.close();
        }

        return hostNamePairs;
    }
View Full Code Here


  public void index() throws IOException {
    final SimpleIndexer indexer = new SimpleIndexer(indexDir);
    try {
      int counter = 0;
      final LineIterator it = FileUtils.lineIterator(BNB_PATH);
      while (it.hasNext()) {
        final String id = Integer.toString(counter++);
        final String content = (String) it.next();
        logger.info("Indexing document {}", id);
        indexer.addDocument(id, content);
      }
      LineIterator.closeQuietly(it);
      logger.info("Commiting all pending documents");
View Full Code Here

        Integer status = future.get();
        Assert.assertNotNull(status);
        Assert.assertEquals(HttpStatus.SC_OK, status.intValue());
        InputStream instream = new FileInputStream(this.tmpfile);
        try {
            LineIterator it = IOUtils.lineIterator(instream, ASCII.name());
            int count = 0;
            while (it.hasNext()) {
                String line = it.next();
                int i = count % TEXT.length;
                String expected = TEXT[i];
                Assert.assertEquals(expected, line);
                count++;
            }
View Full Code Here

        Integer status = future.get();
        Assert.assertNotNull(status);
        Assert.assertEquals(HttpStatus.SC_OK, status.intValue());
        InputStream instream = new FileInputStream(this.tmpfile);
        try {
            LineIterator it = IOUtils.lineIterator(instream, ASCII.name());
            int count = 0;
            while (it.hasNext()) {
                String line = it.next();
                int i = count % TEXT.length;
                String expected = TEXT[i];
                Assert.assertEquals(expected, line);
                count++;
            }
View Full Code Here

            boolean ok = true;

            InputStream instream = requestEntity.getContent();
            try {
                ContentType contentType = ContentType.getOrDefault(requestEntity);
                LineIterator it = IOUtils.lineIterator(instream, contentType.getCharset());
                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

        return this.convertLinesToStream(message, in, path);
    }

    protected String convertLinesToString(NormalizedMessage message,
                                          InputStream in, String path) throws IOException {
        LineIterator lines = IOUtils.lineIterator(in, this.encoding);

        StringBuffer aBuffer = new StringBuffer(1024);

        if (this.xmlDeclaration) {
            aBuffer.append(XMLDECLARATION_LINE);
        }

        aBuffer.append(XML_OPEN + this.docElementname);

        if (this.docElementNamespace != null) {
            aBuffer.append("xmlns=\"");
            aBuffer.append(this.docElementNamespace);
            aBuffer.append("\"");
        }

        aBuffer.append(" name=\"");
        aBuffer.append(new File(path).getName());
        aBuffer.append("\"");

        aBuffer.append(" location=\"");
        aBuffer.append(path);
        aBuffer.append(XML_CLOSE_ATTR_NEWLINE);

        this.processHeaderLines(aBuffer, lines);

        int lineNumber = 1;
        while (lines.hasNext()) {
            String lineText = lines.nextLine();
            aBuffer.append(XML_OPEN + this.lineElementname);

            if (this.insertLineNumbers || this.insertRawData) {
                if (this.insertLineNumbers) {
                    aBuffer.append(" number=\"");
View Full Code Here

        ExternalSorter<String> sorter = new ExternalSorter<String>(new StringSerializer(),
                                                                   internalSortSize,
                                                                   numThreads);
        @SuppressWarnings("unchecked")
        Iterator<String> it = new LineIterator(new BufferedReader(new FileReader(input),
                                                                  10 * 1024 * 1024));

        String seperator = Utils.NEWLINE;
        BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out),
                                                   10 * 1024 * 1024);
 
View Full Code Here

                                thread.setDaemon(true);
                                return thread;
                            }
                        });

        LineIterator iterator = FileUtils.lineIterator(fs.getGcCandidates(), Charsets.UTF_8.name());
        List<String> ids = Lists.newArrayList();
        int count = 0;
        while (iterator.hasNext()) {
            ids.add(iterator.next());

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

        Integer status = future.get();
        Assert.assertNotNull(status);
        Assert.assertEquals(HttpStatus.SC_OK, status.intValue());
        InputStream instream = new FileInputStream(this.tmpfile);
        try {
            LineIterator it = IOUtils.lineIterator(instream, ASCII.name());
            int count = 0;
            while (it.hasNext()) {
                String line = it.next();
                int i = count % TEXT.length;
                String expected = TEXT[i];
                Assert.assertEquals(expected, line);
                count++;
            }
View Full Code Here

        Integer status = future.get();
        Assert.assertNotNull(status);
        Assert.assertEquals(HttpStatus.SC_OK, status.intValue());
        InputStream instream = new FileInputStream(this.tmpfile);
        try {
            LineIterator it = IOUtils.lineIterator(instream, ASCII.name());
            int count = 0;
            while (it.hasNext()) {
                String line = it.next();
                int i = count % TEXT.length;
                String expected = TEXT[i];
                Assert.assertEquals(expected, line);
                count++;
            }
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.