DataInput
, DataOutput
public class LittleEndianRandomAccessFile extends Object implements DataInput, DataOutput
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.
LittleEndianDataInputStream
,
LittleEndianDataOutputStream
,
RandomAccessFile
,
DataInput
,
DataOutput
Constructor | Description |
---|---|
LittleEndianRandomAccessFile(File pFile,
String pMode) |
|
LittleEndianRandomAccessFile(String pName,
String pMode) |
Modifier and Type | Method | Description |
---|---|---|
void |
close() |
|
FileChannel |
getChannel() |
|
FileDescriptor |
getFD() |
|
long |
getFilePointer() |
|
long |
length() |
|
int |
read() |
|
int |
read(byte[] b) |
|
int |
read(byte[] b,
int off,
int len) |
|
boolean |
readBoolean() |
Reads a
boolean from the underlying input stream by
reading a single byte. |
byte |
readByte() |
Reads a signed
byte from the underlying input stream
with value between -128 and 127 |
char |
readChar() |
Reads a two byte Unicode
char from the underlying
input stream in little endian order, low byte first. |
double |
readDouble() |
|
float |
readFloat() |
|
void |
readFully(byte[] b) |
|
void |
readFully(byte[] b,
int off,
int len) |
|
int |
readInt() |
Reads a four byte signed
int from the underlying
input stream in little endian order, low byte first. |
String |
readLine() |
|
long |
readLong() |
Reads an eight byte signed
int from the underlying
input stream in little endian order, low byte first. |
short |
readShort() |
Reads a two byte signed
short from the underlying
input stream in little endian order, low byte first. |
int |
readUnsignedByte() |
Reads an unsigned
byte from the underlying
input stream with value between 0 and 255 |
int |
readUnsignedShort() |
Reads a two byte unsigned
short from the underlying
input stream in little endian order, low byte first. |
String |
readUTF() |
Reads a string of no more than 65,535 characters
from the underlying input stream using UTF-8
encoding.
|
void |
seek(long pos) |
Sets the file-pointer offset, measured from the beginning of this
file, at which the next read or write occurs.
|
void |
setLength(long newLength) |
|
int |
skipBytes(int n) |
|
void |
write(byte[] b) |
|
void |
write(byte[] b,
int off,
int len) |
|
void |
write(int b) |
|
void |
writeBoolean(boolean pBoolean) |
Writes a
boolean to the underlying output stream as
a single byte. |
void |
writeByte(int pByte) |
Writes out a
byte to the underlying output stream |
void |
writeBytes(String pString) |
Writes a string to the underlying output stream as a sequence of
bytes.
|
void |
writeChar(int pChar) |
Writes a two byte
char to the underlying output stream
in little endian order, low byte first. |
void |
writeChars(String pString) |
Writes a string to the underlying output stream as a sequence of
characters.
|
void |
writeDouble(double d) |
Writes an 8 byte Java double to the underlying output stream in
little endian order.
|
void |
writeFloat(float f) |
Writes a 4 byte Java float to the underlying output stream in
little endian order.
|
void |
writeInt(int pInt) |
Writes a four-byte
int to the underlying output stream
in little endian order, low byte first, high byte last |
void |
writeLong(long pLong) |
Writes an eight-byte
long to the underlying output stream
in little endian order, low byte first, high byte last |
void |
writeShort(int pShort) |
Writes a two byte
short to the underlying output stream in
little endian order, low byte first. |
void |
writeUTF(String pString) |
Writes a string of no more than 65,535 characters
to the underlying output stream using UTF-8
encoding.
|
public LittleEndianRandomAccessFile(String pName, String pMode) throws FileNotFoundException
FileNotFoundException
public LittleEndianRandomAccessFile(File pFile, String pMode) throws FileNotFoundException
FileNotFoundException
public void close() throws IOException
IOException
public FileChannel getChannel()
public FileDescriptor getFD() throws IOException
IOException
public long getFilePointer() throws IOException
IOException
public long length() throws IOException
IOException
public int read() throws IOException
IOException
public int read(byte[] b) throws IOException
IOException
public int read(byte[] b, int off, int len) throws IOException
IOException
public void readFully(byte[] b) throws IOException
readFully
in interface DataInput
IOException
public void readFully(byte[] b, int off, int len) throws IOException
readFully
in interface DataInput
IOException
public String readLine() throws IOException
readLine
in interface DataInput
IOException
public boolean readBoolean() throws IOException
boolean
from 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.readBoolean
in interface DataInput
boolean
value read.EOFException
- if the end of the underlying input stream
has been reachedIOException
- if the underlying stream throws an IOException.public byte readByte() throws IOException
byte
from the underlying input stream
with value between -128 and 127readByte
in interface DataInput
byte
value read.EOFException
- if the end of the underlying input stream
has been reachedIOException
- if the underlying stream throws an IOException.public int readUnsignedByte() throws IOException
byte
from the underlying
input stream with value between 0 and 255readUnsignedByte
in interface DataInput
byte
value read.EOFException
- if the end of the underlying input
stream has been reachedIOException
- if the underlying stream throws an IOException.public short readShort() throws IOException
short
from the underlying
input stream in little endian order, low byte first.readShort
in interface DataInput
short
read.EOFException
- if the end of the underlying input stream
has been reachedIOException
- if the underlying stream throws an IOException.public int readUnsignedShort() throws IOException
short
from the underlying
input stream in little endian order, low byte first.readUnsignedShort
in interface DataInput
EOFException
- if the end of the underlying input stream
has been reachedIOException
- if the underlying stream throws an IOException.public char readChar() throws IOException
char
from the underlying
input stream in little endian order, low byte first.readChar
in interface DataInput
EOFException
- if the end of the underlying input stream
has been reachedIOException
- if the underlying stream throws an IOException.public int readInt() throws IOException
int
from the underlying
input stream in little endian order, low byte first.readInt
in interface DataInput
int
read.EOFException
- if the end of the underlying input stream
has been reachedIOException
- if the underlying stream throws an IOException.public long readLong() throws IOException
int
from the underlying
input stream in little endian order, low byte first.readLong
in interface DataInput
int
read.EOFException
- if the end of the underlying input stream
has been reachedIOException
- if the underlying stream throws an IOException.public String readUTF() throws IOException
readUTF
in interface DataInput
UTFDataFormatException
- if the string cannot be decodedIOException
- if the underlying stream throws an IOException.public final double readDouble() throws IOException
readDouble
in interface DataInput
double
.EOFException
- if end of stream occurs before eight bytes
have been read.IOException
- if an I/O error occurs.public final float readFloat() throws IOException
readFloat
in interface DataInput
int
.EOFException
- if end of stream occurs before four bytes
have been read.IOException
- if an I/O error occurs.public void seek(long pos) throws IOException
pos
- the offset position, measured in bytes from the
beginning of the file, at which to set the file
pointer.IOException
- if pos
is less than
0
or if an I/O error occurs.public void setLength(long newLength) throws IOException
IOException
public int skipBytes(int n) throws IOException
skipBytes
in interface DataInput
IOException
public void write(byte[] b) throws IOException
write
in interface DataOutput
IOException
public void write(byte[] b, int off, int len) throws IOException
write
in interface DataOutput
IOException
public void write(int b) throws IOException
write
in interface DataOutput
IOException
public void writeBoolean(boolean pBoolean) throws IOException
boolean
to 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 value 0
in written.writeBoolean
in interface DataOutput
pBoolean
- the boolean
value to be written.IOException
- if the underlying stream throws an IOException.public void writeByte(int pByte) throws IOException
byte
to the underlying output streamwriteByte
in interface DataOutput
pByte
- the byte
value to be written.IOException
- if the underlying stream throws an IOException.public void writeShort(int pShort) throws IOException
short
to the underlying output stream in
little endian order, low byte first.writeShort
in interface DataOutput
pShort
- the short
to be written.IOException
- if the underlying stream throws an IOException.public void writeChar(int pChar) throws IOException
char
to the underlying output stream
in little endian order, low byte first.writeChar
in interface DataOutput
pChar
- the char
value to be written.IOException
- if the underlying stream throws an IOException.public void writeInt(int pInt) throws IOException
int
to the underlying output stream
in little endian order, low byte first, high byte lastwriteInt
in interface DataOutput
pInt
- the int
to be written.IOException
- if the underlying stream throws an IOException.public void writeLong(long pLong) throws IOException
long
to the underlying output stream
in little endian order, low byte first, high byte lastwriteLong
in interface DataOutput
pLong
- the long
to be written.IOException
- if the underlying stream throws an IOException.public final void writeFloat(float f) throws IOException
writeFloat
in interface DataOutput
f
- the float
value to be written.IOException
- if an I/O error occurs.public final void writeDouble(double d) throws IOException
writeDouble
in interface DataOutput
d
- the double
value to be written.IOException
- if an I/O error occurs.public void writeBytes(String pString) throws IOException
writeByte()
method.writeBytes
in interface DataOutput
pString
- the String
value to be written.IOException
- if the underlying stream throws an IOException.writeByte(int)
,
file
public void writeChars(String pString) throws IOException
writeChar
method.writeChars
in interface DataOutput
pString
- a String
value to be written.IOException
- if the underlying stream throws an IOException.writeChar(int)
,
file
public void writeUTF(String pString) throws IOException
writeUTF
in interface DataOutput
pString
- the string to be written.UTFDataFormatException
- if the string is longer than
65,535 characters.IOException
- if the underlying stream throws an IOException.Copyright © 2018. All rights reserved.