public class TempChunkFileManager extends Object
Modifier | Constructor and Description |
---|---|
protected |
TempChunkFileManager() |
Modifier and Type | Method and Description |
---|---|
File |
createTempChunkFile(File destFile,
long offset)
Create the temporary file for the given
destFile and offset . |
protected File |
createTempChunkFile(File destFile,
long offset,
boolean createNewFile) |
TempChunkFileDto |
createTempChunkFileDto(long offset,
File tempChunkFile,
String sha1) |
protected void |
deleteOrFail(File file) |
void |
deleteTempChunkFiles(Collection<TempChunkFileWithDtoFile> tempChunkFileWithDtoFiles) |
void |
deleteTempChunkFilesWithoutDtoFile(Collection<TempChunkFileWithDtoFile> tempChunkFileWithDtoFiles) |
void |
deleteTempDirIfEmpty(File destFile)
Deletes the temporary directory for the given
destFile ,
if this directory is empty. |
static TempChunkFileManager |
getInstance() |
Map<Long,TempChunkFileWithDtoFile> |
getOffset2TempChunkFileWithDtoFile(File destFile) |
File |
getTempChunkFileDtoFile(File tempChunkFile) |
File |
getTempDir(File destFile) |
void |
moveChunks(File oldDestFile,
File newDestFile)
If source file was moved, the chunks need to be moved, too.
|
protected void |
moveOrFail(File oldFile,
File newFile) |
void |
writeFileDataToTempChunkFile(File destFile,
long offset,
byte[] fileData) |
protected TempChunkFileManager()
public static TempChunkFileManager getInstance()
public void writeFileDataToTempChunkFile(File destFile, long offset, byte[] fileData)
protected void deleteOrFail(File file) throws IOException
IOException
public void deleteTempChunkFilesWithoutDtoFile(Collection<TempChunkFileWithDtoFile> tempChunkFileWithDtoFiles)
public Map<Long,TempChunkFileWithDtoFile> getOffset2TempChunkFileWithDtoFile(File destFile)
public File getTempChunkFileDtoFile(File tempChunkFile)
public File createTempChunkFile(File destFile, long offset)
destFile
and offset
.
The returned file is created, if it does not yet exist; but it is not overwritten, if it already exists.
The temporary directory in which the temporary file is located
is created, if necessary. In order to prevent collisions with code trying to delete the empty
temporary directory, this method and the corresponding deleteTempDirIfEmpty(File)
are
both synchronized.
destFile
- the destination file for which to resolve and create the temporary file.
Must not be null
.offset
- the offset (inside the final destination file and the source file) of the block to
be temporarily stored in the temporary file created by this method. The temporary file will hold
solely this block (thus the offset in the temporary file is 0).null
. The file is already created in the file system
(empty), if it did not yet exist.protected File createTempChunkFile(File destFile, long offset, boolean createNewFile)
public void moveChunks(File oldDestFile, File newDestFile)
protected void moveOrFail(File oldFile, File newFile) throws IOException
IOException
public void deleteTempDirIfEmpty(File destFile)
destFile
,
if this directory is empty.
This method is synchronized to prevent it from colliding with createTempChunkFile(File, long)
which first creates the temporary directory and then the file in it. Without synchronisation, the
newly created directory might be deleted by this method, before the temporary file in it is created.
destFile
- the destination file for which to resolve and delete the temporary directory.
Must not be null
.public File getTempDir(File destFile)
public TempChunkFileDto createTempChunkFileDto(long offset, File tempChunkFile, String sha1)
offset
- the offset in the (real) destination file (not in tempChunkFile
! there the offset is always 0).tempChunkFile
- the tempChunkFile containing the chunk's data. Must not be null
.sha1
- the sha1 of the single chunk (in tempChunkFile
). Must not be null
.null
.public void deleteTempChunkFiles(Collection<TempChunkFileWithDtoFile> tempChunkFileWithDtoFiles)
Copyright © 2013–2019. All rights reserved.