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 RandomAccessFile
s
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 RandomAccessFile
java.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 RandomAccessFile
bufferSize
- Größe des Lese und Schreibpuffers in Bytejava.io.FileNotFoundException
- Falls Datei nicht gefundenpublic boolean isOpen()
isOpen
in interface java.nio.channels.Channel
public void close() throws java.io.IOException
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
close
in interface java.nio.channels.Channel
java.io.IOException
public void readFully(byte[] b) throws java.io.IOException
readFully
in interface java.io.DataInput
java.io.IOException
public void readFully(byte[] b, int off, int len) throws java.io.IOException
readFully
in interface java.io.DataInput
java.io.IOException
public 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.DataInput
n
- Anzahl zu überspringender Bytes (kann negativ sein, dann wird rückwärts gesprungen)java.io.IOException
public 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.IOException
public boolean readBoolean() throws java.io.IOException
readBoolean
in interface java.io.DataInput
java.io.IOException
public byte readByte() throws java.io.IOException
readByte
in interface java.io.DataInput
java.io.IOException
public int readUnsignedByte() throws java.io.IOException
readUnsignedByte
in interface java.io.DataInput
java.io.IOException
public short readShort() throws java.io.IOException
readShort
in interface java.io.DataInput
java.io.IOException
public int readUnsignedShort() throws java.io.IOException
readUnsignedShort
in interface java.io.DataInput
java.io.IOException
public char readChar() throws java.io.IOException
readChar
in interface java.io.DataInput
java.io.IOException
public int readInt() throws java.io.IOException
readInt
in interface java.io.DataInput
java.io.IOException
public long readLong() throws java.io.IOException
readLong
in interface java.io.DataInput
java.io.IOException
public float readFloat() throws java.io.IOException
readFloat
in interface java.io.DataInput
java.io.IOException
public double readDouble() throws java.io.IOException
readDouble
in interface java.io.DataInput
java.io.IOException
@Deprecated public java.lang.String readLine() throws java.io.IOException
readLine
in interface java.io.DataInput
java.io.IOException
public java.lang.String readUTF() throws java.io.IOException
readUTF
in interface java.io.DataInput
java.io.IOException
public void write(int b) throws java.io.IOException
write
in interface java.io.DataOutput
java.io.IOException
public void write(byte[] b) throws java.io.IOException
write
in interface java.io.DataOutput
java.io.IOException
public void write(byte[] b, int off, int len) throws java.io.IOException
write
in interface java.io.DataOutput
java.io.IOException
public void writeBoolean(boolean v) throws java.io.IOException
writeBoolean
in interface java.io.DataOutput
java.io.IOException
public void writeByte(int v) throws java.io.IOException
writeByte
in interface java.io.DataOutput
java.io.IOException
public void writeShort(int v) throws java.io.IOException
writeShort
in interface java.io.DataOutput
java.io.IOException
public void writeChar(int v) throws java.io.IOException
writeChar
in interface java.io.DataOutput
java.io.IOException
public void writeInt(int v) throws java.io.IOException
writeInt
in interface java.io.DataOutput
java.io.IOException
public void writeLong(long v) throws java.io.IOException
writeLong
in interface java.io.DataOutput
java.io.IOException
public void writeFloat(float v) throws java.io.IOException
writeFloat
in interface java.io.DataOutput
java.io.IOException
public void writeDouble(double v) throws java.io.IOException
writeDouble
in interface java.io.DataOutput
java.io.IOException
public void writeBytes(java.lang.String s) throws java.io.IOException
writeBytes
in interface java.io.DataOutput
java.io.IOException
public void writeChars(java.lang.String s) throws java.io.IOException
writeChars
in interface java.io.DataOutput
java.io.IOException
public void writeUTF(java.lang.String s) throws java.io.IOException
writeUTF
in interface java.io.DataOutput
java.io.IOException
public int read(java.nio.ByteBuffer dst) throws java.io.IOException
read
in interface java.nio.channels.ReadableByteChannel
java.io.IOException
public int write(java.nio.ByteBuffer src) throws java.io.IOException
write
in interface java.nio.channels.WritableByteChannel
java.io.IOException
public long position()
FileChannel.position()
public BufferedRandomAccessFile position(long newPosition) throws java.io.IOException
java.io.IOException
FileChannel.position(long)
public long size() throws java.io.IOException
java.io.IOException
FileChannel.size()
public BufferedRandomAccessFile truncate(long size) throws java.io.IOException
java.io.IOException
FileChannel.truncate(long)
public void seek(long position) throws java.io.IOException
Für RandomAccessFile-Kompatibilität
java.io.IOException
position(long)
public long getFilePointer()
Für RandomAccessFile-Kompatibilität
position()
public long length() throws java.io.IOException
Für RandomAccessFile-Kompatibilität
java.io.IOException
size()
public void setLength(long len) throws java.io.IOException
Für RandomAccessFile-Kompatibilität
java.io.IOException
public java.lang.String toString()
toString
in class java.lang.Object