Package org.apache.commons.io

Examples of org.apache.commons.io.LineIterator


   *
   * @param work
   */
  protected void extractFileMapResult(InitialMapWork work) {
    LinkedList<Future<Map<String, Integer>>> futureResults = new LinkedList<Future<Map<String, Integer>>>();
    LineIterator lineIterator = null;
    try {
      File fileToCount = work.getFileToCount();
      lineIterator = FileUtils.lineIterator(fileToCount);

      while (lineIterator.hasNext()) {
        // All work including special character handling done at worker
        // level
        String line = lineIterator.nextLine();
        // key is just the file name - initial mapping is easy
        // hard part comes with partitioning and reduction
        // we assume that we have unique file names in the dir
        MapWork newWork = new MapWork(fileToCount.getName(), line);

        Future<Map<String, Integer>> future = this.workRouter
            .sendRequestReplyFuture(newWork, 30000, getContext());
        future.await();
        futureResults.add(future);
      }

      // FinalMapResult result = new FinalMapResult(
      // (LinkedList<Future<Map<String, Integer>>>) futureResults);
      getContext().channel().sendOneWay(futureResults);
    } catch (IOException e) {
      e.printStackTrace();
    } finally {
      if (lineIterator != null) {
        lineIterator.close();
      }
    }
  }
View Full Code Here


          if ((!item.isFormField()) && (item.getFieldName().equals("file1"))) {
           
            String fileName = item.getName();
            if (fileName.length()>0){
              try {
                LineIterator it =  IOUtils.lineIterator(in, "UTF-8");
                while (it.hasNext()) {
                  String line = it.nextLine();
 
                  PersistenceManager pm = PMF.get().getPersistenceManager();
                  try  {
                    pm.makePersistent(processMessage(line));
                    messageCount ++;
View Full Code Here

   */
  public static String asString(ClientResponse response) throws IOException {

    StringWriter out = new StringWriter();
    try {
      LineIterator itr = IOUtils.lineIterator(
          response.getEntityInputStream(), "UTF-8");
      while (itr.hasNext()) {
        String line = itr.next();
        out.write(line + (itr.hasNext() ? "\n" : ""));
      }
    } finally {
      closeQuietly(response.getEntityInputStream());
    }
    return out.toString();
View Full Code Here

  /**
   * Creates a new LineIterator instance on this reader.
   * @return LineIterator
   */
  public LineIterator iterateLines() {
    return new LineIterator(this);
  }
View Full Code Here

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

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

                final ContentType contentType = ContentType.getOrDefault(requestEntity);
                Charset charset = contentType.getCharset();
                if (charset == null) {
                    charset = Consts.ISO_8859_1;
                }
                final LineIterator it = IOUtils.lineIterator(instream, charset.name());
                int count = 0;
                while (it.hasNext()) {
                    final String line = it.next();
                    final int i = count % TEXT.length;
                    final String expected = TEXT[i];
                    if (!line.equals(expected)) {
                        ok = false;
                        break;
View Full Code Here

        //UTF-8, but some configurations might want to use URLs as keys!
        Map<String,Object> configMap = new HashMap<String,Object>();
        try {
            InputStream in = openConfig(configFile);
            if(in != null){
                LineIterator lines = IOUtils.lineIterator(in, "UTF-8");
                while(lines.hasNext()){
                    String line = (String)lines.next();
                    if(!line.isEmpty()){
                        int indexOfEquals = line.indexOf('=');
                        String key = indexOfEquals > 0 ?
                                line.substring(0,indexOfEquals).trim():
                                    line.trim();
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

    }

    @Override
    public List<String> getLines(String resource) throws IOException {
        List<String> lines = new ArrayList<String>();
        LineIterator it = IOUtils.lineIterator(openResource(resource), "UTF-8");
        while(it.hasNext()){
            String line = it.nextLine();
            if(line != null && !line.isEmpty() && line.charAt(0) != '#'){
                lines.add(line);
            }
        }
        return lines;
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.