public class MultiPartOutputStream extends OutputStream
OutputStream which packages data written to it into discrete StreamParts which can be obtained
in a separate thread via iteration and uploaded to S3.
A single MultiPartOutputStream is allocated a range of part numbers it can assign to the StreamParts
it produces, which is determined at construction.
Creating a StreamPart is triggered when checkSize() is called and the stream
holds enough data, so be sure to call this regularly when writing data. It's also essential to call
close() when finished so that it can create the final StreamPart and consumers
can finish.
| Modifier and Type | Field and Description |
|---|---|
static int |
S3_MIN_PART_SIZE |
| Constructor and Description |
|---|
MultiPartOutputStream(int partNumberStart,
int partNumberEnd,
int partSize,
BlockingQueue<alex.mojaki.s3upload.StreamPart> queue)
Creates a new stream that will produce parts of the given size with part numbers in the given range.
|
| Modifier and Type | Method and Description |
|---|---|
void |
checkSize()
Checks if the stream currently contains enough data to create a new part.
|
void |
close()
Packages any remaining data into a
StreamPart and signals to the StreamTransferManager that there are no more parts
afterwards. |
String |
toString() |
void |
write(byte[] b) |
void |
write(byte[] b,
int off,
int len) |
void |
write(int b) |
flushpublic static final int S3_MIN_PART_SIZE
public MultiPartOutputStream(int partNumberStart,
int partNumberEnd,
int partSize,
BlockingQueue<alex.mojaki.s3upload.StreamPart> queue)
partNumberStart - the part number of the first part the stream will produce. Minimum 1.partNumberEnd - 1 more than the last part number that the parts are allowed to have. Maximum 10 001.partSize - the minimum size in bytes of parts to be produced.queue - where stream parts are put on production.public void checkSize()
throws InterruptedException
Internally this puts the part on a queue, which if full will cause this method to block and potentially
throw an InterruptedException, in which case retrying is acceptable.
InterruptedExceptionpublic void write(int b)
write in class OutputStreampublic void write(byte[] b,
int off,
int len)
write in class OutputStreampublic void write(byte[] b)
write in class OutputStreampublic void close()
StreamPart and signals to the StreamTransferManager that there are no more parts
afterwards. You cannot write to the stream after it has been closed.close in interface Closeableclose in interface AutoCloseableclose in class OutputStreamCopyright © 2015. All rights reserved.