Class StorageOutputStream
java.lang.Object
java.io.OutputStream
org.apache.james.mime4j.storage.StorageOutputStream
- All Implemented Interfaces:
Closeable, Flushable, AutoCloseable
- Direct Known Subclasses:
CipherStorageProvider.CipherStorageOutputStream, MemoryStorageProvider.MemoryStorageOutputStream, TempFileStorageProvider.TempFileStorageOutputStream, ThresholdStorageProvider.ThresholdStorageOutputStream
This class implements an output stream that can be used to create a
Storage object. An instance of this class is obtained by calling
StorageProvider.createStorageOutputStream(). The user can then write
data to this instance and invoke toStorage() to retrieve a
Storage object that contains the data that has been written.
Note that the StorageOutputStream does not have to be closed
explicitly because toStorage() invokes close() if
necessary. Also note that toStorage() may be invoked only once. One
StorageOutputStream can create only one Storage
instance.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate booleanprivate byte[]private boolean -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes this output stream.final StorageCloses this output stream if it has not already been closed and returns aStorageobject which contains the bytes that have been written to this output stream.protected abstract StorageHas to be implemented by a concrete subclass to create aStorageobject from the bytes that have been written to thisStorageOutputStream.final voidwrite(byte[] buffer) final voidwrite(byte[] buffer, int offset, int length) final voidwrite(int b) protected abstract voidwrite0(byte[] buffer, int offset, int length) Has to implemented by a concrete subclass to write bytes from the given byte array to thisStorageOutputStream.Methods inherited from class OutputStream
flush
-
Field Details
-
singleByte
private byte[] singleByte -
closed
private boolean closed -
usedUp
private boolean usedUp
-
-
Constructor Details
-
StorageOutputStream
protected StorageOutputStream()Sole constructor.
-
-
Method Details
-
toStorage
Closes this output stream if it has not already been closed and returns aStorageobject which contains the bytes that have been written to this output stream.Note that this method may not be invoked a second time. This is because for some implementations it is not possible to create another
Storageobject that can be read from and deleted independently (e.g. if the implementation writes to a file).- Returns:
- a
Storageobject as described above. - Throws:
IOException- if an I/O error occurs.IllegalStateException- if this method has already been called.
-
write
- Specified by:
writein classOutputStream- Throws:
IOException
-
write
- Overrides:
writein classOutputStream- Throws:
IOException
-
write
- Overrides:
writein classOutputStream- Throws:
IOException
-
close
Closes this output stream. Subclasses that override this method have to invokesuper.close().This implementation never throws an
IOExceptionbut a subclass might.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classOutputStream- Throws:
IOException- if an I/O error occurs.
-
write0
Has to implemented by a concrete subclass to write bytes from the given byte array to thisStorageOutputStream. This method gets called bywrite(int),write(byte[])andwrite(byte[], int, int). All the required preconditions have already been checked by these methods, including the check if the output stream has already been closed.- Parameters:
buffer- buffer containing bytes to write.offset- start offset in the buffer.length- number of bytes to write.- Throws:
IOException- if an I/O error occurs.
-
toStorage0
Has to be implemented by a concrete subclass to create aStorageobject from the bytes that have been written to thisStorageOutputStream. This method gets called bytoStorage()after the preconditions have been checked. The implementation can also be sure that this methods gets invoked only once.- Returns:
- a
Storageobject as described above. - Throws:
IOException- if an I/O error occurs.
-