public abstract class XsDataOutputStream extends OutputStream
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.
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 and Description |
|---|
XsDataOutputStream() |
| Modifier and Type | Method and Description |
|---|---|
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.
|
public abstract int size()
public abstract int position()
public abstract XsDataOutputStream position(int i) throws IOException
IOExceptionpublic abstract XsDataOutputStream rewind() throws IOException
IOExceptionpublic abstract byte[] toByteArray()
public abstract ByteBuffer toByteBuffer(ByteBuffer buf) throws IOException
buf - a buffer where the content of this stream will be written.IOExceptionpublic abstract void writeBoolean(boolean bool)
throws IOException
IOExceptionpublic abstract void writeByte(byte b)
throws IOException
IOExceptionpublic abstract void writeUnsignedByte(int b)
throws IOException
IOExceptionpublic abstract void writeChar(char c)
throws IOException
IOExceptionpublic abstract void writeChars(char[] c)
throws IOException
IOExceptionpublic abstract void writeInt(int i)
throws IOException
IOExceptionpublic abstract void writeFloat(float f)
throws IOException
IOExceptionpublic abstract void writeDouble(double d)
throws IOException
IOExceptionpublic abstract void writeLong(long l)
throws IOException
IOExceptionpublic abstract void writeShort(short s)
throws IOException
IOExceptionpublic abstract void writeUnsignedShort(int s)
throws IOException
IOExceptionpublic abstract void writeVarint(int i)
throws IOException
IOExceptionpublic abstract void writeVarint(long i)
throws IOException
IOExceptionpublic abstract int writeString(String s) throws IOException
s - a string. Must not be null.IOExceptionNullPointerException - 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 schemeIOExceptionNullPointerException - is the given string is null.UnsupportedEncodingExceptionIllegalArgumentException - 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.IOExceptionpublic abstract int writeStringAsNullTerminated(String s, String encoding) throws IOException
s - a string. Must not be null.encoding - canonical name of a supported encoding schemeIOExceptionpublic abstract int writeStringRaw(String s) throws IOException
s - a string. Must not be null.IOExceptionpublic abstract int writeStringRaw(String s, String encoding) throws IOException
s - a string. Must not be null.encoding - canonical name of a supported encoding schemeIOExceptionpublic 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.IOExceptionIllegalArgumentException - 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 nullIOExceptionpublic 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 orderpublic abstract ByteOrder getByteOrder()
public abstract boolean isClosed()