public final class PrivateOutputStream extends OutputStream
Constructor and Description |
---|
PrivateOutputStream(BaseStream p,
int maxSize)
Creates an empty
PrivateOutputStream to write to. |
Modifier and Type | Method and Description |
---|---|
void |
close()
Closes the output stream.
|
boolean |
isClosed()
Determines if the connection is closed
|
byte[] |
readBytes(int size)
Reads the bytes that have been written to this stream.
|
int |
size()
Determines how many bytes have been written to the output stream.
|
void |
write(byte[] buffer)
Writes
b.length bytes from the specified byte array
to this output stream. |
void |
write(byte[] buffer,
int offset,
int count)
Writes
len bytes from the specified byte array
starting at offset off to this output stream. |
void |
write(int b)
Writes the specified byte to this output stream.
|
flush
public PrivateOutputStream(BaseStream p, int maxSize)
PrivateOutputStream
to write to.p
- the connection that this stream runs overpublic int size()
public void write(int b) throws IOException
write
in class OutputStream
b
- the byte to writeIOException
- if an I/O error occurspublic void write(byte[] buffer) throws IOException
OutputStream
b.length
bytes from the specified byte array
to this output stream. The general contract for write(b)
is that it should have exactly the same effect as the call
write(b, 0, b.length)
.write
in class OutputStream
buffer
- the data.IOException
- if an I/O error occurs.OutputStream.write(byte[], int, int)
public void write(byte[] buffer, int offset, int count) throws IOException
OutputStream
len
bytes from the specified byte array
starting at offset off
to this output stream.
The general contract for write(b, off, len)
is that
some of the bytes in the array b
are written to the
output stream in order; element b[off]
is the first
byte written and b[off+len-1]
is the last byte written
by this operation.
The write
method of OutputStream
calls
the write method of one argument on each of the bytes to be
written out. Subclasses are encouraged to override this method and
provide a more efficient implementation.
If b
is null
, a
NullPointerException
is thrown.
If off
is negative, or len
is negative, or
off+len
is greater than the length of the array
b
, then an IndexOutOfBoundsException is thrown.
write
in class OutputStream
buffer
- the data.offset
- the start offset in the data.count
- the number of bytes to write.IOException
- if an I/O error occurs. In particular,
an IOException
is thrown if the output
stream is closed.public byte[] readBytes(int size)
size
- the size of the array to returnpublic void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
close
in class OutputStream
IOException
- this will never happenpublic boolean isClosed()
true
if the connection is closed; false
if the connection is open