Class FileSyncImpl
java.lang.Object
org.aksw.commons.txn.impl.FileSyncImpl
- All Implemented Interfaces:
ContentSync, FileSync, TxnComponent
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionFileSyncImpl(Path targetFile, Path oldContentFile, Path newContentFile, boolean deleteTargetFileOnUpdateWithEmptyContent) -
Method Summary
Modifier and TypeMethodDescriptionstatic FileSyncImplbooleanexists()Returns true iff there is at least one backing resource with the old or new statevoidstatic StringgetBaseName(String str) Return the base name for a file name that is has special meaning w.r.t.Get the path to file with the current content - can be the original file or the temp fileReturns null if not existsstatic InstantGet the file that represents the new contentGet the path to the file that contains the original contentstatic PathDiffStateGet the path to the file affected by the syncnewOutputStreamToNewTmpContent(boolean truncate) Open an output stream to the tmp content.Read the most recent content (maybe open the original file).voidReplace the new content with the current temporary contentvoidputContent(Consumer<OutputStream> outputStreamSupplier) Set the new content of a resource.voidrollback()Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface ContentSync
markForDeletion
-
Field Details
-
targetFile
-
newContentFile
-
newContentTmpFile
-
oldContentFile
-
deleteTargetFileOnUpdateWithEmptyContent
protected boolean deleteTargetFileOnUpdateWithEmptyContentWhether to delete 'targetFile' if the new content is empty -
TO_BASENAME
-
-
Constructor Details
-
FileSyncImpl
-
-
Method Details
-
create
-
getBaseName
Return the base name for a file name that is has special meaning w.r.t. syncing. For example, getBaseName("myfile.sync.old") yields "myfile". Useful for iterating directory content and getting the view of "effective" file names with those special sync files hidden. -
getTargetFile
Description copied from interface:FileSyncGet the path to the file affected by the sync- Specified by:
getTargetFilein interfaceFileSync
-
getOldContentPath
Description copied from interface:FileSyncGet the path to the file that contains the original content- Specified by:
getOldContentPathin interfaceFileSync
-
getCurrentPath
Description copied from interface:FileSyncGet the path to file with the current content - can be the original file or the temp file- Specified by:
getCurrentPathin interfaceFileSync
-
openCurrentContent
Description copied from interface:ContentSyncRead the most recent content (maybe open the original file). Beware that callingmay practically invalidate the returned input stream.invalid reference
#newOutputStreamToNewTmpContent()- Specified by:
openCurrentContentin interfaceContentSync- Throws:
IOException
-
newOutputStreamToNewTmpContent
Description copied from interface:ContentSyncOpen an output stream to the tmp content. If the new content is currently a symlink then it gets deleted and replaced with a regular file- Specified by:
newOutputStreamToNewTmpContentin interfaceContentSync- Throws:
IOException
-
exists
public boolean exists()Description copied from interface:ContentSyncReturns true iff there is at least one backing resource with the old or new state- Specified by:
existsin interfaceContentSync
-
getLastModifiedTime
Description copied from interface:ContentSyncReturns null if not exists- Specified by:
getLastModifiedTimein interfaceContentSync- Throws:
IOException
-
putContent
Set the new content of a resource. The new content is not committed.- Specified by:
putContentin interfaceContentSync- Parameters:
outputStreamSupplier-- Throws:
IOException
-
preCommit
Replace the new content with the current temporary content- Specified by:
preCommitin interfaceTxnComponent- Throws:
IOException
-
finalizeCommit
- Specified by:
finalizeCommitin interfaceTxnComponent- Throws:
IOException
-
rollback
- Specified by:
rollbackin interfaceTxnComponent- Throws:
IOException
-
getNewContentTmpFile
Description copied from interface:FileSyncGet the file that represents the new content- Specified by:
getNewContentTmpFilein interfaceFileSync
-
getLastModifiedTimeAsInstant
-
getState
-