Package org.apache.hadoop.fs

Examples of org.apache.hadoop.fs.LocatedBlockFileStatus


    fs.mkdirs(TEST_DIR);
    writeFile(fs, FILE1, FILE_LEN);

    RemoteIterator<LocatedBlockFileStatus> itor = fs.listLocatedBlockStatus(
        FILE1);
    LocatedBlockFileStatus stat = itor.next();
    assertFalse(itor.hasNext());
   
    // check file status
    assertFalse(stat.isDir());
    assertEquals(FILE_LEN, stat.getLen());
    assertEquals(fs.makeQualified(FILE1), stat.getPath());
    assertEquals(-1, stat.getChildrenCount());
   
    // check block and locations
    BlockAndLocation[] locations = stat.getBlockLocations();
    assertEquals(2, locations.length);
    assertEquals(BLOCK_LEN, locations[0].getLength());
    assertEquals(0L, locations[0].getOffset());
    String[] hostNames = locations[0].getNames();
    assertEquals(3, hostNames.length);
View Full Code Here


    assertFalse(itor.hasNext());
   
    // testing directory with 1 file
    writeFile(fs, FILE2, FILE_LEN);   
    itor = fs.listLocatedBlockStatus(DIR1);
    LocatedBlockFileStatus stat = itor.next();
    assertFalse(itor.hasNext());
    assertFalse(stat.isDir());
    assertEquals(FILE_LEN, stat.getLen());
    assertEquals(-1, stat.getChildrenCount());
    assertEquals(fs.makeQualified(FILE2), stat.getPath());
    assertEquals(2, stat.getBlockLocations().length);
   
    // test more complicated directory
    writeFile(fs, FILE1, FILE_LEN);
    writeFile(fs, FILE3, FILE_LEN);
    writeFile(fs, FILE4, FILE_LEN);

    Set<Path> expectedResults = new TreeSet<Path>();
    expectedResults.add(fs.makeQualified(FILE2));
    expectedResults.add(fs.makeQualified(FILE3));
    for (itor = fs.listLocatedBlockStatus(DIR1); itor.hasNext(); ) {
      stat = itor.next();
      assertFalse(stat.isDir());
      assertTrue(expectedResults.remove(stat.getPath()));
    }
    assertTrue(expectedResults.isEmpty());
   
    final Path qualifiedDir1 = fs.makeQualified(DIR1);
    expectedResults.add(qualifiedDir1);
    expectedResults.add(fs.makeQualified(FILE1));
    expectedResults.add(fs.makeQualified(FILE4));
   
    for (itor = fs.listLocatedBlockStatus(TEST_DIR); itor.hasNext(); ) {
      stat = itor.next();
      assertTrue(expectedResults.remove(stat.getPath()));
      if (qualifiedDir1.equals(stat.getPath())) {
        assertTrue(stat.isDir());
        assertEquals(2, stat.getChildrenCount());
      } else {
        assertFalse(stat.isDir());
        assertEquals(-1, stat.getChildrenCount());
      }
    }
    assertTrue(expectedResults.isEmpty());
   
    fs.delete(TEST_DIR, true);
View Full Code Here

  public static LocatedBlockFileStatus toLocatedBlockFileStatus(HdfsFileStatus stat,
      LocatedBlocks locs, String src) {
    if (stat == null) {
      return null;
    }
    return new LocatedBlockFileStatus(stat.getLen(),
        stat.isDir(), stat.getReplication(),
        stat.getBlockSize(), stat.getModificationTime(),
        stat.getAccessTime(),
        stat.getPermission(), stat.getOwner(), stat.getGroup(),
        stat.getFullPath(new Path(src)), // full path
View Full Code Here


      @Override
      public boolean hasNext() throws IOException {
        while (curStat == null && itor.hasNext()) {
          LocatedBlockFileStatus next =itor.next();
          next.makeQualified(DistributedFileSystem.this);
          if (filter.accept(next.getPath())) {
            curStat = next;
          }
        }
        return curStat != null;
      }
    
      @Override
      public LocatedBlockFileStatus next() throws IOException {
        if (!hasNext()) {
          throw new java.util.NoSuchElementException("No more entry in " + p);
        }
        LocatedBlockFileStatus tmp = curStat;
        curStat = null;
        return tmp;
      }
    };
  }
View Full Code Here

TOP

Related Classes of org.apache.hadoop.fs.LocatedBlockFileStatus

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.