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
Modifier and Type Method Description voidclose()voidcloseFile()Schließt die Datei auf Betriebssystemebene, aber erlaubt weitere Lese- und Schreibzugriffe.protected java.nio.channels.FileChannelgetChannel()Gibt einen gültigen FileChannel zurück, mit dem die Klasse die Datei manipulieren kann.protected java.io.DataInputStreamgetDataInStream()Gibt einen DataInputStream zum Lesen zurückprotected java.io.DataOutputStreamgetDataOutStream()Gibt einen DataOutputStream zum Schreiben zurückbooleanisOpen()protected voidopenFile()-
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.IOExceptionDescription copied from class:FileAccessGibt einen DataOutputStream zum Schreiben zurück- Specified by:
getDataOutStreamin classFileAccess- Returns:
- DataOutputStream
- Throws:
java.io.IOException
-
getDataInStream
protected java.io.DataInputStream getDataInStream() throws java.io.IOExceptionDescription copied from class:FileAccessGibt einen DataInputStream zum Lesen zurück- Specified by:
getDataInStreamin classFileAccess- Returns:
- DataInputStream
- Throws:
java.io.IOException
-
getChannel
protected final java.nio.channels.FileChannel getChannel() throws java.io.IOExceptionDescription copied from class:FileAccessGibt einen gültigen FileChannel zurück, mit dem die Klasse die Datei manipulieren kann.- Specified by:
getChannelin 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:
isOpenin interfacejava.nio.channels.Channel- Specified by:
isOpenin classFileAccess
-
close
public void close() throws java.io.IOException- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.nio.channels.Channel- Specified by:
closein interfacejava.io.Closeable- Overrides:
closein classFileAccess- Throws:
java.io.IOException
-
closeFile
public void closeFile() throws java.io.IOExceptionSchließ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
-
-