Package org.apache.commons.io

Examples of org.apache.commons.io.LineIterator


    }

    private DeltaIndex readIndex(ZipInputStream patch) throws IOException {
        ZipEntry indexEntry = patch.getNextEntry();
        checkArgument(indexEntry.getName().startsWith(".index"), "Unexpected index file name: '{}', must start with '.index'");
        LineIterator iter = IOUtils.lineIterator(patch, "UTF-8");
        List<? extends IndexEntry> entries = ImmutableList.copyOf(Iterators.transform(iter, new IndexEntryMapper()));
        patch.closeEntry();
        ImmutableList<IndexEntry.Unchanged> unchanged = ImmutableList.copyOf(Iterables.filter(entries, IndexEntry.Unchanged.class));
        ImmutableList<IndexEntry.Created> created = ImmutableList.copyOf(Iterables.filter(entries, IndexEntry.Created.class));
        ImmutableList<IndexEntry.Updated> updated = ImmutableList.copyOf(Iterables.filter(entries, IndexEntry.Updated.class));
View Full Code Here


    URL resource = getClass().getResource( RESOURCE_NAME_DE_PLZ_TXT );
    if ( resource == null ) {
      throw new IOException( "Resource \"" + RESOURCE_NAME_DE_PLZ_TXT + "\" not found" );
    }

    LineIterator iterator = IOUtils.lineIterator( resource.openStream(), "UTF-8" );
    while ( iterator.hasNext() ) {
      String line = iterator.nextLine();
      String[] parts = line.split( "\t" );
      if ( parts.length < 2 ) {
        continue;
      }
View Full Code Here

     */
    public static List<String> tail(File file, int count) throws IOException {
        LinkedList<String> tailLines = new LinkedList<String>();
        FileReader reader = new FileReader(file);
        try {
            LineIterator iterator = org.apache.commons.io.IOUtils.lineIterator(reader);
            int lineCount = 0;
            while (iterator.hasNext()) {
                String line = iterator.nextLine();
                lineCount++;
                if (lineCount > count)
                    tailLines.removeFirst();
                tailLines.offer(line);
            }
View Full Code Here

     * @return Snippet contents.
     * @throws IOException
     */
    public static String loadSnippet(String id, URL url, String encoding) throws IOException {
        StringBuilder snippet = new StringBuilder();
        LineIterator lines = IOUtils.lineIterator(url.openStream(), encoding);
       
        try {
            boolean include = (id == null);
           
            while (lines.hasNext()) {
                String line = lines.nextLine();
               
                if (match(line, START_SNIPPET, id)) {
                    include = true;
                } else if (match(line, END_SNIPPET, id)) {
                    break;
View Full Code Here

            return isSearchTextPresentInLinesOfFile(f);
        }
    }

    private boolean isSearchTextPresentInLinesOfFile(File f) {
        LineIterator it = null;
        try {
            it = FileUtils.lineIterator(f, "UTF-8");
            while (it.hasNext()) {
                String line = it.nextLine();
                if (line.contains(searchText)) {
                    return true;
                }
            }
            return false;
View Full Code Here

    final InMemorySenseiService memorySenseiService = InMemorySenseiService.valueOf(new File(
        InMemoryIndexPerfEval.class.getClassLoader().getResource("test-conf/node1/").toURI()));
       
     
    final List<JSONObject> docs = new ArrayList<JSONObject>(15000);
    LineIterator lineIterator = FileUtils.lineIterator(new File(InMemoryIndexPerfEval.class.getClassLoader().getResource("data/test_data.json").toURI()));
    int i = 0;
    while(lineIterator.hasNext() && i < 100) {
      String car = lineIterator.next();
      if (car != null && car.contains("{"))
      docs.add(new JSONObject(car));
      i++;
    }
    Thread[] threads = new Thread[10];
View Full Code Here

  private List<JSONObject> docs;
  @Override
  protected void setUp() throws Exception {
    inMemorySenseiService =  InMemorySenseiService.valueOf(new File(
        InMemoryIndexPerfEval.class.getClassLoader().getResource("test-conf/node1/").toURI()));
    LineIterator lineIterator = FileUtils.lineIterator(new File(InMemoryIndexPerfEval.class.getClassLoader().getResource("data/test_data.json").toURI()));
    int i = 0;
    docs = new ArrayList<JSONObject>();
    while(lineIterator.hasNext() && i < 100) {
      String car = lineIterator.next();
      if (car != null && car.contains("{"))
      docs.add(new JSONObject(car));
      i++;
    }
    lineIterator.close();
  }
View Full Code Here

    federatedBroker.stop();
  }

  private List<JSONObject> readCarDocs() throws IOException, URISyntaxException, JSONException {
    List<JSONObject> ret = new ArrayList<JSONObject>();
    LineIterator lineIterator = FileUtils.lineIterator(new File(FederatedBrokerIntegrationTest.class.getClassLoader().getResource("data/cars.json").toURI()));
    while(lineIterator.hasNext()) {
      String car = lineIterator.next();
      if (car != null && car.contains("{")) {
        JSONObject carDoc = new JSONObject(car);
        carDoc.put("id", carDoc.getLong("id") + 15000);
        ret.add(carDoc);
      }
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

    linesLock = new Object();
    this.log = log;
  }

  public void run() {
    LineIterator it = null;

    try {
      it = IOUtils.lineIterator(inputStream, "UTF-8");

      while (it.hasNext()) {
        String line = it.nextLine();

        if (line.length() > 0) {
          addLine(line);
        }
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.