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 booleancanWrite()I2P is the file writable? Only valid if the File constructor was used, not the RAF constructorvoidclose()longgetFilePointer()longlength()intread()intread(byte[] b)intread(byte[] b, int off, int len)booleanreadBoolean()bytereadByte()charreadChar()doublereadDouble()floatreadFloat()voidreadFully(byte[] b)voidreadFully(byte[] b, int off, int len)intreadInt()StringreadLine()longreadLong()shortreadShort()intreadUnsignedByte()intreadUnsignedInt()I2PintreadUnsignedShort()StringreadUTF()Read a UTF encoded string I would delegate here.voidseek(long pos)voidsetLength(long newLength)intskipBytes(int n)StringtoString()voidwrite(byte[] b)voidwrite(byte[] b, int off, int len)voidwrite(int b)voidwriteBoolean(boolean v)voidwriteByte(int v)voidwriteBytes(String s)voidwriteChar(int v)voidwriteChars(String s)voidwriteDouble(double v)voidwriteFloat(float v)voidwriteInt(int v)voidwriteLong(long v)voidwriteShort(int v)voidwriteUTF(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:
canWritein interfaceRandomAccessInterface- Since:
- 0.8.8
-
getFilePointer
public long getFilePointer() throws IOException- Specified by:
getFilePointerin interfaceRandomAccessInterface- Throws:
IOException
-
length
public long length() throws IOException- Specified by:
lengthin interfaceRandomAccessInterface- Throws:
IOException
-
read
public int read() throws IOException- Specified by:
readin interfaceRandomAccessInterface- Throws:
IOException
-
read
public int read(byte[] b) throws IOException- Specified by:
readin interfaceRandomAccessInterface- Throws:
IOException
-
read
public int read(byte[] b, int off, int len) throws IOException- Specified by:
readin interfaceRandomAccessInterface- Throws:
IOException
-
seek
public void seek(long pos) throws IOException- Specified by:
seekin interfaceRandomAccessInterface- Throws:
IOException
-
setLength
public void setLength(long newLength) throws IOException- Specified by:
setLengthin interfaceRandomAccessInterface- Throws:
IOException
-
close
public void close() throws IOException- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein interfaceRandomAccessInterface- Throws:
IOException
-
readBoolean
public boolean readBoolean() throws IOException- Specified by:
readBooleanin interfaceDataInput- Specified by:
readBooleanin interfaceRandomAccessInterface- Throws:
IOException
-
readByte
public byte readByte() throws IOException- Specified by:
readBytein interfaceDataInput- Specified by:
readBytein interfaceRandomAccessInterface- Throws:
IOException
-
readChar
public char readChar() throws IOException- Specified by:
readCharin interfaceDataInput- Specified by:
readCharin interfaceRandomAccessInterface- Throws:
IOException
-
readDouble
public double readDouble() throws IOException- Specified by:
readDoublein interfaceDataInput- Specified by:
readDoublein interfaceRandomAccessInterface- Throws:
IOException
-
readFloat
public float readFloat() throws IOException- Specified by:
readFloatin interfaceDataInput- Specified by:
readFloatin interfaceRandomAccessInterface- Throws:
IOException
-
readFully
public void readFully(byte[] b) throws IOException- Specified by:
readFullyin interfaceDataInput- Specified by:
readFullyin interfaceRandomAccessInterface- Throws:
IOException
-
readFully
public void readFully(byte[] b, int off, int len) throws IOException- Specified by:
readFullyin interfaceDataInput- Specified by:
readFullyin interfaceRandomAccessInterface- Throws:
IOException
-
readInt
public int readInt() throws IOException- Specified by:
readIntin interfaceDataInput- Specified by:
readIntin interfaceRandomAccessInterface- Throws:
IOException
-
readLine
public String readLine() throws IOException
- Specified by:
readLinein interfaceDataInput- Specified by:
readLinein interfaceRandomAccessInterface- Throws:
IOException
-
readLong
public long readLong() throws IOException- Specified by:
readLongin interfaceDataInput- Specified by:
readLongin interfaceRandomAccessInterface- Throws:
IOException
-
readShort
public short readShort() throws IOException- Specified by:
readShortin interfaceDataInput- Specified by:
readShortin interfaceRandomAccessInterface- Throws:
IOException
-
readUnsignedByte
public int readUnsignedByte() throws IOException- Specified by:
readUnsignedBytein interfaceDataInput- Specified by:
readUnsignedBytein interfaceRandomAccessInterface- Throws:
IOException
-
readUnsignedShort
public int readUnsignedShort() throws IOException- Specified by:
readUnsignedShortin interfaceDataInput- Specified by:
readUnsignedShortin interfaceRandomAccessInterface- Throws:
IOException
-
readUnsignedInt
public int readUnsignedInt() throws IOExceptionI2P- Specified by:
readUnsignedIntin 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:
readUTFin interfaceDataInput- Specified by:
readUTFin interfaceRandomAccessInterface- Throws:
IOException
-
skipBytes
public int skipBytes(int n) throws IOException- Specified by:
skipBytesin interfaceDataInput- Specified by:
skipBytesin interfaceRandomAccessInterface- Throws:
IOException
-
write
public void write(int b) throws IOException- Specified by:
writein interfaceDataOutput- Specified by:
writein interfaceRandomAccessInterface- Throws:
IOException
-
write
public void write(byte[] b) throws IOException- Specified by:
writein interfaceDataOutput- Specified by:
writein interfaceRandomAccessInterface- Throws:
IOException
-
write
public void write(byte[] b, int off, int len) throws IOException- Specified by:
writein interfaceDataOutput- Specified by:
writein interfaceRandomAccessInterface- Throws:
IOException
-
writeBoolean
public void writeBoolean(boolean v) throws IOException- Specified by:
writeBooleanin interfaceDataOutput- Specified by:
writeBooleanin interfaceRandomAccessInterface- Throws:
IOException
-
writeByte
public void writeByte(int v) throws IOException- Specified by:
writeBytein interfaceDataOutput- Specified by:
writeBytein interfaceRandomAccessInterface- Throws:
IOException
-
writeShort
public void writeShort(int v) throws IOException- Specified by:
writeShortin interfaceDataOutput- Specified by:
writeShortin interfaceRandomAccessInterface- Throws:
IOException
-
writeChar
public void writeChar(int v) throws IOException- Specified by:
writeCharin interfaceDataOutput- Specified by:
writeCharin interfaceRandomAccessInterface- Throws:
IOException
-
writeInt
public void writeInt(int v) throws IOException- Specified by:
writeIntin interfaceDataOutput- Specified by:
writeIntin interfaceRandomAccessInterface- Throws:
IOException
-
writeLong
public void writeLong(long v) throws IOException- Specified by:
writeLongin interfaceDataOutput- Specified by:
writeLongin interfaceRandomAccessInterface- Throws:
IOException
-
writeFloat
public void writeFloat(float v) throws IOException- Specified by:
writeFloatin interfaceDataOutput- Specified by:
writeFloatin interfaceRandomAccessInterface- Throws:
IOException
-
writeDouble
public void writeDouble(double v) throws IOException- Specified by:
writeDoublein interfaceDataOutput- Specified by:
writeDoublein interfaceRandomAccessInterface- Throws:
IOException
-
writeBytes
public void writeBytes(String s) throws IOException
- Specified by:
writeBytesin interfaceDataOutput- Specified by:
writeBytesin interfaceRandomAccessInterface- Throws:
IOException
-
writeChars
public void writeChars(String s) throws IOException
- Specified by:
writeCharsin interfaceDataOutput- Specified by:
writeCharsin 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:
writeUTFin interfaceDataOutput- Specified by:
writeUTFin interfaceRandomAccessInterface- Throws:
IOException
-
-