public class BasicByteSink extends Object implements ByteSink
Path.
Typically, these represent writable files.
In the case of a fragmented (parallel) write,
this would represent the directory containing
the individual partition fragment files.| Constructor and Description |
|---|
BasicByteSink(Path path)
Creates a data sink for the named path.
|
BasicByteSink(Path path,
CompressionFormat format)
Creates a data sink for the named path.
|
BasicByteSink(String path)
Creates a data sink for the named path.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
appendsExisting(WriteMode mode)
Indicates whether a write in the given mode
represents an append to an existing sink.
|
ByteSink |
authorize(FileClient client)
Creates a new sink with the same properties, but using the
specified authorization.
|
void |
cleanForOverwrite(int partitionCount)
Erases contents of the sink which do not correspond to
expected partition fragments.
|
ByteSink |
fragmentForPartition(int fragmentId)
Creates a new subordinate sink.
|
CompressionFormat |
getCompression()
Gets the compression format used for writing.
|
Path |
getPath()
Gets the path identifying the byte sink.
|
boolean |
isFragmentable()
Indicates whether the sink can be broken into
subordinate sinks for parallel writes.
|
OutputStream |
open(WriteMode mode)
Opens the sink for writing in the specified mode.
|
FileChannel |
openChannel()
Opens the sink for random access.
|
InputStream |
openForRead()
Opens the sink for reading.
|
boolean |
supportsRandomAccess()
Indicates whether the sink supports random access.
|
void |
validate(WriteMode mode,
boolean forFragments)
Performs validation of the sink configuration.
|
public BasicByteSink(String path)
The last element of the path is used
to automatically determine if the target
is compressed, and if so, what the format
is. If this is not desired, use
BasicByteSink(Path, CompressionFormat)
instead. In a parallel write using
automatic compression as described above,
the directory name will have the compressed file
suffix removed.
path - the file/directory to writepublic BasicByteSink(Path path)
The last element of the path is used
to automatically determine if the target
is compressed, and if so, what the format
is. If this is not desired, use
BasicByteSink(Path, CompressionFormat)
instead. In a parallel write using
automatic compression as described above,
the directory name will have the compressed file
suffix removed.
path - the file/directory to writepublic BasicByteSink(Path path, CompressionFormat format)
If used with a parallel write, the path is assumed to be a directory; output files will be written in this directory.
path - the file/directory to writeformat - the compression format of the
sink file(s)public Path getPath()
public CompressionFormat getCompression()
public ByteSink authorize(FileClient client)
ByteSinkIf a sink is supposed to be used with a specific authorization context, this method should be called to produce a new sink to use.
public OutputStream open(WriteMode mode) throws IOException
ByteSinkopen in interface ByteSinkmode - indicates how to handle an existing sourceIOException - if an I/O error occurs opening the sinkpublic InputStream openForRead() throws IOException
ByteSinkByteSink.appendsExisting(WriteMode).openForRead in interface ByteSinkIOException - if an I/O error occurs opening the sinkpublic boolean supportsRandomAccess()
ByteSinksupportsRandomAccess in interface ByteSinktrue if the sink supports random access,
false otherwise.ByteSink.openChannel()public FileChannel openChannel() throws IOException
ByteSinkByteSink.supportsRandomAccess() first.openChannel in interface ByteSinkIOException - if an I/O error occurs opening the sinkpublic boolean isFragmentable()
ByteSinkTypically, this is only true if the sink represents a path in some hierarchical store, such as a file system.
isFragmentable in interface ByteSinktrue if the sink can be
"fragmented", false otherwise.ByteSink.fragmentForPartition(int)public ByteSink fragmentForPartition(int fragmentId)
ByteSinkFragments are used for parallel writes; each logical partition is written to a separate fragment created from the provided source.
fragmentForPartition in interface ByteSinkfragmentId - a partition identifierpublic void cleanForOverwrite(int partitionCount)
throws IOException
ByteSinkThis method will be called by one of the nodes during a parallel write in overwrite mode to ensure only the data from the current write is present on completion of the write.
cleanForOverwrite in interface ByteSinkpartitionCount - the number of partitions expectedIOException - if an error occurs while attempting
to delete extraneous files from the target locationpublic boolean appendsExisting(WriteMode mode)
ByteSinkThis is used to determine whether file metadata needs to be written or updated. It is not always the case that this can be determined solely from the mode. For instance, an append to a non-existent file needs metadata to be written, but an append to an existing file may need to update metadata. Another example is console output, which should always write metadata, even though the sink always exists.
appendsExisting in interface ByteSinkmode - the intended write modetrue if the write represents
the creation of a new dataset, false
otherwise.public void validate(WriteMode mode, boolean forFragments) throws IOException
ByteSinkThe caller should indicate how the write will be performed so that appropriate checks can be performed. For instance, if no overwriting is allowed, the target is checked to see if it already exists.
validate in interface ByteSinkmode - the intended write modeforFragments - indicates whether the sink will
be fragmented for the writeIOException - if an I/O error occurs while
validating the sourceCopyright © 2016 Actian Corporation. All rights reserved.