public class RAIFile extends Object implements RandomAccessInterface, DataInput, DataOutput
| Constructor and Description |
|---|
RAIFile(File file,
boolean read,
boolean write) |
RAIFile(RandomAccessFile file)Constructor. |
| Modifier and Type | Method and Description |
|---|---|
boolean | canWrite()Is the file writable? (I2P)
Only valid if the File constructor was used, not the RAF constructor |
void | 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()Reads an unsigned 32-bit integer from the file. |
int | readUnsignedShort() |
String | readUTF()Read a UTF encoded string with 4-byte length prefix. |
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 with 4-byte length prefix. |
public RAIFile(File file, boolean read, boolean write) throws FileNotFoundException
read - must be trueFileNotFoundExceptionpublic RAIFile(RandomAccessFile file) throws FileNotFoundException
file - the underlying fileFileNotFoundException - if the file cannot be openedpublic boolean canWrite()
canWrite in interface RandomAccessInterfacepublic void close()
throws IOExceptionclose in interface Closeableclose in interface AutoCloseableclose in interface RandomAccessInterfaceIOExceptionRandomAccessFile.close()public long getFilePointer()
throws IOExceptiongetFilePointer in interface RandomAccessInterfaceIOExceptionpublic long length()
throws IOExceptionlength in interface RandomAccessInterfaceIOExceptionpublic int read()
throws IOExceptionread in interface RandomAccessInterfaceIOExceptionRandomAccessFile.read()public int read(byte[] b)
throws IOExceptionread in interface RandomAccessInterfaceIOExceptionRandomAccessFile.read(byte[])public int read(byte[] b,
int off,
int len)
throws IOExceptionread in interface RandomAccessInterfaceIOExceptionRandomAccessFile.read(byte[],int,int)public boolean readBoolean()
throws IOExceptionreadBoolean in interface DataInputreadBoolean in interface RandomAccessInterfaceIOExceptionRandomAccessFile.readBoolean()public byte readByte()
throws IOExceptionreadByte in interface DataInputreadByte in interface RandomAccessInterfaceIOExceptionRandomAccessFile.readByte()public char readChar()
throws IOExceptionreadChar in interface DataInputreadChar in interface RandomAccessInterfaceIOExceptionRandomAccessFile.readChar()public double readDouble()
throws IOExceptionreadDouble in interface DataInputreadDouble in interface RandomAccessInterfaceIOExceptionRandomAccessFile.readDouble()public float readFloat()
throws IOExceptionreadFloat in interface DataInputreadFloat in interface RandomAccessInterfaceIOExceptionRandomAccessFile.readFloat()public void readFully(byte[] b)
throws IOExceptionreadFully in interface DataInputreadFully in interface RandomAccessInterfaceIOExceptionRandomAccessFile.readFully(byte[])public void readFully(byte[] b,
int off,
int len)
throws IOExceptionreadFully in interface DataInputreadFully in interface RandomAccessInterfaceIOExceptionRandomAccessFile.readFully(byte[],int,int)public int readInt()
throws IOExceptionreadInt in interface DataInputreadInt in interface RandomAccessInterfaceIOExceptionRandomAccessFile.readInt()public String readLine() throws IOException
readLine in interface DataInputreadLine in interface RandomAccessInterfaceIOExceptionRandomAccessFile.readLine()public long readLong()
throws IOExceptionreadLong in interface DataInputreadLong in interface RandomAccessInterfaceIOExceptionRandomAccessFile.readLong()public short readShort()
throws IOExceptionreadShort in interface DataInputreadShort in interface RandomAccessInterfaceIOExceptionRandomAccessFile.readShort()public int readUnsignedByte()
throws IOExceptionreadUnsignedByte in interface DataInputreadUnsignedByte in interface RandomAccessInterfaceIOExceptionRandomAccessFile.readUnsignedByte()public int readUnsignedInt()
throws IOExceptionreadUnsignedInt in interface RandomAccessInterfaceIOException - if the read value is negativepublic int readUnsignedShort()
throws IOExceptionreadUnsignedShort in interface DataInputreadUnsignedShort in interface RandomAccessInterfaceIOExceptionRandomAccessFile.readUnsignedShort()public String readUTF() throws IOException
This method uses a 4-byte length prefix instead of Java's standard 2-byte prefix, allowing for strings up to 16MB in length. The upper byte must be zero for compatibility.
readUTF in interface DataInputreadUTF in interface RandomAccessInterfaceIOException - if the length encoding is invalid or EOF is reachedRandomAccessFile.readUTF()public void seek(long pos)
throws IOExceptionseek in interface RandomAccessInterfaceIOExceptionRandomAccessFile.seek(long)public void setLength(long newLength)
throws IOExceptionsetLength in interface RandomAccessInterfaceIOExceptionRandomAccessFile.setLength(long)public int skipBytes(int n)
throws IOExceptionskipBytes in interface DataInputskipBytes in interface RandomAccessInterfaceIOExceptionRandomAccessFile.skipBytes(int)public void write(byte[] b)
throws IOExceptionwrite in interface DataOutputwrite in interface RandomAccessInterfaceIOExceptionRandomAccessFile.write(byte[])public void write(byte[] b,
int off,
int len)
throws IOExceptionwrite in interface DataOutputwrite in interface RandomAccessInterfaceIOExceptionRandomAccessFile.write(byte[],int,int)public void write(int b)
throws IOExceptionwrite in interface DataOutputwrite in interface RandomAccessInterfaceIOExceptionRandomAccessFile.write(int)public void writeBoolean(boolean v)
throws IOExceptionwriteBoolean in interface DataOutputwriteBoolean in interface RandomAccessInterfaceIOExceptionRandomAccessFile.writeBoolean(boolean)public void writeByte(int v)
throws IOExceptionwriteByte in interface DataOutputwriteByte in interface RandomAccessInterfaceIOExceptionRandomAccessFile.writeByte(int)public void writeBytes(String s) throws IOException
writeBytes in interface DataOutputwriteBytes in interface RandomAccessInterfaceIOExceptionRandomAccessFile.writeBytes(String)public void writeChar(int v)
throws IOExceptionwriteChar in interface DataOutputwriteChar in interface RandomAccessInterfaceIOExceptionRandomAccessFile.writeChar(int)public void writeChars(String s) throws IOException
writeChars in interface DataOutputwriteChars in interface RandomAccessInterfaceIOExceptionRandomAccessFile.writeChars(String)public void writeDouble(double v)
throws IOExceptionwriteDouble in interface DataOutputwriteDouble in interface RandomAccessInterfaceIOExceptionRandomAccessFile.writeDouble(double)public void writeFloat(float v)
throws IOExceptionwriteFloat in interface DataOutputwriteFloat in interface RandomAccessInterfaceIOExceptionRandomAccessFile.writeFloat(float)public void writeInt(int v)
throws IOExceptionwriteInt in interface DataOutputwriteInt in interface RandomAccessInterfaceIOExceptionRandomAccessFile.writeInt(int)public void writeLong(long v)
throws IOExceptionwriteLong in interface DataOutputwriteLong in interface RandomAccessInterfaceIOExceptionRandomAccessFile.writeLong(long)public void writeShort(int v)
throws IOExceptionwriteShort in interface DataOutputwriteShort in interface RandomAccessInterfaceIOExceptionRandomAccessFile.writeShort(int)public void writeUTF(String str) throws IOException
This method uses a 4-byte length prefix instead of Java's standard 2-byte prefix, allowing for strings up to 16MB in length.
writeUTF in interface DataOutputwriteUTF in interface RandomAccessInterfacestr - the string to writeIOException - if the string is too long for encodingRandomAccessFile.writeUTF(String)