On 11/3/2011 12:50 PM, Jan Burse wrote:
Joshua Cranmer schrieb:
The "standard way" (at least, all of the use cases I've ever had for
RandomAccessFile) effectively uses the methods that are associated with
java.io.DataInput to read data: read(byte[]), and read*().
I would like to use an arbirary encoding/decoding on top of the
byte stream to get a character stream. But since RandomAccessFile
does not implement InputStream/OutputStream, I cannot create
a InputStreamReader/OutputStreamWrite on top.
Bye
5 minutes, untested:
package quicktest;
import java.io.IOException;
import java.io.InputStream;
import java.io.RandomAccessFile;
/**
*
* @author Brenden
*/
public class RndFileStream extends InputStream {
private final RandomAccessFile raf;
public RndFileStream(RandomAccessFile raf) {
this.raf = raf;
}
@Override
public int read() throws IOException {
return raf.read();
}
public void seek( long pos ) throws IOException {
raf.seek(pos);
}
}
I like that, I'm going to have to give it a try.