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.
|
ByteSink |
resolveChildFragment(String childPath)
Creates a new subordinate sink.
|
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)
ByteSink
If 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
ByteSink
open
in interface ByteSink
mode
- indicates how to handle an existing sourceIOException
- if an I/O error occurs opening the sinkpublic InputStream openForRead() throws IOException
ByteSink
ByteSink.appendsExisting(WriteMode)
.openForRead
in interface ByteSink
IOException
- if an I/O error occurs opening the sinkpublic boolean supportsRandomAccess()
ByteSink
supportsRandomAccess
in interface ByteSink
true
if the sink supports random access,
false
otherwise.ByteSink.openChannel()
public FileChannel openChannel() throws IOException
ByteSink
ByteSink.supportsRandomAccess()
first.openChannel
in interface ByteSink
IOException
- if an I/O error occurs opening the sinkpublic boolean isFragmentable()
ByteSink
Typically, this is only true if the sink represents a path in some hierarchical store, such as a file system.
isFragmentable
in interface ByteSink
true
if the sink can be
"fragmented", false
otherwise.ByteSink.fragmentForPartition(int)
public ByteSink fragmentForPartition(int fragmentId)
ByteSink
Fragments are used for parallel writes; each logical partition is written to a separate fragment created from the provided source.
fragmentForPartition
in interface ByteSink
fragmentId
- a partition identifierpublic void cleanForOverwrite(int partitionCount) throws IOException
ByteSink
This 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 ByteSink
partitionCount
- the number of partitions expectedIOException
- if an error occurs while attempting
to delete extraneous files from the target locationpublic boolean appendsExisting(WriteMode mode)
ByteSink
This 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 ByteSink
mode
- 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
ByteSink
The 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 ByteSink
mode
- the intended write modeforFragments
- indicates whether the sink will
be fragmented for the writeIOException
- if an I/O error occurs while
validating the sourcepublic ByteSink resolveChildFragment(String childPath)
Fragments are used for parallel writes; each fragment generated will be a relative path from the original target of the sink,
the
- relative path of the new targetCopyright © 2020 Actian Corporation. All rights reserved.