Package net.metanotion.io
Class RAIFile
- java.lang.Object
-
- net.metanotion.io.RAIFile
-
- All Implemented Interfaces:
Closeable
,DataInput
,DataOutput
,AutoCloseable
,RandomAccessInterface
public class RAIFile extends Object implements RandomAccessInterface, DataInput, DataOutput
-
-
Constructor Summary
Constructors Constructor Description RAIFile(File file, boolean read, boolean write)
RAIFile(RandomAccessFile file)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
canWrite()
I2P is the file writable? Only valid if the File constructor was used, not the RAF constructorvoid
close()
long
getFilePointer()
long
length()
int
read()
int
read(byte[] b)
int
read(byte[] b, int off, int len)
boolean
readBoolean()
byte
readByte()
char
readChar()
double
readDouble()
float
readFloat()
void
readFully(byte[] b)
void
readFully(byte[] b, int off, int len)
int
readInt()
String
readLine()
long
readLong()
short
readShort()
int
readUnsignedByte()
int
readUnsignedInt()
I2Pint
readUnsignedShort()
String
readUTF()
Read a UTF encoded string I would delegate here.void
seek(long pos)
void
setLength(long newLength)
int
skipBytes(int n)
String
toString()
void
write(byte[] b)
void
write(byte[] b, int off, int len)
void
write(int b)
void
writeBoolean(boolean v)
void
writeByte(int v)
void
writeBytes(String s)
void
writeChar(int v)
void
writeChars(String s)
void
writeDouble(double v)
void
writeFloat(float v)
void
writeInt(int v)
void
writeLong(long v)
void
writeShort(int v)
void
writeUTF(String str)
Write a UTF encoded string I would delegate here.
-
-
-
Constructor Detail
-
RAIFile
public RAIFile(RandomAccessFile file) throws FileNotFoundException
- Throws:
FileNotFoundException
-
RAIFile
public RAIFile(File file, boolean read, boolean write) throws FileNotFoundException
- Parameters:
read
- must be true- Throws:
FileNotFoundException
-
-
Method Detail
-
canWrite
public boolean canWrite()
I2P is the file writable? Only valid if the File constructor was used, not the RAF constructor- Specified by:
canWrite
in interfaceRandomAccessInterface
- Since:
- 0.8.8
-
getFilePointer
public long getFilePointer() throws IOException
- Specified by:
getFilePointer
in interfaceRandomAccessInterface
- Throws:
IOException
-
length
public long length() throws IOException
- Specified by:
length
in interfaceRandomAccessInterface
- Throws:
IOException
-
read
public int read() throws IOException
- Specified by:
read
in interfaceRandomAccessInterface
- Throws:
IOException
-
read
public int read(byte[] b) throws IOException
- Specified by:
read
in interfaceRandomAccessInterface
- Throws:
IOException
-
read
public int read(byte[] b, int off, int len) throws IOException
- Specified by:
read
in interfaceRandomAccessInterface
- Throws:
IOException
-
seek
public void seek(long pos) throws IOException
- Specified by:
seek
in interfaceRandomAccessInterface
- Throws:
IOException
-
setLength
public void setLength(long newLength) throws IOException
- Specified by:
setLength
in interfaceRandomAccessInterface
- Throws:
IOException
-
close
public void close() throws IOException
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Specified by:
close
in interfaceRandomAccessInterface
- Throws:
IOException
-
readBoolean
public boolean readBoolean() throws IOException
- Specified by:
readBoolean
in interfaceDataInput
- Specified by:
readBoolean
in interfaceRandomAccessInterface
- Throws:
IOException
-
readByte
public byte readByte() throws IOException
- Specified by:
readByte
in interfaceDataInput
- Specified by:
readByte
in interfaceRandomAccessInterface
- Throws:
IOException
-
readChar
public char readChar() throws IOException
- Specified by:
readChar
in interfaceDataInput
- Specified by:
readChar
in interfaceRandomAccessInterface
- Throws:
IOException
-
readDouble
public double readDouble() throws IOException
- Specified by:
readDouble
in interfaceDataInput
- Specified by:
readDouble
in interfaceRandomAccessInterface
- Throws:
IOException
-
readFloat
public float readFloat() throws IOException
- Specified by:
readFloat
in interfaceDataInput
- Specified by:
readFloat
in interfaceRandomAccessInterface
- Throws:
IOException
-
readFully
public void readFully(byte[] b) throws IOException
- Specified by:
readFully
in interfaceDataInput
- Specified by:
readFully
in interfaceRandomAccessInterface
- Throws:
IOException
-
readFully
public void readFully(byte[] b, int off, int len) throws IOException
- Specified by:
readFully
in interfaceDataInput
- Specified by:
readFully
in interfaceRandomAccessInterface
- Throws:
IOException
-
readInt
public int readInt() throws IOException
- Specified by:
readInt
in interfaceDataInput
- Specified by:
readInt
in interfaceRandomAccessInterface
- Throws:
IOException
-
readLine
public String readLine() throws IOException
- Specified by:
readLine
in interfaceDataInput
- Specified by:
readLine
in interfaceRandomAccessInterface
- Throws:
IOException
-
readLong
public long readLong() throws IOException
- Specified by:
readLong
in interfaceDataInput
- Specified by:
readLong
in interfaceRandomAccessInterface
- Throws:
IOException
-
readShort
public short readShort() throws IOException
- Specified by:
readShort
in interfaceDataInput
- Specified by:
readShort
in interfaceRandomAccessInterface
- Throws:
IOException
-
readUnsignedByte
public int readUnsignedByte() throws IOException
- Specified by:
readUnsignedByte
in interfaceDataInput
- Specified by:
readUnsignedByte
in interfaceRandomAccessInterface
- Throws:
IOException
-
readUnsignedShort
public int readUnsignedShort() throws IOException
- Specified by:
readUnsignedShort
in interfaceDataInput
- Specified by:
readUnsignedShort
in interfaceRandomAccessInterface
- Throws:
IOException
-
readUnsignedInt
public int readUnsignedInt() throws IOException
I2P- Specified by:
readUnsignedInt
in interfaceRandomAccessInterface
- Throws:
IOException
- if the read value is negative
-
readUTF
public String readUTF() throws IOException
Read a UTF encoded string I would delegate here. But Java's read/writeUTF combo suck. A signed 2 byte length is not enough. This reads a 4 byte length. The upper byte MUST be zero, if its not, then its not this method and has used an extensible length encoding. This is followed by the bytes of the UTF encoded string, as returned by String.getBytes("UTF-8");- Specified by:
readUTF
in interfaceDataInput
- Specified by:
readUTF
in interfaceRandomAccessInterface
- Throws:
IOException
-
skipBytes
public int skipBytes(int n) throws IOException
- Specified by:
skipBytes
in interfaceDataInput
- Specified by:
skipBytes
in interfaceRandomAccessInterface
- Throws:
IOException
-
write
public void write(int b) throws IOException
- Specified by:
write
in interfaceDataOutput
- Specified by:
write
in interfaceRandomAccessInterface
- Throws:
IOException
-
write
public void write(byte[] b) throws IOException
- Specified by:
write
in interfaceDataOutput
- Specified by:
write
in interfaceRandomAccessInterface
- Throws:
IOException
-
write
public void write(byte[] b, int off, int len) throws IOException
- Specified by:
write
in interfaceDataOutput
- Specified by:
write
in interfaceRandomAccessInterface
- Throws:
IOException
-
writeBoolean
public void writeBoolean(boolean v) throws IOException
- Specified by:
writeBoolean
in interfaceDataOutput
- Specified by:
writeBoolean
in interfaceRandomAccessInterface
- Throws:
IOException
-
writeByte
public void writeByte(int v) throws IOException
- Specified by:
writeByte
in interfaceDataOutput
- Specified by:
writeByte
in interfaceRandomAccessInterface
- Throws:
IOException
-
writeShort
public void writeShort(int v) throws IOException
- Specified by:
writeShort
in interfaceDataOutput
- Specified by:
writeShort
in interfaceRandomAccessInterface
- Throws:
IOException
-
writeChar
public void writeChar(int v) throws IOException
- Specified by:
writeChar
in interfaceDataOutput
- Specified by:
writeChar
in interfaceRandomAccessInterface
- Throws:
IOException
-
writeInt
public void writeInt(int v) throws IOException
- Specified by:
writeInt
in interfaceDataOutput
- Specified by:
writeInt
in interfaceRandomAccessInterface
- Throws:
IOException
-
writeLong
public void writeLong(long v) throws IOException
- Specified by:
writeLong
in interfaceDataOutput
- Specified by:
writeLong
in interfaceRandomAccessInterface
- Throws:
IOException
-
writeFloat
public void writeFloat(float v) throws IOException
- Specified by:
writeFloat
in interfaceDataOutput
- Specified by:
writeFloat
in interfaceRandomAccessInterface
- Throws:
IOException
-
writeDouble
public void writeDouble(double v) throws IOException
- Specified by:
writeDouble
in interfaceDataOutput
- Specified by:
writeDouble
in interfaceRandomAccessInterface
- Throws:
IOException
-
writeBytes
public void writeBytes(String s) throws IOException
- Specified by:
writeBytes
in interfaceDataOutput
- Specified by:
writeBytes
in interfaceRandomAccessInterface
- Throws:
IOException
-
writeChars
public void writeChars(String s) throws IOException
- Specified by:
writeChars
in interfaceDataOutput
- Specified by:
writeChars
in interfaceRandomAccessInterface
- Throws:
IOException
-
writeUTF
public void writeUTF(String str) throws IOException
Write a UTF encoded string I would delegate here. But Java's read/writeUTF combo suck. A signed 2 byte length is not enough. This writes a 4 byte length. The upper byte MUST be zero, if its not, then its not this method and has used an extensible length encoding. This is followed by the bytes of the UTF encoded string, as returned by String.getBytes("UTF-8");- Specified by:
writeUTF
in interfaceDataOutput
- Specified by:
writeUTF
in interfaceRandomAccessInterface
- Throws:
IOException
-
-