
public class SplittableOutputStream extends OutputStream implements SplittableOutputStreamBuilder, SplittableOutputStreamBuilder.SplitOutputStreamBuilder
Deals with structured (e.g. XML) or unstructured data.
User code must invoke beginRecord() before writing bytes, and subsequently delimit safe
splitting points by invoking endRecord(). The number of bytes written between the
call to beginRecord() and call to endRecord() must not exceed
maxSize(long) - (header.length + footer.length)
A record is defined as any bytes written between calls to #start() and
#finish(). Should the maximum file size be specified and the length of a single record (plus
header and footer) exceed the maximum then a BufferOverflowException is throw.
Common usage would be splitting files, in this case the Supplier is expected to keep
track of output file names.
Please note limitation; due to the use of Long internally, the maximum
size per-file is limited to 9223372036854775807L bytes (which is
9,223PB) per split OutputStream .
SplittableOutputStreamBuilder.SplitOutputStreamBuilder| Modifier and Type | Method and Description |
|---|---|
void |
beginRecord()
Called to mark the beginning of a record (where a "record" is any block
of bytes that can only be treated atomically; in that it's valid to split content
at the record's boundaries.
|
void |
close() |
void |
endRecord()
Called to mark the end of a record
|
SplittableOutputStreamBuilder.SplitOutputStreamBuilder |
maxCount(long numberOfRecords)
Split criteria for maximum number of records.
|
SplittableOutputStreamBuilder.SplitOutputStreamBuilder |
maxSize(long bytes)
Split criteria for maximum file size.
|
SplittableOutputStream |
outputStream()
The builder's build method.
|
static SplittableOutputStreamBuilder |
splittable(Supplier<OutputStream> next,
byte[] head,
byte[] footer)
Begin building a
SplittableOutputStream |
void |
write(byte[] bytes) |
void |
write(int b) |
flush, writepublic static SplittableOutputStreamBuilder splittable(Supplier<OutputStream> next, byte[] head, byte[] footer) throws IOException
SplittableOutputStreamnext - a Supplier of the underlying OutputStreamsheader - written at the start of each OutputStream (e.g. file header)footer - written at the end of each OutputStream (e.g. file footer)IOException - rethrows in the unlikely event the underlying ByteArrayOutputStream buffer doespublic SplittableOutputStreamBuilder.SplitOutputStreamBuilder maxSize(long bytes)
SplittableOutputStreamBuilderSplit criteria for maximum file size.
May also be composed with maximum record count criteria.
maxSize in interface SplittableOutputStreamBuilderbytes - the maximum file size permitted.SplittableOutputStreamBuilder.maxCount(long)public SplittableOutputStreamBuilder.SplitOutputStreamBuilder maxCount(long numberOfRecords)
SplittableOutputStreamBuilderSplit criteria for maximum number of records. Where the definition of a record
is any bytes written between calls to SplittableOutputStream#start() and
SplittableOutputStream#finish()
May also be composed with maximum file size criteria.
maxCount in interface SplittableOutputStreamBuildernumberOfRecords - the maximum permitted number of records per file.SplittableOutputStreamBuilder.maxSize(long)public SplittableOutputStream outputStream() throws IOException
SplittableOutputStreamBuilder.SplitOutputStreamBuilderThe builder's build method.
Note: side effect; also writes the head byte array.
outputStream in interface SplittableOutputStreamBuilder.SplitOutputStreamBuilderOutputStream for regular useIOException - if the attempt to write the head failspublic void write(int b)
throws IOException
write in class OutputStreamIOExceptionpublic void write(byte[] bytes)
throws IOException
write in class OutputStreamIOExceptionpublic void beginRecord()
endRecord()public void endRecord()
throws IOException
IOException - rethrows anything from the underlying OutputStreambeginRecord()public void close()
throws IOException
close in interface Closeableclose in interface AutoCloseableclose in class OutputStreamIOExceptionCopyright © 2017 earcam. All rights reserved.