public abstract class FileAccess
extends java.lang.Object
implements java.io.DataInput, java.io.DataOutput, java.nio.channels.SeekableByteChannel
Modifier and Type | Field and Description |
---|---|
protected int |
_bufferSize
Größe des Lese und Schreibpuffers
|
protected java.io.DataInputStream |
_dataInStream
Gepufferter EingabeStream, wird bei Bedarf initialisiert und gelöscht
|
protected java.io.DataOutputStream |
_dataOutStream
Gepufferter AusgabeStream, wird bei Bedarf initialisiert und gelöscht
|
protected long |
_position
Aktuelle Dateiposition aus Anwendersicht, 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
|
protected static int |
defaultBufferSize
Standardpuffergröße
|
Constructor and Description |
---|
FileAccess(int bufferSize) |
Modifier and Type | Method and Description |
---|---|
void |
close() |
void |
flush()
Schreibt den Schreibpuffer auf die Festplatte
|
protected void |
flushInStream() |
protected void |
flushOutStream() |
protected abstract java.nio.channels.FileChannel |
getChannel()
Gibt einen gültigen FileChannel zurück, mit dem die Klasse die Datei manipulieren kann.
|
protected abstract java.io.DataInputStream |
getDataInStream()
Gibt einen DataInputStream zum Lesen zurück
|
protected abstract java.io.DataOutputStream |
getDataOutStream()
Gibt einen DataOutputStream zum Schreiben zurück
|
long |
getFilePointer()
Für RandomAccessFile-Kompatibilität
|
abstract boolean |
isOpen() |
long |
length()
Für RandomAccessFile-Kompatibilität
|
long |
position() |
FileAccess |
position(long newPosition) |
int |
read()
Deprecated.
|
int |
read(byte[] b)
Methode analog zu
RandomAccessFile.read(byte[]) . |
int |
read(byte[] b,
int off,
int len)
Methode analog zu
RandomAccessFile.read(byte[], int, int) . |
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()
Gibt die Dateilänge zurück
|
long |
skip(long n)
Überspringt genau n Bytes.
|
int |
skipBytes(int n)
Überspringt n genau Bytes.
|
java.lang.String |
toString() |
FileAccess |
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) |
protected static final int defaultBufferSize
protected final int _bufferSize
protected java.io.DataInputStream _dataInStream
protected java.io.DataOutputStream _dataOutStream
protected long _position
protected void flushInStream()
protected void flushOutStream() throws java.io.IOException
java.io.IOException
protected abstract java.io.DataOutputStream getDataOutStream() throws java.io.IOException
java.io.IOException
protected abstract java.io.DataInputStream getDataInStream() throws java.io.IOException
java.io.IOException
protected abstract java.nio.channels.FileChannel getChannel() throws java.io.IOException
java.io.IOException
public abstract 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
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
- Eingabe-/Ausgabefehler beim Lesen oder Schreiben der Dateipublic long skip(long n) throws java.io.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)java.io.IOException
- Eingabe-/Ausgabefehler beim Lesen oder Schreiben der Dateipublic 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()
readLine
in interface java.io.DataInput
java.lang.UnsupportedOperationException
- immerpublic 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
read
in interface java.nio.channels.SeekableByteChannel
java.io.IOException
public int read(byte[] b) throws java.io.IOException
RandomAccessFile.read(byte[])
. Sollte nicht benutzt werden, sie fehleranfällig ist falls nicht der ganze Puffer
gelesen wird. Besser: readFully(byte[])
b
- Pufferjava.io.IOException
- Eingabe-/Ausgabefehler beim Lesen oder Schreiben der Dateipublic int read(byte[] b, int off, int len) throws java.io.IOException
RandomAccessFile.read(byte[], int, int)
. Sollte nicht benutzt werden, sie fehleranfällig ist falls nicht der ganze
Puffer gelesen wird. Besser: readFully(byte[], int, int)
b
- Pufferoff
- Position im Puffer an die die Daten geschrieben werdenlen
- Maximalanzahl zu lesender Bytesjava.io.IOException
- Eingabe-/Ausgabefehler beim Lesen oder Schreiben der Datei@Deprecated public int read() throws java.io.IOException
RandomAccessFile.read()
. Sollte nicht benutzt werden, da fehleranfällig bei Dateiende. Besser: readByte()
java.io.IOException
- Eingabe-/Ausgabefehler beim Lesen oder Schreiben der Dateipublic int write(java.nio.ByteBuffer src) throws java.io.IOException
write
in interface java.nio.channels.SeekableByteChannel
write
in interface java.nio.channels.WritableByteChannel
java.io.IOException
public long position()
position
in interface java.nio.channels.SeekableByteChannel
FileChannel.position()
public FileAccess position(long newPosition) throws java.io.IOException
position
in interface java.nio.channels.SeekableByteChannel
java.io.IOException
FileChannel.position(long)
public FileAccess truncate(long size) throws java.io.IOException
truncate
in interface java.nio.channels.SeekableByteChannel
java.io.IOException
FileChannel.truncate(long)
public long size() throws java.io.IOException
size
in interface java.nio.channels.SeekableByteChannel
java.io.IOException
FileChannel.size()
public void seek(long position) throws java.io.IOException
position
- Neue Positionjava.io.IOException
position(long)
,
RandomAccessFile.seek(long)
public long getFilePointer()
position()
,
RandomAccessFile.getFilePointer()
public long length() throws java.io.IOException
java.io.IOException
size()
,
RandomAccessFile.length()
public void setLength(long len) throws java.io.IOException
len
- neue Dateilängejava.io.IOException
RandomAccessFile.setLength(long)
public void flush() throws java.io.IOException
java.io.IOException
- Eingabe-/Ausgabefehler beim Lesen oder Schreiben der Dateipublic java.lang.String toString()
toString
in class java.lang.Object