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 RandomAccessFiles
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 RandomAccessFileFileNotFoundException - 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 RandomAccessFilebufferSize - 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
IOExceptionprivate void flushInStream()
private void flushOutStream()
throws IOException
IOExceptionpublic void close()
throws IOException
close in interface Closeableclose in interface AutoCloseableclose in interface ChannelIOExceptionpublic void readFully(byte[] b)
throws IOException
readFully in interface DataInputIOExceptionpublic void readFully(byte[] b,
int off,
int len)
throws IOException
readFully in interface DataInputIOExceptionpublic 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 DataInputn - Anzahl zu überspringender Bytes (kann negativ sein, dann wird rückwärts gesprungen)IOExceptionpublic 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)IOExceptionpublic boolean readBoolean()
throws IOException
readBoolean in interface DataInputIOExceptionpublic byte readByte()
throws IOException
readByte in interface DataInputIOExceptionpublic int readUnsignedByte()
throws IOException
readUnsignedByte in interface DataInputIOExceptionpublic short readShort()
throws IOException
readShort in interface DataInputIOExceptionpublic int readUnsignedShort()
throws IOException
readUnsignedShort in interface DataInputIOExceptionpublic char readChar()
throws IOException
readChar in interface DataInputIOExceptionpublic int readInt()
throws IOException
readInt in interface DataInputIOExceptionpublic long readLong()
throws IOException
readLong in interface DataInputIOExceptionpublic float readFloat()
throws IOException
readFloat in interface DataInputIOExceptionpublic double readDouble()
throws IOException
readDouble in interface DataInputIOException@Deprecated public String readLine() throws IOException
readLine in interface DataInputIOExceptionpublic String readUTF() throws IOException
readUTF in interface DataInputIOExceptionpublic void write(int b)
throws IOException
write in interface DataOutputIOExceptionpublic void write(byte[] b)
throws IOException
write in interface DataOutputIOExceptionpublic void write(byte[] b,
int off,
int len)
throws IOException
write in interface DataOutputIOExceptionpublic void writeBoolean(boolean v)
throws IOException
writeBoolean in interface DataOutputIOExceptionpublic void writeByte(int v)
throws IOException
writeByte in interface DataOutputIOExceptionpublic void writeShort(int v)
throws IOException
writeShort in interface DataOutputIOExceptionpublic void writeChar(int v)
throws IOException
writeChar in interface DataOutputIOExceptionpublic void writeInt(int v)
throws IOException
writeInt in interface DataOutputIOExceptionpublic void writeLong(long v)
throws IOException
writeLong in interface DataOutputIOExceptionpublic void writeFloat(float v)
throws IOException
writeFloat in interface DataOutputIOExceptionpublic void writeDouble(double v)
throws IOException
writeDouble in interface DataOutputIOExceptionpublic void writeBytes(String s) throws IOException
writeBytes in interface DataOutputIOExceptionpublic void writeChars(String s) throws IOException
writeChars in interface DataOutputIOExceptionpublic void writeUTF(String s) throws IOException
writeUTF in interface DataOutputIOExceptionpublic int read(ByteBuffer dst) throws IOException
read in interface ReadableByteChannelIOExceptionpublic int write(ByteBuffer src) throws IOException
write in interface WritableByteChannelIOExceptionpublic long position()
FileChannel.position()public BufferedRandomAccessFile position(long newPosition) throws IOException
IOExceptionFileChannel.position(long)public long size()
throws IOException
IOExceptionFileChannel.size()public BufferedRandomAccessFile truncate(long size) throws IOException
IOExceptionFileChannel.truncate(long)public void seek(long position)
throws IOException
IOExceptionposition(long)public long getFilePointer()
position()public long length()
throws IOException
IOExceptionsize()public void setLength(long len)
throws IOException
IOException