Package org.cryptomator.cryptofs.fh
Class OpenCryptoFiles
- java.lang.Object
-
- org.cryptomator.cryptofs.fh.OpenCryptoFiles
-
- All Implemented Interfaces:
Closeable,AutoCloseable
@CryptoFileSystemScoped public class OpenCryptoFiles extends Object implements Closeable
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description classOpenCryptoFiles.TwoPhaseMove
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Close all currently opened files by invokingOpenCryptoFile.close().Optional<OpenCryptoFile>get(Path ciphertextPath)Gets an OpenCryptoFile (if any is opened) without creating it.OpenCryptoFilegetOrCreate(Path ciphertextPath)Opens a file toretrieve a FileChannel.OpenCryptoFiles.TwoPhaseMoveprepareMove(Path src, Path dst)Prepares to update any open file references during a move operation.ByteBufferreadCiphertextFile(Path ciphertextPath, EffectiveOpenOptions openOptions, int maxBufferSize)voidwriteCiphertextFile(Path ciphertextPath, EffectiveOpenOptions openOptions, ByteBuffer contents)
-
-
-
Method Detail
-
get
public Optional<OpenCryptoFile> get(Path ciphertextPath)
Gets an OpenCryptoFile (if any is opened) without creating it.Useful if you don't want to create any FileChannel but want to check whether this file is currently opened (e.g. to get its current
OpenCryptoFile.size()).- Parameters:
ciphertextPath- Path of the file which might have been opened- Returns:
- The OpenCryptoFile if opened or an empty Optional otherwise.
-
getOrCreate
public OpenCryptoFile getOrCreate(Path ciphertextPath)
Opens a file toretrieve a FileChannel. If this file is already opened, a shared instance is returned. Getting the file channel should be the next invocation, since thelifecycleof the OpenFile strictly depends on the lifecycle of the channel.- Parameters:
ciphertextPath- Path of the file to open- Returns:
- The opened file.
- See Also:
get(Path)
-
writeCiphertextFile
public void writeCiphertextFile(Path ciphertextPath, EffectiveOpenOptions openOptions, ByteBuffer contents) throws IOException
- Throws:
IOException
-
readCiphertextFile
public ByteBuffer readCiphertextFile(Path ciphertextPath, EffectiveOpenOptions openOptions, int maxBufferSize) throws BufferUnderflowException, IOException
- Throws:
BufferUnderflowExceptionIOException
-
prepareMove
public OpenCryptoFiles.TwoPhaseMove prepareMove(Path src, Path dst) throws FileAlreadyExistsException
Prepares to update any open file references during a move operation. MUST be invoked using a try-with-resource statement and committed after the physical file move succeeded.- Parameters:
src- The ciphertext file path before the movedst- The ciphertext file path after the move- Returns:
- Utility to update OpenCryptoFile references.
- Throws:
FileAlreadyExistsException- Thrown if the destination file is an existing file that is currently opened.
-
close
public void close()
Close all currently opened files by invokingOpenCryptoFile.close().- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-
-