Package de.bsvrz.dav.daf.util
Class CloseableRandomAccessFile
- java.lang.Object
-
- de.bsvrz.dav.daf.util.FileAccess
-
- de.bsvrz.dav.daf.util.CloseableRandomAccessFile
-
- All Implemented Interfaces:
java.io.Closeable
,java.io.DataInput
,java.io.DataOutput
,java.lang.AutoCloseable
,java.nio.channels.ByteChannel
,java.nio.channels.Channel
,java.nio.channels.ReadableByteChannel
,java.nio.channels.SeekableByteChannel
,java.nio.channels.WritableByteChannel
public class CloseableRandomAccessFile extends FileAccess
RandomAccessFile-ähnliche implementierung, die es erlaubt, die Datei zu schließen und bei Bedarf wieder von der selben Position zu öffnen. Diese Implementierung kann verwendet werden, weil eine Applikation sonst viele Dateien gleichzeitig öffnet um Beschränkungen im Betriebssystem zu umgehen.Zusätzlich ist die Ein- und Ausgabe gepuffert, wodurch die Performance wesentlich erhöht wird.
Es sollte sichergestellt werden, dass kein anderer Prozess parallel die Datei bearbeitet, sonst entsteht möglicherweise unerwünschtes Verhalten.
-
-
Field Summary
-
Fields inherited from class de.bsvrz.dav.daf.util.FileAccess
_bufferSize, _dataInStream, _dataOutStream, _position, defaultBufferSize
-
-
Constructor Summary
Constructors Constructor Description CloseableRandomAccessFile(java.io.File file)
CloseableRandomAccessFile(java.io.File file, int bufferSize)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
void
closeFile()
Schließt die Datei auf Betriebssystemebene, aber erlaubt weitere Lese- und Schreibzugriffe.protected java.nio.channels.FileChannel
getChannel()
Gibt einen gültigen FileChannel zurück, mit dem die Klasse die Datei manipulieren kann.protected java.io.DataInputStream
getDataInStream()
Gibt einen DataInputStream zum Lesen zurückprotected java.io.DataOutputStream
getDataOutStream()
Gibt einen DataOutputStream zum Schreiben zurückboolean
isOpen()
protected void
openFile()
-
Methods inherited from class de.bsvrz.dav.daf.util.FileAccess
flush, flushInStream, flushOutStream, getFilePointer, length, position, position, read, read, read, read, readBoolean, readByte, readChar, readDouble, readFloat, readFully, readFully, readInt, readLine, readLong, readShort, readUnsignedByte, readUnsignedShort, readUTF, seek, setLength, size, skip, skipBytes, toString, truncate, write, write, write, write, writeBoolean, writeByte, writeBytes, writeChar, writeChars, writeDouble, writeFloat, writeInt, writeLong, writeShort, writeUTF
-
-
-
-
Method Detail
-
getDataOutStream
protected java.io.DataOutputStream getDataOutStream() throws java.io.IOException
Description copied from class:FileAccess
Gibt einen DataOutputStream zum Schreiben zurück- Specified by:
getDataOutStream
in classFileAccess
- Returns:
- DataOutputStream
- Throws:
java.io.IOException
-
getDataInStream
protected java.io.DataInputStream getDataInStream() throws java.io.IOException
Description copied from class:FileAccess
Gibt einen DataInputStream zum Lesen zurück- Specified by:
getDataInStream
in classFileAccess
- Returns:
- DataInputStream
- Throws:
java.io.IOException
-
getChannel
protected final java.nio.channels.FileChannel getChannel() throws java.io.IOException
Description copied from class:FileAccess
Gibt einen gültigen FileChannel zurück, mit dem die Klasse die Datei manipulieren kann.- Specified by:
getChannel
in classFileAccess
- Returns:
- einen gültigen FileChannel
- Throws:
java.io.IOException
-
openFile
protected void openFile() throws java.io.IOException
- Throws:
java.io.IOException
-
isOpen
public boolean isOpen()
- Specified by:
isOpen
in interfacejava.nio.channels.Channel
- Specified by:
isOpen
in classFileAccess
-
close
public void close() throws java.io.IOException
- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.nio.channels.Channel
- Specified by:
close
in interfacejava.io.Closeable
- Overrides:
close
in classFileAccess
- Throws:
java.io.IOException
-
closeFile
public void closeFile() throws java.io.IOException
Schließt die Datei auf Betriebssystemebene, aber erlaubt weitere Lese- und Schreibzugriffe. Falls später wieder Daten gelesen oder geschrieben werden sollen wird die Datei automatisch erneut geöffnet. Da nicht sichergestellt wird, dass die Datei nicht zwischenzeitlich manipuliert wird muss der Anwender hier vorsichtig sein.- Throws:
java.io.IOException
-
-