// // EncapsulatedRandomAccessFile class // part of the set of documents known as Java no sugar. // Copyright (c) 1996 Sunil Gupta, sunil@magnetic.demon.co.uk // placed into the public domain by the author // // Unfortunately RandomAccessFile has loads of final methods, which means // that if you want to change behaviours of subclasses (eg byte swapping) // it cant be done in a transparent fashion. This is inheritance by the backdoor // and appears to create a subclasses by encapsulation and changes final // methods to ordinary ones // ****************************************************************************** // import java.io.*; public class EncapsulatedRandomAccessFile extends Object { private RandomAccessFile file; // Constructors public EncapsulatedRandomAccessFile(File infile, String mode) throws IOException { file = new RandomAccessFile(infile, mode);} public EncapsulatedRandomAccessFile(String name, String mode) throws IOException { file = new RandomAccessFile(name, mode);} // Methods public void close() throws IOException {file.close(); } public FileDescriptor getFD() throws IOException {return file.getFD(); } public long getFilePointer() throws IOException {return file.getFilePointer(); } public long length() throws IOException {return file.length(); } public int read() throws IOException {return file.read(); } public int read(byte b[]) throws IOException {return file.read(b); } public int read(byte b[], int off, int len) throws IOException {return file.read(b,off,len); } public boolean readBoolean() throws IOException {return file.readBoolean(); } public byte readByte() throws IOException {return file.readByte(); } public char readChar() throws IOException {return file.readChar(); } public double readDouble() throws IOException {return file.readDouble(); } public float readFloat() throws IOException {return file.readFloat(); } public void readFully(byte b[]) throws IOException {file.readFully(b); } public void readFully(byte b[], int off, int len)throws IOException {file.readFully(b,off,len); } public int readInt() throws IOException {return file.readInt(); } public String readLine() throws IOException {return file.readLine(); } public long readLong() throws IOException {return file.readLong(); } public short readShort() throws IOException {return file.readShort(); } public int readUnsignedByte() throws IOException {return file.readUnsignedByte(); } public int readUnsignedShort() throws IOException {return file.readUnsignedShort();} public String readUTF() throws IOException {return file.readUTF(); } public void seek(long pos) throws IOException {file.seek(pos); } public int skipBytes(int n) throws IOException {return file.skipBytes(n); } public void write(byte b[]) throws IOException {file.write(b); } public void write(byte b[], int off, int len) throws IOException {file.write(b,off,len); } public void write(int b) throws IOException {file.write(b); } public void writeBoolean(boolean v) throws IOException {file.writeBoolean(v); } public void writeByte(int v) throws IOException {file.writeByte(v); } public void writeBytes(String s) throws IOException {file.writeBytes(s); } public void writeChar(int v) throws IOException {file.writeChar(v); } public void writeChars(String s) throws IOException {file.writeChars(s); } public void writeDouble(double v) throws IOException {file.writeDouble(v); } public void writeFloat(float v) throws IOException {file.writeFloat(v); } public void writeInt(int v) throws IOException {file.writeInt(v); } public void writeLong(long v) throws IOException {file.writeLong(v); } public void writeShort(int v) throws IOException {file.writeShort(v); } public void writeUTF(String str) throws IOException {file.writeUTF(str); } }
.