Class LittleEndianDataOutputStream
java.lang.Object
java.io.OutputStream
java.io.FilterOutputStream
com.twelvemonkeys.io.LittleEndianDataOutputStream
- All Implemented Interfaces:
Closeable, DataOutput, Flushable, AutoCloseable
A little endian output stream writes primitive Java numbers
and characters to an output stream in a little endian format.
The standard java.io.DataOutputStream class which this class
imitates uses big endian integers.
Warning:
The DataInput and DataOutput interfaces
specifies big endian byte order in their documentation.
This means that this class is, strictly speaking, not a proper
implementation. However, I don't see a reason for the these interfaces to
specify the byte order of their underlying representations.
- Version:
- 1.0.1, 19 May 1999
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected intThe number of bytes written so far to the little endian output stream.Fields inherited from class FilterOutputStream
out -
Constructor Summary
ConstructorsConstructorDescriptionLittleEndianDataOutputStream(OutputStream pStream) Creates a new little endian output stream and chains it to the output stream specified by thepStreamargument. -
Method Summary
Modifier and TypeMethodDescriptionintsize()Returns the number of bytes written to this little endian output stream.voidwrite(byte[] pBytes, int pOffset, int pLength) WritespLengthbytes from the specified byte array starting atpOffsetto the underlying output stream.voidwrite(int pByte) Writes the specified byte value to the underlying output stream.voidwriteBoolean(boolean pBoolean) Writes abooleanto the underlying output stream as a single byte.voidwriteByte(int pByte) Writes out abyteto the underlying output streamvoidwriteBytes(String pString) Writes a string to the underlying output stream as a sequence of bytes.voidwriteChar(int pChar) Writes a two bytecharto the underlying output stream in little endian order, low byte first.voidwriteChars(String pString) Writes a string to the underlying output stream as a sequence of characters.final voidwriteDouble(double d) Writes an 8 byte Java double to the underlying output stream in little endian order.final voidwriteFloat(float f) Writes a 4 byte Java float to the underlying output stream in little endian order.voidwriteInt(int pInt) Writes a four-byteintto the underlying output stream in little endian order, low byte first, high byte lastvoidwriteLong(long pLong) Writes an eight-bytelongto the underlying output stream in little endian order, low byte first, high byte lastvoidwriteShort(int pShort) Writes a two byteshortto the underlying output stream in little endian order, low byte first.voidWrites a string of no more than 65,535 characters to the underlying output stream using UTF-8 encoding.Methods inherited from class FilterOutputStream
close, flush, writeMethods inherited from class OutputStream
nullOutputStreamMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface DataOutput
write
-
Field Details
-
bytesWritten
protected int bytesWrittenThe number of bytes written so far to the little endian output stream.
-
-
Constructor Details
-
LittleEndianDataOutputStream
Creates a new little endian output stream and chains it to the output stream specified by thepStreamargument.- Parameters:
pStream- the underlying output stream.- See Also:
-
-
Method Details
-
write
Writes the specified byte value to the underlying output stream.- Specified by:
writein interfaceDataOutput- Overrides:
writein classFilterOutputStream- Parameters:
pByte- thebytevalue to be written.- Throws:
IOException- if the underlying stream throws an IOException.
-
write
WritespLengthbytes from the specified byte array starting atpOffsetto the underlying output stream.- Specified by:
writein interfaceDataOutput- Overrides:
writein classFilterOutputStream- Parameters:
pBytes- the data.pOffset- the start offset in the data.pLength- the number of bytes to write.- Throws:
IOException- if the underlying stream throws an IOException.
-
writeBoolean
Writes abooleanto the underlying output stream as a single byte. If the argument is true, the byte value 1 is written. If the argument is false, the byte value0in written.- Specified by:
writeBooleanin interfaceDataOutput- Parameters:
pBoolean- thebooleanvalue to be written.- Throws:
IOException- if the underlying stream throws an IOException.
-
writeByte
Writes out abyteto the underlying output stream- Specified by:
writeBytein interfaceDataOutput- Parameters:
pByte- thebytevalue to be written.- Throws:
IOException- if the underlying stream throws an IOException.
-
writeShort
Writes a two byteshortto the underlying output stream in little endian order, low byte first.- Specified by:
writeShortin interfaceDataOutput- Parameters:
pShort- theshortto be written.- Throws:
IOException- if the underlying stream throws an IOException.
-
writeChar
Writes a two bytecharto the underlying output stream in little endian order, low byte first.- Specified by:
writeCharin interfaceDataOutput- Parameters:
pChar- thecharvalue to be written.- Throws:
IOException- if the underlying stream throws an IOException.
-
writeInt
Writes a four-byteintto the underlying output stream in little endian order, low byte first, high byte last- Specified by:
writeIntin interfaceDataOutput- Parameters:
pInt- theintto be written.- Throws:
IOException- if the underlying stream throws an IOException.
-
writeLong
Writes an eight-bytelongto the underlying output stream in little endian order, low byte first, high byte last- Specified by:
writeLongin interfaceDataOutput- Parameters:
pLong- thelongto be written.- Throws:
IOException- if the underlying stream throws an IOException.
-
writeFloat
Writes a 4 byte Java float to the underlying output stream in little endian order.- Specified by:
writeFloatin interfaceDataOutput- Parameters:
f- thefloatvalue to be written.- Throws:
IOException- if an I/O error occurs.
-
writeDouble
Writes an 8 byte Java double to the underlying output stream in little endian order.- Specified by:
writeDoublein interfaceDataOutput- Parameters:
d- thedoublevalue to be written.- Throws:
IOException- if an I/O error occurs.
-
writeBytes
Writes a string to the underlying output stream as a sequence of bytes. Each character is written to the data output stream as if by thewriteByte(int)method.- Specified by:
writeBytesin interfaceDataOutput- Parameters:
pString- theStringvalue to be written.- Throws:
IOException- if the underlying stream throws an IOException.- See Also:
-
writeChars
Writes a string to the underlying output stream as a sequence of characters. Each character is written to the data output stream as if by thewriteCharmethod.- Specified by:
writeCharsin interfaceDataOutput- Parameters:
pString- aStringvalue to be written.- Throws:
IOException- if the underlying stream throws an IOException.- See Also:
-
writeUTF
Writes a string of no more than 65,535 characters to the underlying output stream using UTF-8 encoding. This method first writes a two byte short in big endian order as required by the UTF-8 specification. This gives the number of bytes in the UTF-8 encoded version of the string, not the number of characters in the string. Next each character of the string is written using the UTF-8 encoding for the character.- Specified by:
writeUTFin interfaceDataOutput- Parameters:
pString- the string to be written.- Throws:
UTFDataFormatException- if the string is longer than 65,535 characters.IOException- if the underlying stream throws an IOException.
-
size
public int size()Returns the number of bytes written to this little endian output stream. (This class is not thread-safe with respect to this method. It is possible that this number is temporarily less than the actual number of bytes written.)- Returns:
- the value of the
writtenfield. - See Also:
-