public abstract class StorageOutputStream extends OutputStream
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.
| Modifier | Constructor and Description |
|---|---|
protected |
StorageOutputStream()
Sole constructor.
|
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Closes this output stream.
|
Storage |
toStorage()
Closes this output stream if it has not already been closed and returns a
Storage object which contains the bytes that have been written to
this output stream. |
protected abstract Storage |
toStorage0()
Has to be implemented by a concrete subclass to create a
Storage
object from the bytes that have been written to this
StorageOutputStream. |
void |
write(byte[] buffer) |
void |
write(byte[] buffer,
int offset,
int length) |
void |
write(int b) |
protected abstract void |
write0(byte[] buffer,
int offset,
int length)
Has to implemented by a concrete subclass to write bytes from the given
byte array to this
StorageOutputStream. |
flushpublic final Storage toStorage() throws IOException
Storage object 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
Storage object that can be read from and deleted
independently (e.g. if the implementation writes to a file).
Storage object as described above.IOException - if an I/O error occurs.IllegalStateException - if this method has already been called.public final void write(int b)
throws IOException
write in class OutputStreamIOExceptionpublic final void write(byte[] buffer)
throws IOException
write in class OutputStreamIOExceptionpublic final void write(byte[] buffer,
int offset,
int length)
throws IOException
write in class OutputStreamIOExceptionpublic void close()
throws IOException
super.close().
This implementation never throws an IOException but a subclass
might.
close in interface Closeableclose in interface AutoCloseableclose in class OutputStreamIOException - if an I/O error occurs.protected abstract void write0(byte[] buffer,
int offset,
int length)
throws IOException
StorageOutputStream. This method gets
called by write(int), write(byte[]) and
write(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.buffer - buffer containing bytes to write.offset - start offset in the buffer.length - number of bytes to write.IOException - if an I/O error occurs.protected abstract Storage toStorage0() throws IOException
Storage
object from the bytes that have been written to this
StorageOutputStream. This method gets called by
toStorage() after the preconditions have been checked. The
implementation can also be sure that this methods gets invoked only once.Storage object as described above.IOException - if an I/O error occurs.Copyright © 2004-2012 The Apache Software Foundation. All Rights Reserved.