Package com.ericsson.otp.erlang
Class OtpOutputStream
- java.lang.Object
- 
- java.io.OutputStream
- 
- java.io.ByteArrayOutputStream
- 
- com.ericsson.otp.erlang.OtpOutputStream
 
 
 
- 
- All Implemented Interfaces:
- java.io.Closeable,- java.io.Flushable,- java.lang.AutoCloseable
 
 public class OtpOutputStream extends java.io.ByteArrayOutputStreamProvides a stream for encoding Erlang 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 SummaryFields Modifier and Type Field Description static intdefaultIncrementThe default increment used when growing the stream (increment at least this much).static intdefaultInitialSizeThe default initial size of the stream.
 - 
Constructor SummaryConstructors Constructor Description OtpOutputStream()Create a stream with the default initial size (2048 bytes).OtpOutputStream(int size)Create a stream with the specified initial size.OtpOutputStream(OtpErlangObject o)Create a stream containing the encoded version of the given Erlang term.
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description intcount()Deprecated.As of Jinterface 1.4, replaced by super.size().voidensureCapacity(int minCapacity)Increases the capacity of thisOtpOutputStreaminstance, if necessary, to ensure that it can hold at least the number of elements specified by the minimum capacity argument.intgetPos()Get the current position in the stream.intlength()Get the current capacity of the stream.voidpoke4BE(int offset, long n)Write the low four bytes of a value to the stream in bif endian order, at the specified position.voidtrimToSize()Trims the capacity of thisOtpOutputStreaminstance to be the buffer's current size.voidwrite(byte b)Write one byte to the stream.voidwrite(byte[] abuf)voidwrite(byte[] b, int off, int len)voidwrite(int b)voidwrite_any(OtpErlangObject o)Write an arbitrary Erlang term to the stream.voidwrite_atom(java.lang.String atom)Write a string to the stream as an Erlang atom.voidwrite_big_integer(java.math.BigInteger v)voidwrite_binary(byte[] bin)Write an array of bytes to the stream as an Erlang binary.voidwrite_bitstr(byte[] bin, int pad_bits)Write an array of bytes to the stream as an Erlang bitstr.voidwrite_boolean(boolean b)Write a boolean value to the stream as the Erlang atom 'true' or 'false'.voidwrite_byte(byte b)Write a single byte to the stream as an Erlang integer.voidwrite_char(char c)Write a character to the stream as an Erlang integer.voidwrite_compressed(OtpErlangObject o)Write an arbitrary Erlang term to the stream in compressed format.voidwrite_compressed(OtpErlangObject o, int level)Write an arbitrary Erlang term to the stream in compressed format.voidwrite_double(double d)Write a double value to the stream.voidwrite_external_fun(java.lang.String module, java.lang.String function, int arity)voidwrite_float(float f)Write a float value to the stream.voidwrite_fun(OtpErlangPid pid, java.lang.String module, long old_index, int arity, byte[] md5, long index, long uniq, OtpErlangObject[] freeVars)voidwrite_int(int i)Write an integer to the stream.voidwrite_list_head(int arity)Write an Erlang list header to the stream.voidwrite_long(long l)Write a long to the stream.voidwrite_map_head(int arity)voidwrite_nil()Write an empty Erlang list to the stream.voidwrite_pid(OtpErlangPid pid)Write an Erlang PID to the stream.voidwrite_pid(java.lang.String node, int id, int serial, int creation)Write an Erlang PID to the stream.voidwrite_port(OtpErlangPort port)Write an Erlang port to the stream.voidwrite_port(java.lang.String node, long id, int creation)Write an Erlang port to the stream.voidwrite_ref(OtpErlangRef ref)Write an Erlang ref to the stream.voidwrite_ref(java.lang.String node, int[] ids, int creation)Write an Erlang ref to the stream.voidwrite_ref(java.lang.String node, int id, int creation)Write an old style Erlang ref to the stream.voidwrite_short(short s)Write a short to the stream.voidwrite_string(java.lang.String s)Write a string to the stream.voidwrite_tuple_head(int arity)Write an Erlang tuple header to the stream.voidwrite_uint(int ui)Write a positive integer to the stream.voidwrite_ulong(long ul)Write a positive long to the stream.voidwrite_ushort(short us)Write a positive short to the stream.voidwrite1(long n)Write the low byte of a value to the stream.voidwrite2BE(long n)Write the low two bytes of a value to the stream in big endian order.voidwrite2LE(long n)Write the low two bytes of a value to the stream in little endian order.voidwrite4BE(long n)Write the low four bytes of a value to the stream in big endian order.voidwrite4LE(long n)Write the low four bytes of a value to the stream in little endian order.voidwrite8BE(long n)Write the low eight (all) bytes of a value to the stream in big endian order.voidwrite8LE(long n)Write the low eight bytes of a value to the stream in little endian order.voidwriteLE(long n, int b)Write any number of bytes in little endian format.voidwriteN(byte[] bytes)Write an array of bytes to the stream.voidwriteTo(java.io.OutputStream out)voidwriteToAndFlush(java.io.OutputStream out)
 
