public class MultiFileOutputStream extends java.io.OutputStream implements OnFileDelete
Modifier and Type | Field and Description |
---|---|
private boolean |
closed |
private int |
currFileBytesWritten
Number of bytes that have been written to the current file.
|
(package private) static int |
DEFAULT_PART_SIZE |
private long |
diskLimit |
private java.util.concurrent.Semaphore |
diskPermits
null means no blocking necessary.
|
private int |
filesCreated |
private java.lang.String |
namePrefix |
private UploadObjectObserver |
observer |
private java.io.FileOutputStream |
os |
private long |
partSize |
private java.io.File |
root |
private long |
totalBytesWritten
Total number of bytes written to all files so far.
|
Constructor and Description |
---|
MultiFileOutputStream()
Construct an instance to use the default temporary directory and temp
file naming convention.
|
MultiFileOutputStream(java.io.File root,
java.lang.String namePrefix)
Construct an instance to use the specified directory for temp file
creations, and the specified prefix for temp file naming.
|
Modifier and Type | Method and Description |
---|---|
private void |
blockIfNecessary()
Blocks the running thread if running out of disk space.
|
void |
cleanup() |
void |
close() |
void |
flush() |
private java.io.FileOutputStream |
fos()
Returns the file output stream to be used for writing, blocking if
necessary if running out of disk space.
|
long |
getDiskLimit() |
java.io.File |
getFile(int partNumber) |
java.lang.String |
getNamePrefix() |
int |
getNumFilesWritten() |
long |
getPartSize() |
java.io.File |
getRoot() |
long |
getTotalBytesWritten() |
MultiFileOutputStream |
init(UploadObjectObserver observer,
long partSize,
long diskLimit)
Used to initialized this stream.
|
boolean |
isClosed() |
void |
onFileDelete(FileDeletionEvent event)
Called upon a file deletion event.
|
void |
write(byte[] b)
This method would block as necessary if running out of disk space.
|
void |
write(byte[] b,
int off,
int len)
This method would block as necessary if running out of disk space.
|
void |
write(int b)
This method would block as necessary if running out of disk space.
|
(package private) static java.lang.String |
yyMMdd_hhmmss() |
static final int DEFAULT_PART_SIZE
private final java.io.File root
private final java.lang.String namePrefix
private int filesCreated
private long partSize
private long diskLimit
private UploadObjectObserver observer
private int currFileBytesWritten
private long totalBytesWritten
private java.io.FileOutputStream os
private boolean closed
private java.util.concurrent.Semaphore diskPermits
public MultiFileOutputStream()
init(UploadObjectObserver, long, long)
must be called before
this stream is considered fully initialized.public MultiFileOutputStream(java.io.File root, java.lang.String namePrefix)
init(UploadObjectObserver, long, long)
must be called before
this stream is considered fully initialized.public MultiFileOutputStream init(UploadObjectObserver observer, long partSize, long diskLimit)
AmazonS3EncryptionClient
.
Implementation of this method should never block.
observer
- the upload object observerpartSize
- part size for multi-part uploaddiskLimit
- the maximum disk space to be used for this multi-part uploadpublic void write(int b) throws java.io.IOException
write
in class java.io.OutputStream
java.io.IOException
public void write(byte[] b) throws java.io.IOException
write
in class java.io.OutputStream
java.io.IOException
public void write(byte[] b, int off, int len) throws java.io.IOException
write
in class java.io.OutputStream
java.io.IOException
private java.io.FileOutputStream fos() throws java.io.IOException
java.lang.InterruptedException
- if the running thread was interruptedjava.io.IOException
public void onFileDelete(FileDeletionEvent event)
OnFileDelete
Implementation of this method should never block.
onFileDelete
in interface OnFileDelete
event
- file deletion eventprivate void blockIfNecessary()
AbortedException
- if the running thread is interrupted while acquiring a
semaphorepublic void flush() throws java.io.IOException
flush
in interface java.io.Flushable
flush
in class java.io.OutputStream
java.io.IOException
public void close() throws java.io.IOException
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
close
in class java.io.OutputStream
java.io.IOException
public void cleanup()
public int getNumFilesWritten()
public java.io.File getFile(int partNumber)
public long getPartSize()
public java.io.File getRoot()
public java.lang.String getNamePrefix()
public long getTotalBytesWritten()
static java.lang.String yyMMdd_hhmmss()
public boolean isClosed()
public long getDiskLimit()