|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
Object
OutputStream
public class OutputStream
The OutputStream class provides
for converting data from any of the
primitive types to a series of bytes and
writing these bytes to a binary stream.
There is also a facility for converting
a String into Java modified
UTF-8 format and writing the resulting series
of bytes.
InputStream,
ByteArray,
Value,
IS_BINARY| Constructor Summary | |
|---|---|
OutputStream(int initialCapacity)
Creates a new output stream that will write into memory buffer. |
|
| Method Summary | |
|---|---|
ByteArray |
toByteArray()
Returns the contents of memory buffer that is backing up this OutputStream. |
void |
write(ByteArray b)
Writes b.length() bytes from the specified byte array
to this output stream. |
void |
write(ByteArray b,
int off,
int len)
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. |
void |
writeBoolean(boolean v)
Writes a boolean value to this output stream. |
void |
writeByte(int v)
Writes to the output stream the eight low- order bits of the argument v. |
void |
writeChar(char v)
Writes a char value, which
is comprised of two bytes, to the
output stream. |
void |
writeInt(int v)
Writes an int value, which is
comprised of four bytes, to the output stream. |
void |
writeLong(long v)
Writes an long value, which is
comprised of four bytes, to the output stream. |
void |
writeShort(int v)
Writes two bytes to the output stream to represent the value of the argument. |
void |
writeUTF(String str)
Writes two bytes of length information to the output stream, followed by the Java modified UTF representation of every character in the string s. |
void |
writeValue(Value value)
Serializes specified structure into this output stream. |
| Methods inherited from class Object |
|---|
toString, equals, hashCode |
| Methods inherited from |
|---|
equals, getClass, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public OutputStream(int initialCapacity)
initialCapacity - initial size of memory buffer,
buffer will expand as needed.| Method Detail |
|---|
public void write(ByteArray b)
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()).
b - the data.write(ByteArray, int, int)
public void write(ByteArray b,
int off,
int len)
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 off is negative, or len is negative, or
off+len is greater than the length of the array
b, then an IndexOutOfBoundsException is thrown.
b - the data.off - the start offset in the data.len - the number of bytes to write.public void write(int b)
write is that one byte is written
to the output stream. The byte to be written is the eight
low-order bits of the argument b. The 24
high-order bits of b are ignored.
b - the byte.public void writeBoolean(boolean v)
boolean value to this output stream.
If the argument v
is true, the value (byte)1
is written; if v is false,
the value (byte)0 is written.
The byte written by this method may
be read by the
InputStream.readBoolean(),
which will then return a boolean
equal to v.
v - the boolean to be written.public void writeByte(int v)
v.
The 24 high-order bits of v
are ignored. (This means that writeByte
does exactly the same thing as write
for an integer argument.) The byte written
by this method may be read by the
InputStream.readByte(),
which will then return a byte
equal to (byte)v.
v - the byte value to be written.public void writeChar(char v)
char value, which
is comprised of two bytes, to the
output stream.
The byte values to be written, in the order
shown, are:
(byte)(0xff & (v >> 8))
(byte)(0xff & v)
The bytes written by this method may be
read by the
InputStream.readChar(), which
will then return a char equal
to (char)v.
v - the char value to be written.public void writeInt(int v)
int value, which is
comprised of four bytes, to the output stream.
The byte values to be written, in the order
shown, are:
(byte)(0xff & (v >> 24))
(byte)(0xff & (v >> 16))
(byte)(0xff & (v >> 8))
(byte)(0xff & v)
The bytes written by this method may be read
by the readInt
InputStream.readInt(),
which will then
return an int equal to v.
v - the int value to be written.public void writeLong(long v)
long value, which is
comprised of four bytes, to the output stream.
The byte values to be written, in the order
shown, are:
(byte)(0xff & (v >> 48))
(byte)(0xff & (v >> 40))
(byte)(0xff & (v >> 32))
(byte)(0xff & (v >> 24))
(byte)(0xff & (v >> 16))
(byte)(0xff & (v >> 8))
(byte)(0xff & v)
The bytes written by this method may be
read by the
InputStream.readLong(), which
will then return a long equal
to v.
v - the long value to be written.public void writeShort(int v)
(byte)(0xff & (v >> 8))
(byte)(0xff & v)
The bytes written by this method may be
read by the
InputStream.readShort(), which
will then return a short equal
to (short)v.
v - the short value to be written.public void writeUTF(String str)
s.
str - the string value to be written.public void writeValue(Value value)
value - Value to writepublic ByteArray toByteArray()
|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||