- 
- 
- 
Field Detail- 
defaultInitialSizepublic static final int defaultInitialSize The default initial size of the stream. *- See Also:
- Constant Field Values
 
 - 
defaultIncrementpublic static final int defaultIncrement The default increment used when growing the stream (increment at least this much). *- See Also:
- Constant Field Values
 
 
- 
 - 
Constructor Detail- 
OtpOutputStreampublic OtpOutputStream() Create a stream with the default initial size (2048 bytes).
 - 
OtpOutputStreampublic OtpOutputStream(int size) Create a stream with the specified initial size.
 - 
OtpOutputStreampublic OtpOutputStream(OtpErlangObject o) Create a stream containing the encoded version of the given Erlang term.
 
- 
 - 
Method Detail- 
getPospublic int getPos() Get the current position in the stream.- Returns:
- the current position in the stream.
 
 - 
trimToSizepublic void trimToSize() Trims the capacity of thisOtpOutputStreaminstance to be the buffer's current size. An application can use this operation to minimize the storage of anOtpOutputStreaminstance.
 - 
ensureCapacitypublic void ensureCapacity(int minCapacity) Increases the capacity of thisOtpOutputStreaminstance, if necessary, to ensure that it can hold at least the number of elements specified by the minimum capacity argument.- Parameters:
- minCapacity- the desired minimum capacity
 
 - 
writepublic void write(byte b) Write one byte to the stream.- Parameters:
- b- the byte to write.
 
 - 
writepublic void write(byte[] abuf) - Overrides:
- writein class- java.io.OutputStream
 
 - 
writepublic void write(int b) - Overrides:
- writein class- java.io.ByteArrayOutputStream
 
 - 
writepublic void write(byte[] b, int off, int len)- Overrides:
- writein class- java.io.ByteArrayOutputStream
 
 - 
writeTopublic void writeTo(java.io.OutputStream out) throws java.io.IOException- Overrides:
- writeToin class- java.io.ByteArrayOutputStream
- Throws:
- java.io.IOException
 
 - 
writeToAndFlushpublic void writeToAndFlush(java.io.OutputStream out) throws java.io.IOException- Throws:
- java.io.IOException
 
 - 
write1public void write1(long n) Write the low byte of a value to the stream.- Parameters:
- n- the value to use.
 
 - 
writeNpublic void writeN(byte[] bytes) Write an array of bytes to the stream.- Parameters:
- bytes- the array of bytes to write.
 
 - 
lengthpublic int length() 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@Deprecated public int count() Deprecated.As of Jinterface 1.4, replaced by super.size().Get the number of bytes in the stream.- Returns:
- the number of bytes in the stream.
- See Also:
- ByteArrayOutputStream.size()
 
 - 
write2BEpublic 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.
 
 - 
write4BEpublic 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.
 
 - 
write8BEpublic void write8BE(long n) Write the low eight (all) bytes of a value to the stream in big endian order.- Parameters:
- n- the value to use.
 
 - 
writeLEpublic 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.
 
 - 
write2LEpublic 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.
 
 - 
write4LEpublic 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.
 
 - 
write8LEpublic 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.
 
 - 
poke4BEpublic 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 withsize(), 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.size(); 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_atompublic void write_atom(java.lang.String atom) Write a string to the stream as an Erlang atom.- Parameters:
- atom- the string to write.
 
 - 
