public class BufferedRandomAccessFile extends Object implements DataInput, DataOutput, ByteChannel
RandomAccessFile
. Diese Klasse implementiert die Interfaces
DataInput
, DataOutput
und ByteChannel
und unterstützt
alle wesentlichen Methoden eines RandomAccessFile
s
Diese Klasse ist (anders als FileChannel
) nicht für die Verwendung durch mehrere unsynchronisierte
Threads geeignet.Modifier and Type | Field and Description |
---|---|
private int |
_bufferSize
Größe des Lese und Schreibpuffers
|
private FileChannel |
_channel
FileChannel zum lesen und Schreiben der Datei
|
private DataInputStream |
_dataInStream
Gepufferter EingabeStream, wird bei Bedarf initialisiert und gelöscht
|
private DataOutputStream |
_dataOutStream
Gepufferter AusgabeStream, wird bei Bedarf initialisiert und gelöscht
|
private long |
_position
Aktuelle Dateiposition, muss hier gemerkt und selbst berechnet werden, weil die Position des FileChannels durch die
Pufferung beim Lesen und Schreiben nicht notwendigerweise der aktuellen logischen Position entspricht
|
private InputStream |
_rawInStream
ungepufferter EingabeStream
|
private OutputStream |
_rawOutStream
ungepufferter AusgabeStream
|
private static int |
defaultBufferSize
Standardpuffergröße
|
Modifier | Constructor and Description |
---|---|
|
BufferedRandomAccessFile(File file)
Erstellt ein neues gepuffertes BufferedFile als gepufferten Ersatz eines
RandomAccessFile . |
|
BufferedRandomAccessFile(File file,
int bufferSize)
Erstellt ein neues gepuffertes BufferedFile als gepufferten Ersatz eines
RandomAccessFile . |
|
BufferedRandomAccessFile(File file,
String mode)
Erstellt ein neues gepuffertes BufferedFile als gepufferten Ersatz eines
RandomAccessFile . |
|
BufferedRandomAccessFile(File file,
String mode,
int bufferSize)
Erstellt ein neues gepuffertes BufferedFile als gepufferten Ersatz eines
RandomAccessFile . |
private |
BufferedRandomAccessFile(RandomAccessFile randomAccessFile,
int bufferSize) |
Modifier and Type | Method and Description |
---|---|
void |
close() |
private void |
flushInStream() |
private void |
flushOutStream() |
private DataInputStream |
getDataInStream() |
private DataOutputStream |
getDataOutStream() |
long |
getFilePointer()
Für RandomAccessFile-Kompatibilität
|
boolean |
isOpen() |
long |
length()
Für RandomAccessFile-Kompatibilität
|
long |
position() |
BufferedRandomAccessFile |
position(long newPosition) |
int |
read(ByteBuffer dst) |
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()
Deprecated.
|
long |
readLong() |
short |
readShort() |
int |
readUnsignedByte() |
int |
readUnsignedShort() |
String |
readUTF() |
void |
seek(long position)
Für RandomAccessFile-Kompatibilität
|
void |
setLength(long len)
Für RandomAccessFile-Kompatibilität
|
long |
size() |
long |
skip(long n)
Überspringt n genau Bytes.
|
int |
skipBytes(int n)
Überspringt n genau Bytes.
|
String |
toString() |
BufferedRandomAccessFile |
truncate(long size) |
void |
write(byte[] b) |
void |
write(byte[] b,
int off,
int len) |
int |
write(ByteBuffer src) |
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 s) |
private final InputStream _rawInStream
private final OutputStream _rawOutStream
private final FileChannel _channel
private DataInputStream _dataInStream
private DataOutputStream _dataOutStream
private long _position
private int _bufferSize
private static final int defaultBufferSize
public BufferedRandomAccessFile(File file) throws FileNotFoundException
RandomAccessFile
.file
- DateiFileNotFoundException
- Falls Datei nicht gefundenpublic BufferedRandomAccessFile(File file, int bufferSize) throws FileNotFoundException
RandomAccessFile
.file
- DateibufferSize
- Größe des Lese und Schreibpuffers in ByteFileNotFoundException
- Falls Datei nicht gefundenpublic BufferedRandomAccessFile(File file, String mode) throws FileNotFoundException
RandomAccessFile
.file
- Dateimode
- "r" wenn nur gelesen werden soll, "rw" zum Lesen und schreiben. Siehe RandomAccessFile
FileNotFoundException
- Falls Datei nicht gefundenpublic BufferedRandomAccessFile(File file, String mode, int bufferSize) throws FileNotFoundException
RandomAccessFile
.file
- Dateimode
- "r" wenn nur gelesen werden soll, "rw" zum Lesen und schreiben. Siehe RandomAccessFile
bufferSize
- Größe des Lese und Schreibpuffers in ByteFileNotFoundException
- Falls Datei nicht gefundenprivate BufferedRandomAccessFile(RandomAccessFile randomAccessFile, int bufferSize)
private DataOutputStream getDataOutStream()
private DataInputStream getDataInStream() throws IOException
IOException
private void flushInStream()
private void flushOutStream() throws IOException
IOException
public void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
close
in interface Channel
IOException
public void readFully(byte[] b) throws IOException
readFully
in interface DataInput
IOException
public void readFully(byte[] b, int off, int len) throws IOException
readFully
in interface DataInput
IOException
public int skipBytes(int n) throws IOException
position(position() + n); return n;
Diese Methode kann über das Dateiende hinausspringen, vgl. RandomAccessFile.seek(long)
.skipBytes
in interface DataInput
n
- Anzahl zu überspringender Bytes (kann negativ sein, dann wird rückwärts gesprungen)IOException
public long skip(long n) throws IOException
position(position() + n); return n;
Diese Methode kann über das Dateiende hinausspringen, vgl. RandomAccessFile.seek(long)
.n
- Anzahl zu überspringender Bytes (kann negativ sein, dann wird rückwärts gesprungen)IOException
public boolean readBoolean() throws IOException
readBoolean
in interface DataInput
IOException
public byte readByte() throws IOException
readByte
in interface DataInput
IOException
public int readUnsignedByte() throws IOException
readUnsignedByte
in interface DataInput
IOException
public short readShort() throws IOException
readShort
in interface DataInput
IOException
public int readUnsignedShort() throws IOException
readUnsignedShort
in interface DataInput
IOException
public char readChar() throws IOException
readChar
in interface DataInput
IOException
public int readInt() throws IOException
readInt
in interface DataInput
IOException
public long readLong() throws IOException
readLong
in interface DataInput
IOException
public float readFloat() throws IOException
readFloat
in interface DataInput
IOException
public double readDouble() throws IOException
readDouble
in interface DataInput
IOException
@Deprecated public String readLine() throws IOException
readLine
in interface DataInput
IOException
public String readUTF() throws IOException
readUTF
in interface DataInput
IOException
public void write(int b) throws IOException
write
in interface DataOutput
IOException
public void write(byte[] b) throws IOException
write
in interface DataOutput
IOException
public void write(byte[] b, int off, int len) throws IOException
write
in interface DataOutput
IOException
public void writeBoolean(boolean v) throws IOException
writeBoolean
in interface DataOutput
IOException
public void writeByte(int v) throws IOException
writeByte
in interface DataOutput
IOException
public void writeShort(int v) throws IOException
writeShort
in interface DataOutput
IOException
public void writeChar(int v) throws IOException
writeChar
in interface DataOutput
IOException
public void writeInt(int v) throws IOException
writeInt
in interface DataOutput
IOException
public void writeLong(long v) throws IOException
writeLong
in interface DataOutput
IOException
public void writeFloat(float v) throws IOException
writeFloat
in interface DataOutput
IOException
public void writeDouble(double v) throws IOException
writeDouble
in interface DataOutput
IOException
public void writeBytes(String s) throws IOException
writeBytes
in interface DataOutput
IOException
public void writeChars(String s) throws IOException
writeChars
in interface DataOutput
IOException
public void writeUTF(String s) throws IOException
writeUTF
in interface DataOutput
IOException
public int read(ByteBuffer dst) throws IOException
read
in interface ReadableByteChannel
IOException
public int write(ByteBuffer src) throws IOException
write
in interface WritableByteChannel
IOException
public long position()
FileChannel.position()
public BufferedRandomAccessFile position(long newPosition) throws IOException
IOException
FileChannel.position(long)
public long size() throws IOException
IOException
FileChannel.size()
public BufferedRandomAccessFile truncate(long size) throws IOException
IOException
FileChannel.truncate(long)
public void seek(long position) throws IOException
IOException
position(long)
public long getFilePointer()
position()
public long length() throws IOException
IOException
size()
public void setLength(long len) throws IOException
IOException