Package com.tailf.proto
Class ConfOutputStream
Object
com.tailf.proto.ConfOutputStream
Provides a stream for encoding E terms to external format, for transmission
or storage.
Note that this class is not synchronized, if you need synchronization you must provide it yourself.
-
Field Summary
Modifier and TypeFieldDescriptionstatic final int
The default initial size of the stream. -
Constructor Summary
ConstructorDescriptionCreate a stream with the default initial size.ConfOutputStream
(int size) Create a stream with the specified initial size.Create a stream containing the encoded version of the given E term. -
Method Summary
Modifier and TypeMethodDescriptionint
count()
Get the number of bytes in the stream.int
getPos()
Get the current position in the stream.void
poke4BE
(int offset, long n) Write the low four bytes of a value to the stream in bif endian order, at the specified position.void
reset()
Reset the stream so that it can be reused.int
size()
Get the current capacity of the stream.byte[]
Get the contents of the stream in a byte array.void
write
(byte b) Write one byte to the stream.void
write
(byte[] buf) Write an array of bytes to the stream.void
Write an arbitrary E term to the stream.void
write_atom
(String atom) Write a string to the stream as an E atom.void
write_binary
(byte[] bin) Write an array of bytes to the stream as an E binary.void
write_boolean
(boolean b) Write a boolean value to the stream as the E atom 'true' or 'false'.void
write_byte
(byte b) Write a single byte to the stream as an E integer.void
write_char
(char c) Write a character to the stream as an E integer.void
write_double
(double d) Write a double value to the stream.void
write_float
(float f) Write a float value to the stream.void
write_int
(int i) Write an integer to the stream.void
write_list_head
(int arity) Write an E list header to the stream.void
write_long
(long l) Write a long to the stream.void
Write an empty E list to the stream.void
Write an E PID to the stream.void
write_port
(String node, int id, int creation) Write an E port to the stream.void
Write a new style (R6 and later) E ref to the stream.void
Write an old style E ref to the stream.void
write_short
(short s) Write a short to the stream.void
Write a string to the stream.void
write_tuple_head
(int arity) Write an E tuple header to the stream.void
write_uint
(int ui) Write a positive integer to the stream.void
write_ulong
(long ul) Write a positive long to the stream.void
write_ushort
(short us) Write a positive short to the stream.void
write1
(long n) Write the low byte of a value to the stream.void
write2BE
(long n) Write the low two bytes of a value to the stream in big endian order.void
write2LE
(long n) Write the low two bytes of a value to the stream in little endian order.void
write4BE
(long n) Write the low four bytes of a value to the stream in big endian order.void
write4LE
(long n) Write the low four bytes of a value to the stream in little endian order.void
write8LE
(long n) Write the low eight bytes of a value to the stream in little endian order.void
writeLE
(long n, int b) Write any number of bytes in little endian format.void
writeN
(byte[] bytes) Write an array of bytes to the stream.void
writeTo
(OutputStream os) Write the contents of the stream to an OutputStream.void
writeTo
(SocketChannel channel, SelectionKey key)
-
Field Details
-
defaultInitialSize
public static final int defaultInitialSizeThe default initial size of the stream.- See Also:
-
-
Constructor Details
-
ConfOutputStream
public ConfOutputStream()Create a stream with the default initial size. -
ConfOutputStream
public ConfOutputStream(int size) Create a stream with the specified initial size. -
ConfOutputStream
Create a stream containing the encoded version of the given E term.
-
-
Method Details
-
reset
public void reset()Reset the stream so that it can be reused. -
getPos
public int getPos()Get the current position in the stream.- Returns:
- the current position in the stream.
-
toByteArray
public byte[] toByteArray()Get the contents of the stream in a byte array.- Returns:
- a byte array containing a copy of the stream contents.
-
write
public void write(byte b) Write one byte to the stream.- Parameters:
b
- the byte to write.
-
write
public void write(byte[] buf) Write an array of bytes to the stream.- Parameters:
buf
- the array of bytes to write.
-
writeTo
Write the contents of the stream to an OutputStream.- Parameters:
os
- the OutputStream to write to.- Throws:
IOException
- if there is an error writing to the OutputStream.
-
writeTo
- Throws:
IOException
-
write1
public void write1(long n) Write the low byte of a value to the stream.- Parameters:
n
- the value to use.
-
writeN
public void writeN(byte[] bytes) Write an array of bytes to the stream.- Parameters:
bytes
- the array of bytes to write.
-
size
public int size()Get the current capacity of the stream. As bytes are added the capacity of the stream is increased automatically, however this method returns the current size.- Returns:
- the size of the internal buffer used by the stream.
-
count
public int count()Get the number of bytes in the stream.- Returns:
- the number of bytes in the stream.
-
write2BE
public void write2BE(long n) Write the low two bytes of a value to the stream in big endian order.- Parameters:
n
- the value to use.
-
write4BE
public void write4BE(long n) Write the low four bytes of a value to the stream in big endian order.- Parameters:
n
- the value to use.
-
writeLE
public void writeLE(long n, int b) Write any number of bytes in little endian format.- Parameters:
n
- the value to use.b
- the number of bytes to write from the little end.
-
write2LE
public void write2LE(long n) Write the low two bytes of a value to the stream in little endian order.- Parameters:
n
- the value to use.
-
write4LE
public void write4LE(long n) Write the low four bytes of a value to the stream in little endian order.- Parameters:
n
- the value to use.
-
write8LE
public void write8LE(long n) Write the low eight bytes of a value to the stream in little endian order.- Parameters:
n
- the value to use.
-
poke4BE
public void poke4BE(int offset, long n) Write the low four bytes of a value to the stream in bif endian order, at the specified position. If the position specified is beyond the end of the stream, this method will have no effect. Normally this method should be used in conjunction withgetPos()
, when is is necessary to insert data into the stream before it is known what the actual value should be. For example:int pos = s.getPos(); s.write4BE(0); // make space for length data, // but final value is not yet known [ ...more write statements...] // later... when we know the length value s.poke4BE(pos, length);
- Parameters:
offset
- the position in the stream.n
- the value to use.
-
write_atom
Write a string to the stream as an E atom.- Parameters:
atom
- the string to write.
-
write_binary
public void write_binary(byte[] bin) Write an array of bytes to the stream as an E binary.- Parameters:
bin
- the array of bytes to write.
-
write_boolean
public void write_boolean(boolean b) Write a boolean value to the stream as the E atom 'true' or 'false'.- Parameters:
b
- the boolean value to write.
-
write_byte
public void write_byte(byte b) Write a single byte to the stream as an E integer. The byte is really an IDL 'octet', that is, unsigned.- Parameters:
b
- the byte to use.
-
write_char
public void write_char(char c) Write a character to the stream as an E integer. The character may be a 16 bit character, kind of IDL 'wchar'. It is up to the E side to take care of souch, if they should be used.- Parameters:
c
- the character to use.
-
write_double
public void write_double(double d) Write a double value to the stream.- Parameters:
d
- the double to use.
-
write_float
public void write_float(float f) Write a float value to the stream.- Parameters:
f
- the float to use.
-
write_long
public void write_long(long l) Write a long to the stream.- Parameters:
l
- the long to use.
-
write_ulong
public void write_ulong(long ul) Write a positive long to the stream. The long is interpreted as a two's complement unsigned long even if it is negative.- Parameters:
ul
- the long to use.
-
write_int
public void write_int(int i) Write an integer to the stream.- Parameters:
i
- the integer to use.
-
write_uint
public void write_uint(int ui) Write a positive integer to the stream. The integer is interpreted as a two's complement unsigned integer even if it is negative.- Parameters:
ui
- the integer to use.
-
write_short
public void write_short(short s) Write a short to the stream.- Parameters:
s
- the short to use.
-
write_ushort
public void write_ushort(short us) Write a positive short to the stream. The short is interpreted as a two's complement unsigned short even if it is negative.- Parameters:
us
- the short to use.
-
write_list_head
public void write_list_head(int arity) Write an E list header to the stream. After calling this method, you must write 'arity' elements to the stream followed by nil, or it will not be possible to decode it later.- Parameters:
arity
- the number of elements in the list.
-
write_nil
public void write_nil()Write an empty E list to the stream. -
write_tuple_head
public void write_tuple_head(int arity) Write an E tuple header to the stream. After calling this method, you must write 'arity' elements to the stream or it will not be possible to decode it later.- Parameters:
arity
- the number of elements in the tuple.
-
write_pid
Write an E PID to the stream.- Parameters:
node
- the nodename.id
- an arbitrary number. Only the low order 15 bits will be used.serial
- another arbitrary number. Only the low order 13 bits will be used.creation
- yet another arbitrary number. Only the low order 2 bits will be used.
-
write_port
Write an E port to the stream.- Parameters:
node
- the nodename.id
- an arbitrary number. Only the low order 28 bits will be used.creation
- another arbitrary number. Only the low order 2 bits will be used.
-
write_ref
Write an old style E ref to the stream.- Parameters:
node
- the nodename.id
- an arbitrary number. Only the low order 18 bits will be used.creation
- another arbitrary number. Only the low order 2 bits will be used.
-
write_ref
Write a new style (R6 and later) E ref to the stream.- Parameters:
node
- the nodename.ids
- an array of arbitrary numbers. Only the low order 18 bits of the first number will be used. If the array contains only one number, an old style ref will be written instead. At most three numbers will be read from the array.creation
- another arbitrary number. Only the low order 2 bits will be used.
-
write_string
Write a string to the stream.- Parameters:
s
- the string to write.
-
write_any
Write an arbitrary E term to the stream.- Parameters:
o
- the E term to write.
-