write_binarypublic void write_binary(byte[] bin) Write an array of bytes to the stream as an Erlang binary.- Parameters:
- bin- the array of bytes to write.
 
 - 
write_bitstrpublic void write_bitstr(byte[] bin, int pad_bits)Write an array of bytes to the stream as an Erlang bitstr.- Parameters:
- bin- the array of bytes to write.
- pad_bits- the number of zero pad bits at the low end of the last byte
 
 - 
write_booleanpublic void write_boolean(boolean b) Write a boolean value to the stream as the Erlang atom 'true' or 'false'.- Parameters:
- b- the boolean value to write.
 
 - 
write_bytepublic void write_byte(byte b) Write a single byte to the stream as an Erlang integer. The byte is really an IDL 'octet', that is, unsigned.- Parameters:
- b- the byte to use.
 
 - 
write_charpublic void write_char(char c) Write a character to the stream as an Erlang integer. The character may be a 16 bit character, kind of IDL 'wchar'. It is up to the Erlang side to take care of souch, if they should be used.- Parameters:
- c- the character to use.
 
 - 
write_doublepublic void write_double(double d) Write a double value to the stream.- Parameters:
- d- the double to use.
 
 - 
write_floatpublic void write_float(float f) Write a float value to the stream.- Parameters:
- f- the float to use.
 
 - 
write_big_integerpublic void write_big_integer(java.math.BigInteger v) 
 - 
write_longpublic void write_long(long l) Write a long to the stream.- Parameters:
- l- the long to use.
 
 - 
write_ulongpublic 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_intpublic void write_int(int i) Write an integer to the stream.- Parameters:
- i- the integer to use.
 
 - 
write_uintpublic 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_shortpublic void write_short(short s) Write a short to the stream.- Parameters:
- s- the short to use.
 
 - 
write_ushortpublic 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_headpublic void write_list_head(int arity) Write an Erlang 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_nilpublic void write_nil() Write an empty Erlang list to the stream.
 - 
write_tuple_headpublic void write_tuple_head(int arity) Write an Erlang 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_pidpublic void write_pid(java.lang.String node, int id, int serial, int creation)Write an Erlang PID to the stream.- Parameters:
- node- the nodename.
- id- an arbitrary number.
- serial- another arbitrary number.
- creation- node incarnation number.
 
 - 
write_pidpublic void write_pid(OtpErlangPid pid) Write an Erlang PID to the stream.- Parameters:
- pid- the pid
 
 - 
write_portpublic void write_port(java.lang.String node, long id, int creation)Write an Erlang 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_portpublic void write_port(OtpErlangPort port) Write an Erlang port to the stream.- Parameters:
- port- the port.
 
 - 
write_refpublic void write_ref(java.lang.String node, int id, int creation)Write an old style Erlang 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.
 
 - 
write_refpublic void write_ref(java.lang.String node, int[] ids, int creation)Write an Erlang ref to the stream.- Parameters:
- node- the nodename.
- ids- an array of arbitrary numbers. At most three numbers will be read from the array.
- creation- another arbitrary number.
 
 - 
write_refpublic void write_ref(OtpErlangRef ref) Write an Erlang ref to the stream.- Parameters:
- ref- the reference
 
 - 
write_stringpublic void write_string(java.lang.String s) Write a string to the stream.- Parameters:
- s- the string to write.
 
 - 
write_compressedpublic void write_compressed(OtpErlangObject o) Write an arbitrary Erlang term to the stream in compressed format.- Parameters:
- o- the Erlang term to write.
 
 - 
write_compressedpublic void write_compressed(OtpErlangObject o, int level) Write an arbitrary Erlang term to the stream in compressed format.- Parameters:
- o- the Erlang term to write.
- level- the compression level (- 0..9)
 
 - 
write_anypublic void write_any(OtpErlangObject o) Write an arbitrary Erlang term to the stream.- Parameters:
- o- the Erlang term to write.
 
 - 
write_funpublic void write_fun(OtpErlangPid pid, java.lang.String module, long old_index, int arity, byte[] md5, long index, long uniq, OtpErlangObject[] freeVars) 
 - 
write_external_funpublic void write_external_fun(java.lang.String module, java.lang.String function, int arity)
 - 
write_map_headpublic void write_map_head(int arity) 
 
- 
 
-