|
IBM WebSphereTM eXtreme Scale, Release 8.6 API Specification |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.io.OutputStream com.ibm.websphere.objectgrid.io.XsDataOutputStream
public abstract class XsDataOutputStream
An abstract extension of standard i/o stream
for writing primitive types and string
in random accessible, byte-oriented, cross-language manner specifically for internal usage of
WebSphere eXtreme Scale plug-ins.
This stream combines the facilities of
ByteArrayOutputStream
DataOutput
ByteBuffer
.
Resource Allocation: The stream must grow on demand as the bytes
are being written. The actual bytes being written should be allocated in a
a flexible manner that allows both in-memory and off-heap allocation.
The written bytes are accessible via toByteArray()
methods as a single,
contiguous array of bytes. Or can be transferred to a given ByteBuffer
via toByteBuffer(ByteBuffer) method.
Random Access: The data is written at the current position()
.
The caller can, however, position
the stream at any
location. If the position is beyond the current size
of the
stream, new bytes must be allocated.
Data Type Support: The standard fixed-length, signed, primitive Java data types
are supported as in DataOutput
interface. However, for cross-language data
portability, this Java based interface also supports unsigned value of Java primitive types via
wider signed type value. For example, an unsigned 2-byte short could be
written by writeUnsignedShort(int)
supplying a 4-byte integer value as input.
String Encoding: Strings are written, by default, as encoded (by UTF-8 scheme)
array of bytes preceded by a 2-byte integral number designating number of encoded bytes.
The encoding scheme can be specified per string basis or default scheme can be changed via
setEncodingScheme(String)
method. The default encoding
scheme at construction is UTF-8.
Optionally, raw encoded bytes could be written without the length header.
Optionally, a single-byte null character could be appended after the encoded bytes.
Byte Arrays: byte arrays are written directly to the output stream with no conversion. Attempting to write a null byte array will result in a NullPointerException.
Null Handling: Null Strings or array can not be written and will throw NullPointerException when supplied as input.
Byte Ordering: Multi-byte data can be written in either
BIG ENDIAN or LITTLE ENDIAN form. By default, the data is
written in the BIG_ENDIAN order
.
The user can set the default
byte order.
This class is not intended as a base class for user code to extend. Instances of XsDataInputStream are provided solely by the WebSphere eXtreme Scale runtime for use by plug-ins.
Constructor Summary | |
---|---|
XsDataOutputStream()
|
Method Summary | |
---|---|
abstract ByteOrder |
getByteOrder()
Gets the byte order for writing multi-byte data. |
abstract String |
getEncodingScheme()
Gets canonical name of the current string encoding scheme. |
abstract boolean |
isClosed()
Affirms if this stream has been closed. |
abstract int |
position()
Gets the current position of this stream. |
abstract XsDataOutputStream |
position(int i)
Sets the position of this stream at the given byte index. |
abstract XsDataOutputStream |
rewind()
Restores this stream at the initial state at its construction. |
abstract boolean |
setByteOrder(ByteOrder order)
Sets the byte order of the data. |
abstract void |
setEncodingScheme(String enc)
Sets the current string encoding scheme. |
abstract int |
size()
Gets the current size of this stream in number of bytes. |
abstract byte[] |
toByteArray()
Gets a copy of the underlying bytes. |
abstract ByteBuffer |
toByteBuffer(ByteBuffer buf)
Writes the content of this stream on to the given buffer starting at its current position. |
abstract void |
writeBoolean(boolean bool)
Writes a single byte for the given boolean value. |
abstract void |
writeByte(byte b)
Writes a single byte for the signed value of the given byte. |
abstract void |
writeChar(char c)
Writes a 2-byte value for the given character in the current byte order. |
abstract void |
writeChars(char[] c)
Writes an array of 2-byte values for the given character in the current byte order. |
abstract void |
writeDouble(double d)
Writes a 8-byte value for the given floating point number in the current byte order. |
abstract void |
writeFloat(float f)
Writes a 4-byte value for the given floating point number in the current byte order. |
abstract void |
writeInt(int i)
Writes a 4-byte value for the given integral number in the current byte order. |
abstract void |
writeLong(long l)
Writes a 8-byte value for the given integral number in the current byte order. |
abstract void |
writeShort(short s)
Writes a 2-byte value for the given integral number in the current byte order. |
abstract int |
writeString(String s)
Writes the given string as array of bytes encoded in current encoding scheme. |
abstract int |
writeString(String s,
String encoding)
Writes the given string as array of bytes encoded by given encoding scheme. |
abstract int |
writeString(String s,
String encoding,
boolean raw,
boolean nullTerminate)
Writes the given string as array of bytes encoded by the given encoding scheme. |
abstract int |
writeStringAsNullTerminated(String s)
Writes the given string as array of bytes encoded by current encoding scheme. |
abstract int |
writeStringAsNullTerminated(String s,
String encoding)
Writes the given string as array of bytes encoded by the given encoding scheme. |
abstract int |
writeStringRaw(String s)
Writes the given string as array of bytes encoded by the current encoding scheme. |
abstract int |
writeStringRaw(String s,
String encoding)
Writes the given string as array of bytes encoded by the given encoding scheme. |
abstract void |
writeUnsignedByte(int b)
Writes a single byte as the unsigned byte value (i.e. |
abstract void |
writeUnsignedShort(int s)
Writes 2-byte as the unsigned short value (i.e. |
abstract int |
writeUTF8String(String s)
Writes the given string as an array of bytes encoded as UTF-8. |
abstract void |
writeVarint(int i)
Writes a variable length integer value for the given integral number. |
abstract void |
writeVarint(long i)
Writes a variable length integer value for the given integral number. |
Methods inherited from class java.io.OutputStream |
---|
close, flush, write, write, write |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public XsDataOutputStream()
Method Detail |
---|
public abstract int size()
public abstract int position()
public abstract XsDataOutputStream position(int i) throws IOException
IOException
public abstract XsDataOutputStream rewind() throws IOException
IOException
public abstract byte[] toByteArray()
public abstract ByteBuffer toByteBuffer(ByteBuffer buf) throws IOException
buf
- a buffer where the content of this stream will be written.
IOException
public abstract void writeBoolean(boolean bool) throws IOException
IOException
public abstract void writeByte(byte b) throws IOException
IOException
public abstract void writeUnsignedByte(int b) throws IOException
IOException
public abstract void writeChar(char c) throws IOException
IOException
public abstract void writeChars(char[] c) throws IOException
IOException
public abstract void writeInt(int i) throws IOException
IOException
public abstract void writeFloat(float f) throws IOException
IOException
public abstract void writeDouble(double d) throws IOException
IOException
public abstract void writeLong(long l) throws IOException
IOException
public abstract void writeShort(short s) throws IOException
IOException
public abstract void writeUnsignedShort(int s) throws IOException
IOException
public abstract void writeVarint(int i) throws IOException
IOException
public abstract void writeVarint(long i) throws IOException
IOException
public abstract int writeString(String s) throws IOException
s
- a string. Must not be null.
IOException
NullPointerException
- is the given string is null.
IllegalArgumentException
- when the byte length cannot be encoded in a 2-byte integral valuepublic abstract int writeString(String s, String encoding) throws IOException, UnsupportedEncodingException
s
- a string. Must not be null.encoding
- canonical name of a supported encoding scheme
IOException
NullPointerException
- is the given string is null.
UnsupportedEncodingException
IllegalArgumentException
- when the byte length cannot be encoded in a 2-byte integral valuepublic abstract int writeStringAsNullTerminated(String s) throws IOException
s
- a string. Must not be null.
IOException
public abstract int writeStringAsNullTerminated(String s, String encoding) throws IOException
s
- a string. Must not be null.encoding
- canonical name of a supported encoding scheme
IOException
public abstract int writeStringRaw(String s) throws IOException
s
- a string. Must not be null.
IOException
public abstract int writeStringRaw(String s, String encoding) throws IOException
s
- a string. Must not be null.encoding
- canonical name of a supported encoding scheme
IOException
public abstract int writeString(String s, String encoding, boolean raw, boolean nullTerminate) throws IOException
s
- a string. Must not be null.encoding
- canonical name of a supported encoding schemeraw
- if true, 2-byte length header is not written before the bytes.nullTerminate
- if true a single-byte null character is written at end of encoded bytes.
IOException
IllegalArgumentException
- when raw is false, and the byte length cannot be encoded in a 2-byte integral valuepublic abstract int writeUTF8String(String s) throws IOException
s
- a string. Must not be null
IOException
public abstract String getEncodingScheme()
public abstract void setEncodingScheme(String enc)
enc
- canonical name of an encoding scheme.public abstract boolean setByteOrder(ByteOrder order)
order
- BIG_ENDIAN or LITTLE_ENDIAN byte order
public abstract ByteOrder getByteOrder()
public abstract boolean isClosed()
|
IBM WebSphereTM eXtreme Scale, Release 8.6 API Specification |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |