public class BufferedRandomAccessFile
extends java.lang.Object
implements java.io.DataInput, java.io.DataOutput, java.nio.channels.ByteChannel
Implementierung eines gepufferten 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.
| Constructor and Description |
|---|
BufferedRandomAccessFile(java.io.File file)
Erstellt ein neues gepuffertes BufferedFile als gepufferten Ersatz eines
RandomAccessFile. |
BufferedRandomAccessFile(java.io.File file,
int bufferSize)
Erstellt ein neues gepuffertes BufferedFile als gepufferten Ersatz eines
RandomAccessFile. |
BufferedRandomAccessFile(java.io.File file,
java.lang.String mode)
Erstellt ein neues gepuffertes BufferedFile als gepufferten Ersatz eines
RandomAccessFile. |
BufferedRandomAccessFile(java.io.File file,
java.lang.String mode,
int bufferSize)
Erstellt ein neues gepuffertes BufferedFile als gepufferten Ersatz eines
RandomAccessFile. |
| Modifier and Type | Method and Description |
|---|---|
void |
close() |
long |
getFilePointer()
Für RandomAccessFile-Kompatibilität
|
boolean |
isOpen() |
long |
length()
Für RandomAccessFile-Kompatibilität
|
long |
position() |
BufferedRandomAccessFile |
position(long newPosition) |
int |
read(java.nio.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() |
java.lang.String |
readLine()
Deprecated.
|
long |
readLong() |
short |
readShort() |
int |
readUnsignedByte() |
int |
readUnsignedShort() |
java.lang.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.
|
java.lang.String |
toString() |
BufferedRandomAccessFile |
truncate(long size) |
void |
write(byte[] b) |
void |
write(byte[] b,
int off,
int len) |
int |
write(java.nio.ByteBuffer src) |
void |
write(int b) |
void |
writeBoolean(boolean v) |
void |
writeByte(int v) |
void |
writeBytes(java.lang.String s) |
void |
writeChar(int v) |
void |
writeChars(java.lang.String s) |
void |
writeDouble(double v) |
void |
writeFloat(float v) |
void |
writeInt(int v) |
void |
writeLong(long v) |
void |
writeShort(int v) |
void |
writeUTF(java.lang.String s) |
public BufferedRandomAccessFile(java.io.File file)
throws java.io.FileNotFoundException
Erstellt ein neues gepuffertes BufferedFile als gepufferten Ersatz eines RandomAccessFile.
file - Dateijava.io.FileNotFoundException - Falls Datei nicht gefundenpublic BufferedRandomAccessFile(java.io.File file,
int bufferSize)
throws java.io.FileNotFoundException
Erstellt ein neues gepuffertes BufferedFile als gepufferten Ersatz eines RandomAccessFile.
file - DateibufferSize - Größe des Lese und Schreibpuffers in Bytejava.io.FileNotFoundException - Falls Datei nicht gefundenpublic BufferedRandomAccessFile(java.io.File file,
java.lang.String mode)
throws java.io.FileNotFoundException
Erstellt ein neues gepuffertes BufferedFile als gepufferten Ersatz eines RandomAccessFile.
file - Dateimode - “r” wenn nur gelesen werden soll, “rw” zum Lesen und schreiben. Siehe RandomAccessFilejava.io.FileNotFoundException - Falls Datei nicht gefundenpublic BufferedRandomAccessFile(java.io.File file,
java.lang.String mode,
int bufferSize)
throws java.io.FileNotFoundException
Erstellt ein neues gepuffertes BufferedFile als gepufferten Ersatz eines RandomAccessFile.
file - Dateimode - “r” wenn nur gelesen werden soll, “rw” zum Lesen und schreiben. Siehe RandomAccessFilebufferSize - Größe des Lese und Schreibpuffers in Bytejava.io.FileNotFoundException - Falls Datei nicht gefundenpublic boolean isOpen()
isOpen in interface java.nio.channels.Channelpublic void close()
throws java.io.IOException
close in interface java.io.Closeableclose in interface java.lang.AutoCloseableclose in interface java.nio.channels.Channeljava.io.IOExceptionpublic void readFully(byte[] b)
throws java.io.IOException
readFully in interface java.io.DataInputjava.io.IOExceptionpublic void readFully(byte[] b,
int off,
int len)
throws java.io.IOException
readFully in interface java.io.DataInputjava.io.IOExceptionpublic int skipBytes(int n)
throws java.io.IOException
Überspringt n genau Bytes. Anders als DataInput definiert wird immer genau die übergebene Zahl an bytes übersprungen, d.h. die Methode gibt immer den Parameter n zurück. Daher entspricht diese Methode position(position() + n); return n;
Diese Methode kann über das Dateiende hinausspringen, vgl. RandomAccessFile.seek(long).
skipBytes in interface java.io.DataInputn - Anzahl zu überspringender Bytes (kann negativ sein, dann wird rückwärts gesprungen)java.io.IOExceptionpublic long skip(long n)
throws java.io.IOException
Überspringt n genau Bytes. Daher entspricht diese Methode 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)java.io.IOExceptionpublic boolean readBoolean()
throws java.io.IOException
readBoolean in interface java.io.DataInputjava.io.IOExceptionpublic byte readByte()
throws java.io.IOException
readByte in interface java.io.DataInputjava.io.IOExceptionpublic int readUnsignedByte()
throws java.io.IOException
readUnsignedByte in interface java.io.DataInputjava.io.IOExceptionpublic short readShort()
throws java.io.IOException
readShort in interface java.io.DataInputjava.io.IOExceptionpublic int readUnsignedShort()
throws java.io.IOException
readUnsignedShort in interface java.io.DataInputjava.io.IOExceptionpublic char readChar()
throws java.io.IOException
readChar in interface java.io.DataInputjava.io.IOExceptionpublic int readInt()
throws java.io.IOException
readInt in interface java.io.DataInputjava.io.IOExceptionpublic long readLong()
throws java.io.IOException
readLong in interface java.io.DataInputjava.io.IOExceptionpublic float readFloat()
throws java.io.IOException
readFloat in interface java.io.DataInputjava.io.IOExceptionpublic double readDouble()
throws java.io.IOException
readDouble in interface java.io.DataInputjava.io.IOException@Deprecated
public java.lang.String readLine()
throws java.io.IOException
readLine in interface java.io.DataInputjava.io.IOExceptionpublic java.lang.String readUTF()
throws java.io.IOException
readUTF in interface java.io.DataInputjava.io.IOExceptionpublic void write(int b)
throws java.io.IOException
write in interface java.io.DataOutputjava.io.IOExceptionpublic void write(byte[] b)
throws java.io.IOException
write in interface java.io.DataOutputjava.io.IOExceptionpublic void write(byte[] b,
int off,
int len)
throws java.io.IOException
write in interface java.io.DataOutputjava.io.IOExceptionpublic void writeBoolean(boolean v)
throws java.io.IOException
writeBoolean in interface java.io.DataOutputjava.io.IOExceptionpublic void writeByte(int v)
throws java.io.IOException
writeByte in interface java.io.DataOutputjava.io.IOExceptionpublic void writeShort(int v)
throws java.io.IOException
writeShort in interface java.io.DataOutputjava.io.IOExceptionpublic void writeChar(int v)
throws java.io.IOException
writeChar in interface java.io.DataOutputjava.io.IOExceptionpublic void writeInt(int v)
throws java.io.IOException
writeInt in interface java.io.DataOutputjava.io.IOExceptionpublic void writeLong(long v)
throws java.io.IOException
writeLong in interface java.io.DataOutputjava.io.IOExceptionpublic void writeFloat(float v)
throws java.io.IOException
writeFloat in interface java.io.DataOutputjava.io.IOExceptionpublic void writeDouble(double v)
throws java.io.IOException
writeDouble in interface java.io.DataOutputjava.io.IOExceptionpublic void writeBytes(java.lang.String s)
throws java.io.IOException
writeBytes in interface java.io.DataOutputjava.io.IOExceptionpublic void writeChars(java.lang.String s)
throws java.io.IOException
writeChars in interface java.io.DataOutputjava.io.IOExceptionpublic void writeUTF(java.lang.String s)
throws java.io.IOException
writeUTF in interface java.io.DataOutputjava.io.IOExceptionpublic int read(java.nio.ByteBuffer dst)
throws java.io.IOException
read in interface java.nio.channels.ReadableByteChanneljava.io.IOExceptionpublic int write(java.nio.ByteBuffer src)
throws java.io.IOException
write in interface java.nio.channels.WritableByteChanneljava.io.IOExceptionpublic long position()
FileChannel.position()public BufferedRandomAccessFile position(long newPosition) throws java.io.IOException
java.io.IOExceptionFileChannel.position(long)public long size()
throws java.io.IOException
java.io.IOExceptionFileChannel.size()public BufferedRandomAccessFile truncate(long size) throws java.io.IOException
java.io.IOExceptionFileChannel.truncate(long)public void seek(long position)
throws java.io.IOException
Für RandomAccessFile-Kompatibilität
java.io.IOExceptionposition(long)public long getFilePointer()
Für RandomAccessFile-Kompatibilität
position()public long length()
throws java.io.IOException
Für RandomAccessFile-Kompatibilität
java.io.IOExceptionsize()public void setLength(long len)
throws java.io.IOException
Für RandomAccessFile-Kompatibilität
java.io.IOExceptionpublic java.lang.String toString()
toString in class java.lang.Object