Package org.apache.hadoop.fs

Examples of org.apache.hadoop.fs.LocatedFileStatus


            getUri(), getWorkingDirectory())); // fully-qualify path
  }

  private LocatedFileStatus makeQualifiedLocated(
      HdfsLocatedFileStatus f, Path parent) {
    return new LocatedFileStatus(f.getLen(), f.isDir(), f.getReplication(),
        f.getBlockSize(), f.getModificationTime(),
        f.getAccessTime(),
        f.getPermission(), f.getOwner(), f.getGroup(),
        null,
        (f.getFullPath(parent)).makeQualified(
View Full Code Here


      }

      @Override
      public boolean hasNext() throws IOException {
        while (curStat == null && hasNextNoFilter()) {
          LocatedFileStatus next = makeQualifiedLocated(
              (HdfsLocatedFileStatus)thisListing.getPartialListing()[i++], p);
          if (filter.accept(next.getPath())) {
            curStat = next;
          }
        }
        return curStat != null;
      }
     
      /** Check if there is a next item before applying the given filter */
      private boolean hasNextNoFilter() throws IOException {
        if (thisListing == null) {
          return false;
        }
        if (i>=thisListing.getPartialListing().length
            && thisListing.hasMore()) {
          // current listing is exhausted & fetch a new listing
          thisListing = dfs.listPaths(src, thisListing.getLastName(), true);
          statistics.incrementReadOps(1);
          if (thisListing == null) {
            return false;
          }
          i = 0;
        }
        return (i<thisListing.getPartialListing().length);
      }

      @Override
      public LocatedFileStatus next() throws IOException {
        if (hasNext()) {
          LocatedFileStatus tmp = curStat;
          curStat = null;
          return tmp;
        }
        throw new java.util.NoSuchElementException("No more entry in " + p);
      }
View Full Code Here

    fc.mkdir(TEST_DIR, FsPermission.getDefault(), true);
    writeFile(fc, FILE1, FILE_LEN);

    RemoteIterator<LocatedFileStatus> itor = fc.util().listFiles(
        FILE1, true);
    LocatedFileStatus stat = itor.next();
    assertFalse(itor.hasNext());
    assertTrue(stat.isFile());
    assertEquals(FILE_LEN, stat.getLen());
    assertEquals(fc.makeQualified(FILE1), stat.getPath());
    assertEquals(1, stat.getBlockLocations().length);
   
    itor = fc.util().listFiles(FILE1, false);
    stat = itor.next();
    assertFalse(itor.hasNext());
    assertTrue(stat.isFile());
    assertEquals(FILE_LEN, stat.getLen());
    assertEquals(fc.makeQualified(FILE1), stat.getPath());
    assertEquals(1, stat.getBlockLocations().length);
  }
View Full Code Here

   
    // testing directory with 1 file
    writeFile(fc, FILE2, FILE_LEN);
   
    itor = fc.util().listFiles(DIR1, true);
    LocatedFileStatus stat = itor.next();
    assertFalse(itor.hasNext());
    assertTrue(stat.isFile());
    assertEquals(FILE_LEN, stat.getLen());
    assertEquals(fc.makeQualified(FILE2), stat.getPath());
    assertEquals(1, stat.getBlockLocations().length);
   
    itor = fc.util().listFiles(DIR1, false);
    stat = itor.next();
    assertFalse(itor.hasNext());
    assertTrue(stat.isFile());
    assertEquals(FILE_LEN, stat.getLen());
    assertEquals(fc.makeQualified(FILE2), stat.getPath());
    assertEquals(1, stat.getBlockLocations().length);

    // test more complicated directory
    writeFile(fc, FILE1, FILE_LEN);
    writeFile(fc, FILE3, FILE_LEN);

    itor = fc.util().listFiles(TEST_DIR, true);
    stat = itor.next();
    assertTrue(stat.isFile());
    assertEquals(fc.makeQualified(FILE2), stat.getPath());
    stat = itor.next();
    assertTrue(stat.isFile());
    assertEquals(fc.makeQualified(FILE3), stat.getPath());
    stat = itor.next();
    assertTrue(stat.isFile());
    assertEquals(fc.makeQualified(FILE1), stat.getPath());
    assertFalse(itor.hasNext());
   
    itor = fc.util().listFiles(TEST_DIR, false);
    stat = itor.next();
    assertTrue(stat.isFile());
    assertEquals(fc.makeQualified(FILE1), stat.getPath());
    assertFalse(itor.hasNext());
  }
