Class LittleEndianOutputStream
java.lang.Object
java.io.OutputStream
java.io.FilterOutputStream
net.simplace.core.io.endian.LittleEndianOutputStream
- All Implemented Interfaces:
Closeable, Flushable, AutoCloseable
Output stream that writes primitive values in little-endian byte order and counts the written bytes.
-
Field Summary
FieldsFields inherited from class FilterOutputStream
out -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintsize()voidwrite(byte[] data, int offset, int length) Writes a part of a byte array.voidwrite(int b) Writes one byte.voidwriteBoolean(boolean b) Writes a boolean as 1 byte (1 or 0).voidwriteByte(int b) Writes one byte.voidwriteBytes(String s) Writes the low byte of each character.voidwriteChar(int c) Writes a char as 2 bytes (little-endian).voidwriteChars(String s) Writes each character as 2 bytes (little-endian).final voidwriteDouble(double d) Writes a double as 8 bytes (little-endian).final voidwriteFloat(float f) Writes a float as 4 bytes (little-endian).voidwriteInt(int i) Writes 4 bytes (little-endian).voidwriteLong(long l) Writes 8 bytes (little-endian).voidwriteShort(int s) Writes 2 bytes (little-endian).voidWrites a string in modified UTF-8 with a 2 byte length prefix (big-endian, likeDataOutput).Methods inherited from class FilterOutputStream
close, flush, writeMethods inherited from class OutputStream
nullOutputStream
-
Field Details
-
written
protected int writtennumber of bytes written
-
-
Constructor Details
-
LittleEndianOutputStream
- Parameters:
out- the underlying stream
-
-
Method Details
-
write
Writes one byte.- Overrides:
writein classFilterOutputStream- Parameters:
b- the byte (lowest 8 bits)- Throws:
IOException- on write errors
-
write
Writes a part of a byte array.- Overrides:
writein classFilterOutputStream- Parameters:
data- the bytesoffset- start indexlength- number of bytes- Throws:
IOException- on write errors
-
writeBoolean
Writes a boolean as 1 byte (1 or 0).- Parameters:
b- the value- Throws:
IOException- on write errors
-
writeByte
Writes one byte.- Parameters:
b- the byte (lowest 8 bits)- Throws:
IOException- on write errors
-
writeShort
Writes 2 bytes (little-endian).- Parameters:
s- the value (lowest 16 bits)- Throws:
IOException- on write errors
-
writeChar
Writes a char as 2 bytes (little-endian).- Parameters:
c- the char (lowest 16 bits)- Throws:
IOException- on write errors
-
writeInt
Writes 4 bytes (little-endian).- Parameters:
i- the value- Throws:
IOException- on write errors
-
writeLong
Writes 8 bytes (little-endian).- Parameters:
l- the value- Throws:
IOException- on write errors
-
writeFloat
Writes a float as 4 bytes (little-endian).- Parameters:
f- the value- Throws:
IOException- on write errors
-
writeDouble
Writes a double as 8 bytes (little-endian).- Parameters:
d- the value- Throws:
IOException- on write errors
-
writeBytes
Writes the low byte of each character.- Parameters:
s- the string- Throws:
IOException- on write errors
-
writeChars
Writes each character as 2 bytes (little-endian).- Parameters:
s- the string- Throws:
IOException- on write errors
-
writeUTF
Writes a string in modified UTF-8 with a 2 byte length prefix (big-endian, likeDataOutput).- Parameters:
s- the string- Throws:
IOException- if the encoded string is longer than 65535 bytes (UTFDataFormatException) or on write errors
-
size
public int size()- Returns:
- the number of bytes written
-