|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectjava.io.OutputStream
it.unimi.dsi.fastutil.io.MeasurableOutputStream
it.unimi.dsi.fastutil.io.FastBufferedOutputStream
public class FastBufferedOutputStream
Lightweight, unsynchronized output stream buffering class with measurability and repositionability.
This class provides buffering for output streams, but it does so with
purposes and an internal logic that are radically different from the ones
adopted in BufferedOutputStream. The main features follow.
All methods are unsychronized.
As an additional feature, this class implements the RepositionableStream and MeasurableStream interfaces.
An instance of this class will try to cast
the underlying byte stream to a RepositionableStream and to fetch by
reflection the FileChannel underlying the given
output stream, in this order. If either reference can be successfully
fetched, you can use position(long) to reposition the stream.
Much in the same way, an instance of this class will try to cast the
the underlying byte stream to a MeasurableStream, and if this
operation is successful, or if a FileChannel can
be detected, then position() and length() will work as expected.
| Field Summary | |
|---|---|
static int |
DEFAULT_BUFFER_SIZE
The default size of the internal buffer in bytes (8Ki). |
| Constructor Summary | |
|---|---|
FastBufferedOutputStream(OutputStream os)
Creates a new fast buffered ouptut stream by wrapping a given output stream with a buffer of DEFAULT_BUFFER_SIZE bytes. |
|
FastBufferedOutputStream(OutputStream os,
int bufferSize)
Creates a new fast buffered output stream by wrapping a given output stream with a given buffer size. |
|
| Method Summary | |
|---|---|
void |
close()
|
void |
flush()
|
long |
length()
Returns the length of the underlying output stream, if it is measurable. |
long |
position()
Returns the current stream position. |
void |
position(long newPosition)
Repositions the stream. |
void |
write(byte[] b,
int offset,
int length)
|
void |
write(int b)
|
| Methods inherited from class java.io.OutputStream |
|---|
write |
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final int DEFAULT_BUFFER_SIZE
| Constructor Detail |
|---|
public FastBufferedOutputStream(OutputStream os,
int bufferSize)
os - an output stream to wrap.bufferSize - the size in bytes of the internal buffer.public FastBufferedOutputStream(OutputStream os)
DEFAULT_BUFFER_SIZE bytes.
os - an output stream to wrap.| Method Detail |
|---|
public void write(int b)
throws IOException
write in class OutputStreamIOException
public void write(byte[] b,
int offset,
int length)
throws IOException
write in class OutputStreamIOException
public void flush()
throws IOException
flush in interface Flushableflush in class OutputStreamIOException
public void close()
throws IOException
close in interface Closeableclose in class OutputStreamIOException
public long position()
throws IOException
RepositionableStream
position in interface MeasurableStreamposition in interface RepositionableStreamIOException
public void position(long newPosition)
throws IOException
Note that this method performs a flush() before changing the underlying stream position.
position in interface RepositionableStreamnewPosition - the new stream position.
IOException
public long length()
throws IOException
Note that this method performs a flush() before detecting the length.
length in interface MeasurableStreamUnsupportedOperationException - if the underlying output stream is not measurable and
cannot provide a FileChannel.
IOException
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||