View Full Code Here

   
    fc.createSymlink(DIR1, dir5, true);
    fc.createSymlink(FILE1, file4, true);
   
    RemoteIterator<LocatedFileStatus> itor = fc.util().listFiles(dir4, true);
    LocatedFileStatus stat = itor.next();
    assertTrue(stat.isFile());
    assertEquals(fc.makeQualified(FILE2), stat.getPath());
    stat = itor.next();
    assertTrue(stat.isFile());
    assertEquals(fc.makeQualified(FILE3), stat.getPath());
    stat = itor.next();
    assertTrue(stat.isFile());
    assertEquals(fc.makeQualified(FILE1), stat.getPath());
    assertFalse(itor.hasNext());
   
    itor = fc.util().listFiles(dir4, false);
    stat = itor.next();
    assertTrue(stat.isFile());
    assertEquals(fc.makeQualified(FILE1), stat.getPath());
    assertFalse(itor.hasNext());
  }
View Full Code Here

            public RemoteIterator<LocatedFileStatus> listLocatedStatus(Path f)
                    throws IOException
            {
                ImmutableList.Builder<LocatedFileStatus> list = ImmutableList.builder();
                for (FileStatus status : paths.get(f.toString())) {
                    list.add(new LocatedFileStatus(status, new BlockLocation[0]));
                }
                return remoteIterator(list.build().iterator());
            }

            @Override
View Full Code Here

      FileSystem fs = FileSystem.get(config);

      RemoteIterator<LocatedFileStatus> itr = fs.listFiles(libPath, true);

      while (itr.hasNext()) {
        LocatedFileStatus f = itr.next();

        if (!f.isDirectory() && f.getPath().getName().endsWith("jar")) {
          logger.info("Loading Jar : " + f.getPath().getName());
          DistributedCache.addFileToClassPath(f.getPath(), config);
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
      logger.error(e.toString());
View Full Code Here

    {
        try {
            RemoteIterator<LocatedFileStatus> iterator = getLocatedFileStatusRemoteIterator(path);

            while (iterator.hasNext()) {
                LocatedFileStatus status = getLocatedFileStatus(iterator);

                // ignore hidden files. Hive ignores files starting with _ and . as well.
                String fileName = status.getPath().getName();
                if (fileName.startsWith("_") || fileName.startsWith(".")) {
                    continue;
                }
                if (isDirectory(status)) {
                    recursiveWalk(status.getPath(), callback, taskCount, future);
                }
                else {
                    callback.process(status, status.getBlockLocations());
                }
                if (future.isDone()) {
                    return;
                }
            }
View Full Code Here

    private LocatedFileStatus createLocatedFileStatus(FileStatus status)
    {
        try {
            BlockLocation[] fakeLocation = getFileBlockLocations(status, 0, status.getLen());
            return new LocatedFileStatus(status, fakeLocation);
        }
        catch (IOException e) {
            throw propagate(e);
        }
    }
View Full Code Here

            public RemoteIterator<LocatedFileStatus> listLocatedStatus(Path f)
                    throws IOException
            {
                ImmutableList.Builder<LocatedFileStatus> list = ImmutableList.builder();
                for (FileStatus status : paths.get(f.toString())) {
                    list.add(new LocatedFileStatus(status, new BlockLocation[0]));
                }
                return remoteIterator(list.build().iterator());
            }

            @Override
View Full Code Here

TOP

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

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.