Search in sources :

Example 6 with FileStatus

use of org.apache.hadoop.fs.FileStatus in project hadoop by apache.

the class TestFileStatus method constructorNoSymlink.

/**
   * Check that the non-symlink constructor works correctly.
   */
@Test
public void constructorNoSymlink() throws IOException {
    boolean isdir = true;
    FileStatus fileStatus = new FileStatus(LENGTH, isdir, REPLICATION, BLKSIZE, MTIME, ATIME, PERMISSION, OWNER, GROUP, PATH);
    validateAccessors(fileStatus, LENGTH, isdir, REPLICATION, BLKSIZE, MTIME, ATIME, PERMISSION, OWNER, GROUP, null, PATH);
}
Also used : FileStatus(org.apache.hadoop.fs.FileStatus) Test(org.junit.Test)

Example 7 with FileStatus

use of org.apache.hadoop.fs.FileStatus in project hadoop by apache.

the class TestFileStatus method toStringDir.

/**
   * Check that toString produces the expected output for a directory.
   */
@Test
public void toStringDir() throws IOException {
    FileStatus fileStatus = new FileStatus(LENGTH, true, REPLICATION, BLKSIZE, MTIME, ATIME, PERMISSION, OWNER, GROUP, null, PATH);
    validateToString(fileStatus);
}
Also used : FileStatus(org.apache.hadoop.fs.FileStatus) Test(org.junit.Test)

Example 8 with FileStatus

use of org.apache.hadoop.fs.FileStatus in project hadoop by apache.

the class TestFileStatus method testFileStatusWritable.

/**
   * Check that the write and readField methods work correctly.
   */
@Test
public void testFileStatusWritable() throws Exception {
    FileStatus[] tests = { new FileStatus(1, false, 5, 3, 4, 5, null, "", "", new Path("/a/b")), new FileStatus(0, false, 1, 2, 3, new Path("/")), new FileStatus(1, false, 5, 3, 4, 5, null, "", "", new Path("/a/b")) };
    LOG.info("Writing FileStatuses to a ByteArrayOutputStream");
    // Writing input list to ByteArrayOutputStream
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    DataOutput out = new DataOutputStream(baos);
    for (FileStatus fs : tests) {
        fs.write(out);
    }
    LOG.info("Creating ByteArrayInputStream object");
    DataInput in = new DataInputStream(new ByteArrayInputStream(baos.toByteArray()));
    LOG.info("Testing if read objects are equal to written ones");
    FileStatus dest = new FileStatus();
    int iterator = 0;
    for (FileStatus fs : tests) {
        dest.readFields(in);
        assertEquals("Different FileStatuses in iteration " + iterator, dest, fs);
        iterator++;
    }
}
Also used : Path(org.apache.hadoop.fs.Path) DataInput(java.io.DataInput) DataOutput(java.io.DataOutput) FileStatus(org.apache.hadoop.fs.FileStatus) ByteArrayInputStream(java.io.ByteArrayInputStream) DataOutputStream(java.io.DataOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DataInputStream(java.io.DataInputStream) Test(org.junit.Test)

Example 9 with FileStatus

use of org.apache.hadoop.fs.FileStatus in project hadoop by apache.

the class TestFileStatus method constructorNoOwner.

/**
   * Check that the constructor without owner, group and permissions works
   * correctly.
   */
@Test
public void constructorNoOwner() throws IOException {
    boolean isdir = true;
    FileStatus fileStatus = new FileStatus(LENGTH, isdir, REPLICATION, BLKSIZE, MTIME, PATH);
    validateAccessors(fileStatus, LENGTH, isdir, REPLICATION, BLKSIZE, MTIME, 0, FsPermission.getDirDefault(), "", "", null, PATH);
}
Also used : FileStatus(org.apache.hadoop.fs.FileStatus) Test(org.junit.Test)

Example 10 with FileStatus

use of org.apache.hadoop.fs.FileStatus in project hadoop by apache.

the class GenericOptionsParser method expandWildcard.

private void expandWildcard(List<String> finalPaths, Path path, FileSystem fs) throws IOException {
    FileStatus status = fs.getFileStatus(path);
    if (!status.isDirectory()) {
        throw new FileNotFoundException(path + " is not a directory.");
    }
    // get all the jars in the directory
    List<Path> jars = FileUtil.getJarsInDirectory(path.toString(), fs.equals(FileSystem.getLocal(conf)));
    if (jars.isEmpty()) {
        LOG.warn(path + " does not have jars in it. It will be ignored.");
    } else {
        for (Path jar : jars) {
            finalPaths.add(jar.makeQualified(fs.getUri(), fs.getWorkingDirectory()).toString());
        }
    }
}
Also used : Path(org.apache.hadoop.fs.Path) FileStatus(org.apache.hadoop.fs.FileStatus) FileNotFoundException(java.io.FileNotFoundException)

Aggregations

FileStatus (org.apache.hadoop.fs.FileStatus)1156 Path (org.apache.hadoop.fs.Path)910 FileSystem (org.apache.hadoop.fs.FileSystem)417 Test (org.junit.Test)372 IOException (java.io.IOException)296 Configuration (org.apache.hadoop.conf.Configuration)187 ArrayList (java.util.ArrayList)175 FileNotFoundException (java.io.FileNotFoundException)136 LocatedFileStatus (org.apache.hadoop.fs.LocatedFileStatus)105 FsPermission (org.apache.hadoop.fs.permission.FsPermission)86 FSDataInputStream (org.apache.hadoop.fs.FSDataInputStream)67 FSDataOutputStream (org.apache.hadoop.fs.FSDataOutputStream)65 HashMap (java.util.HashMap)54 File (java.io.File)41 URI (java.net.URI)41 PathFilter (org.apache.hadoop.fs.PathFilter)38 BufferedReader (java.io.BufferedReader)30 InputStreamReader (java.io.InputStreamReader)30 BlockLocation (org.apache.hadoop.fs.BlockLocation)30 HdfsFileStatus (org.apache.hadoop.hdfs.protocol.HdfsFileStatus)30