Class LittleEndianRandomAccessFile
java.lang.Object
com.twelvemonkeys.io.LittleEndianRandomAccessFile
- All Implemented Interfaces:
DataInput, DataOutput
A replacement for
RandomAccessFile that is capable of reading
and writing data in little endian byte order.
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:
- $Id: //depot/branches/personal/haraldk/twelvemonkeys/release-2/twelvemonkeys-core/src/main/java/com/twelvemonkeys/io/LittleEndianRandomAccessFile.java#1 $
- See Also:
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionLittleEndianRandomAccessFile(File pFile, String pMode) LittleEndianRandomAccessFile(String pName, String pMode) -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()getFD()longlonglength()intread()intread(byte[] b) intread(byte[] b, int off, int len) booleanReads abooleanfrom the underlying input stream by reading a single byte.bytereadByte()Reads a signedbytefrom the underlying input stream with value between -128 and 127charreadChar()Reads a two byte Unicodecharfrom the underlying input stream in little endian order, low byte first.final doublefinal floatvoidreadFully(byte[] b) voidreadFully(byte[] b, int off, int len) intreadInt()Reads a four byte signedintfrom the underlying input stream in little endian order, low byte first.readLine()longreadLong()Reads an eight byte signedintfrom the underlying input stream in little endian order, low byte first.shortReads a two byte signedshortfrom the underlying input stream in little endian order, low byte first.intReads an unsignedbytefrom the underlying input stream with value between 0 and 255intReads a two byte unsignedshortfrom the underlying input stream in little endian order, low byte first.readUTF()Reads a string of no more than 65,535 characters from the underlying input stream using UTF-8 encoding.voidseek(long pos) Sets the file-pointer offset, measured from the beginning of this file, at which the next read or write occurs.voidsetLength(long newLength) intskipBytes(int n) voidwrite(byte[] b) voidwrite(byte[] b, int off, int len) voidwrite(int b) 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.
-
Field Details
-
file
-
-
Constructor Details
-
LittleEndianRandomAccessFile
- Throws:
FileNotFoundException
-
LittleEndianRandomAccessFile
- Throws:
FileNotFoundException
-
-
Method Details
-
close
- Throws:
IOException
-
getChannel
-
getFD
- Throws:
IOException
-
getFilePointer
- Throws:
IOException
-
length
- Throws:
IOException
-
read
- Throws:
IOException
-
read
- Throws:
IOException
-
read
- Throws:
IOException
-
readFully
- Specified by:
readFullyin interfaceDataInput- Throws:
IOException
-
readFully
- Specified by:
readFullyin interfaceDataInput- Throws:
IOException
-
readLine
- Specified by:
readLinein interfaceDataInput- Throws:
IOException
-
readBoolean
Reads abooleanfrom the underlying input stream by reading a single byte. If the byte is zero, false is returned. If the byte is positive, true is returned.- Specified by:
readBooleanin interfaceDataInput- Returns:
- the
booleanvalue read. - Throws:
EOFException- if the end of the underlying input stream has been reachedIOException- if the underlying stream throws an IOException.
-
readByte
Reads a signedbytefrom the underlying input stream with value between -128 and 127- Specified by:
readBytein interfaceDataInput- Returns:
- the
bytevalue read. - Throws:
EOFException- if the end of the underlying input stream has been reachedIOException- if the underlying stream throws an IOException.
-
readUnsignedByte
Reads an unsignedbytefrom the underlying input stream with value between 0 and 255- Specified by:
readUnsignedBytein interfaceDataInput- Returns:
- the
bytevalue read. - Throws:
EOFException- if the end of the underlying input stream has been reachedIOException- if the underlying stream throws an IOException.
-
readShort
Reads a two byte signedshortfrom the underlying input stream in little endian order, low byte first.- Specified by:
readShortin interfaceDataInput- Returns:
- the
shortread. - Throws:
EOFException- if the end of the underlying input stream has been reachedIOException- if the underlying stream throws an IOException.
-
readUnsignedShort
Reads a two byte unsignedshortfrom the underlying input stream in little endian order, low byte first.- Specified by:
readUnsignedShortin interfaceDataInput- Returns:
- the int value of the unsigned short read.
- Throws:
EOFException- if the end of the underlying input stream has been reachedIOException- if the underlying stream throws an IOException.
-
readChar
Reads a two byte Unicodecharfrom the underlying input stream in little endian order, low byte first.- Specified by:
readCharin interfaceDataInput- Returns:
- the int value of the unsigned short read.
- Throws:
EOFException- if the end of the underlying input stream has been reachedIOException- if the underlying stream throws an IOException.
-
readInt
Reads a four byte signedintfrom the underlying input stream in little endian order, low byte first.- Specified by:
readIntin interfaceDataInput- Returns:
- the
intread. - Throws:
EOFException- if the end of the underlying input stream has been reachedIOException- if the underlying stream throws an IOException.
-
readLong
Reads an eight byte signedintfrom the underlying input stream in little endian order, low byte first.- Specified by:
readLongin interfaceDataInput- Returns:
- the
intread. - Throws:
EOFException- if the end of the underlying input stream has been reachedIOException- if the underlying stream throws an IOException.
-
readUTF
Reads a string of no more than 65,535 characters from the underlying input stream using UTF-8 encoding. This method first reads 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. Next this many bytes are read and decoded as UTF-8 encoded characters.- Specified by:
readUTFin interfaceDataInput- Returns:
- the decoded string
- Throws:
UTFDataFormatException- if the string cannot be decodedIOException- if the underlying stream throws an IOException.
-
readDouble
- Specified by:
readDoublein interfaceDataInput- Returns:
- the next eight bytes of this input stream, interpreted as a
little endian
double. - Throws:
EOFException- if end of stream occurs before eight bytes have been read.IOException- if an I/O error occurs.
-
readFloat
- Specified by:
readFloatin interfaceDataInput- Returns:
- the next four bytes of this input stream, interpreted as a
little endian
int. - Throws:
EOFException- if end of stream occurs before four bytes have been read.IOException- if an I/O error occurs.
-
seek
Sets the file-pointer offset, measured from the beginning of this file, at which the next read or write occurs. The offset may be set beyond the end of the file. Setting the offset beyond the end of the file does not change the file length. The file length will change only by writing after the offset has been set beyond the end of the file.- Parameters:
pos- the offset position, measured in bytes from the beginning of the file, at which to set the file pointer.- Throws:
IOException- ifposis less than0or if an I/O error occurs.
-
setLength
- Throws:
IOException
-
skipBytes
- Specified by:
skipBytesin interfaceDataInput- Throws:
IOException
-
write
- Specified by:
writein interfaceDataOutput- Throws:
IOException
-
write
- Specified by:
writein interfaceDataOutput- Throws:
IOException
-
write
- Specified by:
writein interfaceDataOutput- Throws:
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()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.
-