|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.io.OutputStream
edu.rice.cs.plt.io.DirectOutputStream
public abstract class DirectOutputStream
An OutputStream
that supports writing directly from an InputStream
. This class
provides default implementations defined in terms of InputStream
and OutputStream
methods. Subclasses can override (at least) writeAll(InputStream, byte[])
and
write(InputStream, int, byte[])
to provide better implementations (by, for example,
not invoking OutputStream.write(byte[])
).
Also guarantees that, consistent with the Writer
class, all write operations are
by default defined in terms of the (declared abstract) write(byte[], int, int)
method.
DirectWriter
,
DirectInputStream
,
DirectReader
Field Summary | |
---|---|
protected static int |
DEFAULT_BUFFER_SIZE
|
Constructor Summary | |
---|---|
DirectOutputStream()
|
Method Summary | |
---|---|
void |
write(byte[] bbuf)
Delegate to the more general write(byte[], int, int) method |
abstract void |
write(byte[] bbuf,
int offset,
int bytes)
Subclasses are, at a minimum, required to implement this method. |
int |
write(InputStream in,
int bytes)
Write some number of bytes, using the provided InputStream as input. |
int |
write(InputStream in,
int bytes,
byte[] buffer)
Write some number of bytes, using the provided InputStream as input. |
int |
write(InputStream in,
int bytes,
int bufferSize)
Write some number of bytes, using the provided InputStream as input. |
void |
write(int b)
Delegate to the more general write(byte[], int, int) method |
int |
writeAll(InputStream in)
Write the full contents of the given InputStream to this stream. |
int |
writeAll(InputStream in,
byte[] buffer)
Write the full contents of the given InputStream to this stream. |
int |
writeAll(InputStream in,
int bufferSize)
Write the full contents of the given InputStream to this stream. |
Methods inherited from class java.io.OutputStream |
---|
close, flush |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected static final int DEFAULT_BUFFER_SIZE
Constructor Detail |
---|
public DirectOutputStream()
Method Detail |
---|
public void write(int b) throws IOException
write(byte[], int, int)
method
write
in class OutputStream
IOException
public void write(byte[] bbuf) throws IOException
write(byte[], int, int)
method
write
in class OutputStream
IOException
public abstract void write(byte[] bbuf, int offset, int bytes) throws IOException
write
in class OutputStream
IOException
public int write(InputStream in, int bytes) throws IOException
InputStream
as input. Fewer bytes
may be written if the input stream has fewer available. The default implementation
invokes write(InputStream, int, int)
with the minimum of bytes
and
DEFAULT_BUFFER_SIZE
. Subclasses that do not rely on a buffer in
write(InputStream, int, byte[])
should override this method.
in
- A stream to be read frombytes
- The number of bytes to write
-1
if the input stream is at the end of file; otherwise, the number of characters
written
IOException
- If an error occurs during reading or writingpublic int write(InputStream in, int bytes, int bufferSize) throws IOException
InputStream
as input. Fewer bytes
may be written if the input stream has fewer available. The default implementation
invokes write(InputStream, int, byte[])
with a newly-allocated array of the given size.
Subclasses that do not rely on a buffer in write(InputStream, int, byte[])
should override this method.
in
- A stream to be read frombytes
- The number of bytes to writebufferSize
- The size of buffer to use (if necessary). Smaller values may reduce the amount of
memory required; larger values may increase performance on large readers
-1
if the input stream is at the end of file; otherwise, the number of characters
written
IOException
- If an error occurs during reading or writing
IllegalArgumentException
- If bufferSize <= 0
public int write(InputStream in, int bytes, byte[] buffer) throws IOException
InputStream
as input. Fewer bytes
may be written if the input stream has fewer available. The given buffer is useful
in repeated write
invocations to avoid unnecessary memory allocation. The default
implementation repeatedly fills the given buffer via a
InputStream.read(byte[], int, int)
operation, then writes it via
OutputStream.write(byte[], int, int)
. Subclasses that do not require an external buffer
should override this method.
in
- A stream to be read frombytes
- The number of bytes to writebuffer
- A buffer used to copy bytes from the input stream to this stream. Note that this is only
used to avoid unnecessary memory allocation. No assumptions are made about the buffer's
contents (which may be overwritten), and no assumptions should be made about the contents
of the buffer after the method invocation.
-1
if the input stream is at the end of file; otherwise, the number of characters
written
IOException
- If an error occurs during reading or writing
IllegalArgumentException
- If buffer
has size 0
public int writeAll(InputStream in) throws IOException
InputStream
to this stream. The method will block
until an end-of-file is reached. The default implementation invokes
writeAll(InputStream, int)
with DEFAULT_BUFFER_SIZE
. Subclasses that know the
size of this stream's remaining contents, or that do not rely on a buffer in
writeAll(InputStream, byte[])
, should override this method.
in
- A stream to be read from
-1
if the input stream is at the end of file; otherwise, the number of characters
written (or, if the number is too large, Integer.MAX_VALUE
)
IOException
- If an error occurs during reading or writingpublic int writeAll(InputStream in, int bufferSize) throws IOException
InputStream
to this stream. The method will block
until an end-of-file is reached. The default implementation invokes
writeAll(InputStream, byte[])
with a newly-allocated array of the given size. Subclasses
that do not rely on a buffer in writeAll(InputStream, byte[])
should override this method.
in
- A stream to be read frombufferSize
- The size of buffer to use (if necessary). Smaller values may reduce the amount of
memory required; larger values may increase performance on large readers
-1
if the input stream is at the end of file; otherwise, the number of characters
written (or, if the number is too large, Integer.MAX_VALUE
)
IOException
- If an error occurs during reading or writing
IllegalArgumentException
- If bufferSize <= 0
public int writeAll(InputStream in, byte[] buffer) throws IOException
InputStream
to this stream. The given buffer is useful
in repeated writeAll
invocations to avoid unnecessary memory allocation. The method will
block until an end-of-file is reached. The default implementation repeatedly fills the given buffer
via a InputStream.read(byte[])
operation, then writes it via OutputStream.write(byte[])
.
Subclasses that do not require an external buffer should override this method.
in
- A stream to be read frombuffer
- A buffer used to copy bytes from the input stream to this stream. Note that this is only
used to avoid unnecessary memory allocation. No assumptions are made about the buffer's
contents (which may be overwritten), and no assumptions should be made about the contents
of the buffer after the method invocation.
-1
if the input stream is at the end of file; otherwise, the number of characters
written (or, if the number is too large, Integer.MAX_VALUE
)
IOException
- If an error occurs during reading or writing
IllegalArgumentException
- If buffer
has size 0
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |