Search in sources :

Example 1 with CreateOpts

use of org.apache.hadoop.fs.Options.CreateOpts in project hadoop by apache.

the class FileContextTestHelper method appendToFile.

public static void appendToFile(FileContext fc, Path path, int numBlocks, CreateOpts... options) throws IOException {
    BlockSize blockSizeOpt = CreateOpts.getOpt(CreateOpts.BlockSize.class, options);
    long blockSize = blockSizeOpt != null ? blockSizeOpt.getValue() : DEFAULT_BLOCK_SIZE;
    FSDataOutputStream out;
    out = fc.create(path, EnumSet.of(CreateFlag.APPEND));
    byte[] data = getFileData(numBlocks, blockSize);
    out.write(data, 0, data.length);
    out.close();
}
Also used : CreateOpts(org.apache.hadoop.fs.Options.CreateOpts) BlockSize(org.apache.hadoop.fs.Options.CreateOpts.BlockSize)

Example 2 with CreateOpts

use of org.apache.hadoop.fs.Options.CreateOpts in project hadoop by apache.

the class FileSystemTestWrapper method create.

@Override
public FSDataOutputStream create(Path f, EnumSet<CreateFlag> createFlag, CreateOpts... opts) throws AccessControlException, FileAlreadyExistsException, FileNotFoundException, ParentNotDirectoryException, UnsupportedFileSystemException, IOException {
    // Need to translate the FileContext-style options into FileSystem-style
    // Permissions with umask
    CreateOpts.Perms permOpt = CreateOpts.getOpt(CreateOpts.Perms.class, opts);
    FsPermission umask = FsPermission.getUMask(fs.getConf());
    FsPermission permission = (permOpt != null) ? permOpt.getValue() : FsPermission.getFileDefault().applyUMask(umask);
    permission = permission.applyUMask(umask);
    // Overwrite
    boolean overwrite = createFlag.contains(CreateFlag.OVERWRITE);
    // bufferSize
    int bufferSize = fs.getConf().getInt(CommonConfigurationKeysPublic.IO_FILE_BUFFER_SIZE_KEY, CommonConfigurationKeysPublic.IO_FILE_BUFFER_SIZE_DEFAULT);
    CreateOpts.BufferSize bufOpt = CreateOpts.getOpt(CreateOpts.BufferSize.class, opts);
    bufferSize = (bufOpt != null) ? bufOpt.getValue() : bufferSize;
    // replication
    short replication = fs.getDefaultReplication(f);
    CreateOpts.ReplicationFactor repOpt = CreateOpts.getOpt(CreateOpts.ReplicationFactor.class, opts);
    replication = (repOpt != null) ? repOpt.getValue() : replication;
    // blockSize
    long blockSize = fs.getDefaultBlockSize(f);
    CreateOpts.BlockSize blockOpt = CreateOpts.getOpt(CreateOpts.BlockSize.class, opts);
    blockSize = (blockOpt != null) ? blockOpt.getValue() : blockSize;
    // Progressable
    Progressable progress = null;
    CreateOpts.Progress progressOpt = CreateOpts.getOpt(CreateOpts.Progress.class, opts);
    progress = (progressOpt != null) ? progressOpt.getValue() : progress;
    return fs.create(f, permission, overwrite, bufferSize, replication, blockSize, progress);
}
Also used : CreateOpts(org.apache.hadoop.fs.Options.CreateOpts) Progressable(org.apache.hadoop.util.Progressable) FsPermission(org.apache.hadoop.fs.permission.FsPermission) BlockSize(org.apache.hadoop.fs.Options.CreateOpts.BlockSize)

Example 3 with CreateOpts

use of org.apache.hadoop.fs.Options.CreateOpts in project hadoop by apache.

the class FileContextTestHelper method createFile.

/*
   * Create files with numBlocks blocks each with block size blockSize.
   */
public static long createFile(FileContext fc, Path path, int numBlocks, CreateOpts... options) throws IOException {
    BlockSize blockSizeOpt = CreateOpts.getOpt(CreateOpts.BlockSize.class, options);
    long blockSize = blockSizeOpt != null ? blockSizeOpt.getValue() : DEFAULT_BLOCK_SIZE;
    FSDataOutputStream out = fc.create(path, EnumSet.of(CreateFlag.CREATE), options);
    byte[] data = getFileData(numBlocks, blockSize);
    out.write(data, 0, data.length);
    out.close();
    return data.length;
}
Also used : CreateOpts(org.apache.hadoop.fs.Options.CreateOpts) BlockSize(org.apache.hadoop.fs.Options.CreateOpts.BlockSize)

Example 4 with CreateOpts

use of org.apache.hadoop.fs.Options.CreateOpts in project hadoop by apache.

the class FileContextTestWrapper method createFile.

/*
   * Create files with numBlocks blocks each with block size blockSize.
   */
public long createFile(Path path, int numBlocks, CreateOpts... options) throws IOException {
    BlockSize blockSizeOpt = CreateOpts.getOpt(CreateOpts.BlockSize.class, options);
    long blockSize = blockSizeOpt != null ? blockSizeOpt.getValue() : DEFAULT_BLOCK_SIZE;
    FSDataOutputStream out = fc.create(path, EnumSet.of(CreateFlag.CREATE), options);
    byte[] data = getFileData(numBlocks, blockSize);
    out.write(data, 0, data.length);
    out.close();
    return data.length;
}
Also used : CreateOpts(org.apache.hadoop.fs.Options.CreateOpts) BlockSize(org.apache.hadoop.fs.Options.CreateOpts.BlockSize)

Example 5 with CreateOpts

use of org.apache.hadoop.fs.Options.CreateOpts in project hadoop by apache.

the class FileContextTestWrapper method appendToFile.

public void appendToFile(Path path, int numBlocks, CreateOpts... options) throws IOException {
    BlockSize blockSizeOpt = CreateOpts.getOpt(CreateOpts.BlockSize.class, options);
    long blockSize = blockSizeOpt != null ? blockSizeOpt.getValue() : DEFAULT_BLOCK_SIZE;
    FSDataOutputStream out;
    out = fc.create(path, EnumSet.of(CreateFlag.APPEND));
    byte[] data = getFileData(numBlocks, blockSize);
    out.write(data, 0, data.length);
    out.close();
}
Also used : CreateOpts(org.apache.hadoop.fs.Options.CreateOpts) BlockSize(org.apache.hadoop.fs.Options.CreateOpts.BlockSize)

Aggregations

CreateOpts (org.apache.hadoop.fs.Options.CreateOpts)9 BlockSize (org.apache.hadoop.fs.Options.CreateOpts.BlockSize)7 FsPermission (org.apache.hadoop.fs.permission.FsPermission)3 IOException (java.io.IOException)2 Progressable (org.apache.hadoop.util.Progressable)2 HadoopIllegalArgumentException (org.apache.hadoop.HadoopIllegalArgumentException)1 ChecksumOpt (org.apache.hadoop.fs.Options.ChecksumOpt)1