Class SerialWriter
java.lang.Object
net.mtrop.doom.struct.io.SerialWriter
Assists in endian writing to an output stream.
- Author:
- Matthew Tropiano
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final booleanstatic final boolean -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidsetEndianMode(boolean mode) Sets the byte endian mode for the byte conversion methods.voidwriteBoolean(OutputStream out, boolean b) Writes a boolean as a byte.voidwriteBooleanArray(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.voidwriteByte(OutputStream out, byte b) Writes a byte.voidwriteByteArray(OutputStream out, byte[] b) Writes an array of bytes, which is the length of the array as an integer plus each byte.voidwriteBytes(OutputStream out, byte[] b) Writes a series of bytes.voidwriteBytes(OutputStream out, byte[] b, int offset, int length) Writes a series of bytes.voidwriteChar(OutputStream out, char c) Writes a character.voidwriteCharArray(OutputStream out, char[] c) Writes a character array, which is the length of the array as an integer plus each character.voidwriteDouble(OutputStream out, double d) Writes a 64-bit float.voidwriteDoubleArray(OutputStream out, double[] d) Writes an array of 64-bit floats, which is the length of the array as an integer plus each double.voidwriteFloat(OutputStream out, float f) Writes a 32-bit float.voidwriteFloatArray(OutputStream out, float[] f) Writes an array of 32-bit floats, which is the length of the array as an integer plus each float.voidwriteInt(OutputStream out, int i) Writes an integer.voidwriteIntArray(OutputStream out, int[] i) Writes an integer array, which is the length of the array as an integer plus each integer.voidwriteLong(OutputStream out, long l) Writes a long.voidwriteLongArray(OutputStream out, long[] l) Writes an array of longs, which is the length of the array as an integer plus each long.voidwriteShort(OutputStream out, short s) Writes a short.voidwriteShortArray(OutputStream out, short[] s) Writes an array of shorts, which is the length of the array as an integer plus each short.voidwriteString(OutputStream out, String s) Writes a String.voidwriteString(OutputStream out, String s, String encodingType) Writes a String in a specific encoding.voidwriteString(OutputStream out, String s, Charset charset) Writes a String in a specific encoding.voidwriteStringArray(OutputStream out, String[] s) Writes an array of Strings, which is the length of the array as an integer plus each String.voidwriteUnsignedByte(OutputStream out, int b) Writes an int that is less than 256 to a byte.voidwriteUnsignedByte(OutputStream out, short s) Writes a short that is less than 256 to a byte.voidwriteUnsignedInteger(OutputStream out, long l) Writes a long that is less than 2^32 to an integer.voidwriteUnsignedShort(OutputStream out, int s) Writes an integer, less than 65536, as a short.voidwriteVariableLengthInt(OutputStream out, int i) Converts an integer from an int to a variable-length string of bytes.voidwriteVariableLengthLong(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.
-