Package org.apache.hadoop.fs
Class FSDataOutputStreamBuilder<S extends FSDataOutputStream,B extends FSDataOutputStreamBuilder<S,B>>
java.lang.Object
org.apache.hadoop.fs.impl.AbstractFSBuilderImpl<S,B>
org.apache.hadoop.fs.FSDataOutputStreamBuilder<S,B>
- All Implemented Interfaces:
FSBuilder<S,B>
@Public
@Evolving
public abstract class FSDataOutputStreamBuilder<S extends FSDataOutputStream,B extends FSDataOutputStreamBuilder<S,B>>
extends AbstractFSBuilderImpl<S,B>
Builder for
FSDataOutputStream and its subclasses.
It is used to create FSDataOutputStream when creating a new file or
appending an existing file on FileSystem.
By default, it does not create parent directory that do not exist.
FileSystem.createNonRecursive(Path, boolean, int, short, long, Progressable).
To create missing parent directory, use recursive().
To be more generic, AbstractFSBuilderImpl.opt(String, int) and AbstractFSBuilderImpl.must(String, int)
variants provide implementation-agnostic way to customize the builder.
Each FS-specific builder implementation can interpret the FS-specific
options accordingly, for example:
// Don't
if (fs instanceof FooFileSystem) {
FooFileSystem fs = (FooFileSystem) fs;
OutputStream out = dfs.createFile(path)
.optionA()
.optionB("value")
.cache()
.build()
} else if (fs instanceof BarFileSystem) {
...
}
// Do
OutputStream out = fs.createFile(path)
.permission(perm)
.bufferSize(bufSize)
.opt("foofs:option.a", true)
.opt("foofs:option.b", "value")
.opt("barfs:cache", true)
.must("foofs:cache", true)
.must("barfs:cache-size", 256 * 1024 * 1024)
.build();
If the option is not related to the file system, the option will be ignored.
If the option is must, but not supported by the file system, a
IllegalArgumentException will be thrown.-
Field Summary
Fields inherited from class org.apache.hadoop.fs.impl.AbstractFSBuilderImpl
UNKNOWN_MANDATORY_KEY -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedFSDataOutputStreamBuilder(FileSystem fileSystem, Path p) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionappend()Append to an existing file (optional operation).blockSize(long blkSize) Set block size.bufferSize(int bufSize) Set the size of the buffer to be used.abstract Sbuild()Create the FSDataOutputStream to write on the file system.checksumOpt(org.apache.hadoop.fs.Options.ChecksumOpt chksumOpt) Set checksum opt.create()Create an FSDataOutputStream at the specified path.protected longprotected intprotected org.apache.hadoop.fs.Options.ChecksumOptprotected EnumSet<CreateFlag>getFlags()protected FileSystemgetFS()protected FsPermissionprotected Progressableprotected shortabstract BReturn the concrete implementation of the builder instance.protected booleanReturn true to create the parent directories if they do not exist.overwrite(boolean overwrite) Set to true to overwrite the existing file.permission(FsPermission perm) Set permission for the file.progress(Progressable prog) Set the facility of reporting progress.Create the parent directory if they do not exist.replication(short replica) Set replication factor.Methods inherited from class org.apache.hadoop.fs.impl.AbstractFSBuilderImpl
getMandatoryKeys, getOptionalKeys, getOptionalPath, getOptionalPathHandle, getOptions, getPath, getPathHandle, must, must, must, must, must, must, must, mustDouble, mustLong, opt, opt, opt, opt, opt, opt, opt, optDouble, optLong, rejectUnknownMandatoryKeys, rejectUnknownMandatoryKeys
-
Constructor Details
-
FSDataOutputStreamBuilder
Constructor.- Parameters:
fileSystem- file system.p- the path.
-
-
Method Details
-
getThisBuilder
Return the concrete implementation of the builder instance.- Overrides:
getThisBuilderin classAbstractFSBuilderImpl<S extends FSDataOutputStream,B extends FSDataOutputStreamBuilder<S, B>> - Returns:
- this object, typecast
-
getFS
-
getPermission
-
permission
Set permission for the file.- Parameters:
perm- permission.- Returns:
- B Generics Type.
-
getBufferSize
protected int getBufferSize() -
bufferSize
Set the size of the buffer to be used.- Parameters:
bufSize- buffer size.- Returns:
- Generics Type B.
-
getReplication
protected short getReplication() -
replication
Set replication factor.- Parameters:
replica- replica.- Returns:
- Generics Type B.
-
getBlockSize
protected long getBlockSize() -
blockSize
Set block size.- Parameters:
blkSize- block size.- Returns:
- B Generics Type.
-
isRecursive
protected boolean isRecursive()Return true to create the parent directories if they do not exist.- Returns:
- if create the parent directories if they do not exist true,not false.
-
recursive
Create the parent directory if they do not exist.- Returns:
- B Generics Type.
-
getProgress
-
progress
Set the facility of reporting progress.- Parameters:
prog- progress.- Returns:
- B Generics Type.
-
getFlags
-
create
Create an FSDataOutputStream at the specified path.- Returns:
- return Generics Type B.
-
overwrite
Set to true to overwrite the existing file. Set it to false, an exception will be thrown when callingbuild()if the file exists.- Parameters:
overwrite- overrite.- Returns:
- Generics Type B.
-
append
Append to an existing file (optional operation).- Returns:
- Generics Type B.
-
getChecksumOpt
protected org.apache.hadoop.fs.Options.ChecksumOpt getChecksumOpt() -
checksumOpt
Set checksum opt.- Parameters:
chksumOpt- check sum opt.- Returns:
- Generics Type B.
-
build
Create the FSDataOutputStream to write on the file system.- Returns:
- generic type S.
- Throws:
IllegalArgumentException- if the parameters are not valid.IOException- on errors when file system creates or appends the file.
-