Package net.mtrop.doom.struct.io
Class SerialWriter
java.lang.Object
net.mtrop.doom.struct.io.SerialWriter
Assists in endian writing to an output stream.
- Author:
- Matthew Tropiano
-
Field Summary
Modifier and TypeFieldDescriptionstatic final boolean
static final boolean
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
setEndianMode
(boolean mode) Sets the byte endian mode for the byte conversion methods.void
writeBoolean
(OutputStream out, boolean b) Writes a boolean as a byte.void
writeBooleanArray
(OutputStream out, boolean... b) Writes a boolean array, which is the length of the array as an integer plus each boolean grouped into integer bits.void
writeByte
(OutputStream out, byte b) Writes a byte.void
writeByteArray
(OutputStream out, byte[] b) Writes an array of bytes, which is the length of the array as an integer plus each byte.void
writeBytes
(OutputStream out, byte[] b) Writes a series of bytes.void
writeBytes
(OutputStream out, byte[] b, int offset, int length) Writes a series of bytes.void
writeChar
(OutputStream out, char c) Writes a character.void
writeCharArray
(OutputStream out, char[] c) Writes a character array, which is the length of the array as an integer plus each character.void
writeDouble
(OutputStream out, double d) Writes a 64-bit float.void
writeDoubleArray
(OutputStream out, double[] d) Writes an array of 64-bit floats, which is the length of the array as an integer plus each double.void
writeFloat
(OutputStream out, float f) Writes a 32-bit float.void
writeFloatArray
(OutputStream out, float[] f) Writes an array of 32-bit floats, which is the length of the array as an integer plus each float.void
writeInt
(OutputStream out, int i) Writes an integer.void
writeIntArray
(OutputStream out, int[] i) Writes an integer array, which is the length of the array as an integer plus each integer.void
writeLong
(OutputStream out, long l) Writes a long.void
writeLongArray
(OutputStream out, long[] l) Writes an array of longs, which is the length of the array as an integer plus each long.void
writeShort
(OutputStream out, short s) Writes a short.void
writeShortArray
(OutputStream out, short[] s) Writes an array of shorts, which is the length of the array as an integer plus each short.void
writeString
(OutputStream out, String s) Writes a String.void
writeString
(OutputStream out, String s, String encodingType) Writes a String in a specific encoding.void
writeString
(OutputStream out, String s, Charset charset) Writes a String in a specific encoding.void
writeStringArray
(OutputStream out, String[] s) Writes an array of Strings, which is the length of the array as an integer plus each String.void
writeUnsignedByte
(OutputStream out, int b) Writes an int that is less than 256 to a byte.void
writeUnsignedByte
(OutputStream out, short s) Writes a short that is less than 256 to a byte.void
writeUnsignedInteger
(OutputStream out, long l) Writes a long that is less than 2^32 to an integer.void
writeUnsignedShort
(OutputStream out, int s) Writes an integer, less than 65536, as a short.void
writeVariableLengthInt
(OutputStream out, int i) Converts an integer from an int to a variable-length string of bytes.void
writeVariableLengthLong
(OutputStream out, long i) Converts a long from a long to a variable-length string of bytes.
-
Field Details
-
LITTLE_ENDIAN
public static final boolean LITTLE_ENDIAN- See Also:
-
BIG_ENDIAN
public static final boolean BIG_ENDIAN- See Also:
-
-
Constructor Details
-
SerialWriter
public SerialWriter(boolean endianMode) Creates a new serial writer.- Parameters:
endianMode
- an _ENDIAN mode.
-
-
Method Details
-
setEndianMode
public void setEndianMode(boolean mode) Sets the byte endian mode for the byte conversion methods. LITTLE_ENDIAN (Intel), the default, orients values from lowest byte to highest, while BIG_ENDIAN (Motorola) orients values from highest byte to lowest.- Parameters:
mode
- an _ENDIAN mode.
-
writeString
Writes a String.- Parameters:
out
- the output stream.s
- the String to write.- Throws:
IOException
- if an error occurred during the write.
-
writeString
Writes a String in a specific encoding.- Parameters:
out
- the output stream.s
- the String to write.encodingType
- the encoding type name.- Throws:
IOException
- if an error occurred during the write.
-
writeString
Writes a String in a specific encoding.- Parameters:
out
- the output stream.s
- the String to write.charset
- the encoding charset.- Throws:
IOException
- if an error occurred during the write.
-
writeStringArray
Writes an array of Strings, which is the length of the array as an integer plus each String.- Parameters:
out
- the output stream.s
- the array to write.- Throws:
IOException
- if an error occurred during the write.
-
writeByte
Writes a byte.- Parameters:
out
- the output stream.b
- the value to write.- Throws:
IOException
- if an error occurred during the write.
-
writeUnsignedByte
Writes a short that is less than 256 to a byte.- Parameters:
out
- the output stream.s
- the value to write.- Throws:
IOException
- if an error occurred during the write.
-
writeUnsignedByte
Writes an int that is less than 256 to a byte.- Parameters:
out
- the output stream.b
- the value to write.- Throws:
IOException
- if an error occurred during the write.
-
writeBytes
Writes a series of bytes.- Parameters:
out
- the output stream.b
- the array to write.- Throws:
IOException
- if an error occurred during the write.
-
writeBytes
Writes a series of bytes.- Parameters:
out
- the output stream.b
- the array to write.offset
- the offset into the array to write from.length
- the amount of bytes to write.- Throws:
IOException
- if an error occurred during the write.
-
writeByteArray
Writes an array of bytes, which is the length of the array as an integer plus each byte.- Parameters:
out
- the output stream.b
- the array to write.- Throws:
IOException
- if an error occurred during the write.
-
writeBoolean
Writes a boolean as a byte.- Parameters:
out
- the output stream.b
- the array to write.- Throws:
IOException
- if an error occurred during the write.
-
writeUnsignedInteger
Writes a long that is less than 2^32 to an integer.- Parameters:
out
- the output stream.l
- the value to write.- Throws:
IOException
- if an error occurred during the write.
-
writeInt
Writes an integer.- Parameters:
out
- the output stream.i
- the value to write.- Throws:
IOException
- if an error occurred during the write.
-
writeVariableLengthInt
Converts an integer from an int to a variable-length string of bytes. Makes up to four bytes. Due to the nature of this algorithm, it is always written out in a Big-Endian fashion.- Parameters:
out
- the output stream.i
- the int to convert.- Throws:
IllegalArgumentException
- if the int value to convert is above 0x0fffffff.IOException
- if an error occurred during the write.
-
writeVariableLengthLong
Converts a long from a long to a variable-length string of bytes. Makes up to eight bytes. Due to the nature of this algorithm, it is always written out in a Big-Endian fashion.- Parameters:
out
- the output stream.i
- the long to convert.- Throws:
IllegalArgumentException
- if the long value to convert is above 0x7fffffffffffffffL.IOException
- if an error occurred during the write.
-
writeIntArray
Writes an integer array, which is the length of the array as an integer plus each integer.- Parameters:
out
- the output stream.i
- the array to write.- Throws:
IOException
- if an error occurred during the write.
-
writeLong
Writes a long.- Parameters:
out
- the output stream.l
- the value to write.- Throws:
IOException
- if an error occurred during the write.
-
writeLongArray
Writes an array of longs, which is the length of the array as an integer plus each long.- Parameters:
out
- the output stream.l
- the array to write.- Throws:
IOException
- if an error occurred during the write.
-
writeFloatArray
Writes an array of 32-bit floats, which is the length of the array as an integer plus each float.- Parameters:
out
- the output stream.f
- the array to write.- Throws:
IOException
- if an error occurred during the write.
-
writeFloat
Writes a 32-bit float.- Parameters:
out
- the output stream.f
- the value to write.- Throws:
IOException
- if an error occurred during the write.
-
writeDouble
Writes a 64-bit float.- Parameters:
out
- the output stream.d
- the value to write.- Throws:
IOException
- if an error occurred during the write.
-
writeDoubleArray
Writes an array of 64-bit floats, which is the length of the array as an integer plus each double.- Parameters:
out
- the output stream.d
- the array to write.- Throws:
IOException
- if an error occurred during the write.
-
writeShort
Writes a short.- Parameters:
out
- the output stream.s
- the value to write.- Throws:
IOException
- if an error occurred during the write.
-
writeUnsignedShort
Writes an integer, less than 65536, as a short.- Parameters:
out
- the output stream.s
- the value to write.- Throws:
IOException
- if an error occurred during the write.
-
writeShortArray
Writes an array of shorts, which is the length of the array as an integer plus each short.- Parameters:
out
- the output stream.s
- the array to write.- Throws:
IOException
- if an error occurred during the write.
-
writeChar
Writes a character.- Parameters:
out
- the output stream.c
- the value to write.- Throws:
IOException
- if an error occurred during the write.
-
writeCharArray
Writes a character array, which is the length of the array as an integer plus each character.- Parameters:
out
- the output stream.c
- the array to write.- Throws:
IOException
- if an error occurred during the write.
-
writeBooleanArray
Writes a boolean array, which is the length of the array as an integer plus each boolean grouped into integer bits.- Parameters:
out
- the output stream.b
- the array to write.- Throws:
IOException
- if an error occurred during the write.
-