use of org.syncany.chunk.MultiChunk in project syncany by syncany.
the class FrameworkCombinationTest method extractChunksFromMultiChunks.
private Map<ChunkChecksum, File> extractChunksFromMultiChunks(List<File> outputMultiChunkFiles, FrameworkCombination combination) throws IOException {
Map<ChunkChecksum, File> extractedChunks = new HashMap<ChunkChecksum, File>();
for (File outputMultiChunkFile : outputMultiChunkFiles) {
logger.log(Level.INFO, "- Extracting multichunk " + outputMultiChunkFile + " ...");
MultiChunk outputMultiChunk = combination.multiChunker.createMultiChunk(combination.transformer.createInputStream(new FileInputStream(outputMultiChunkFile)));
Chunk outputChunkInMultiChunk = null;
while (null != (outputChunkInMultiChunk = outputMultiChunk.read())) {
File extractedChunkFile = new File(tempDir + "/chunk-" + StringUtil.toHex((outputChunkInMultiChunk.getChecksum())) + "-from-multichunk-" + outputMultiChunk.getId());
logger.log(Level.INFO, " + Writing chunk " + StringUtil.toHex((outputChunkInMultiChunk.getChecksum())) + " to " + extractedChunkFile + " ...");
TestFileUtil.writeToFile(outputChunkInMultiChunk.getContent(), extractedChunkFile);
extractedChunks.put(new ChunkChecksum(outputChunkInMultiChunk.getChecksum()), extractedChunkFile);
}
}
return extractedChunks;
}
use of org.syncany.chunk.MultiChunk in project syncany by syncany.
the class MultiChunkerTest method chunkFileIntoMultiChunks.
public void chunkFileIntoMultiChunks(Chunker chunker, MultiChunker multiChunker, int minMultiChunkSize) throws Exception {
File tempDir = TestFileUtil.createTempDirectoryInSystemTemp();
int fileSizeBig = 4560000;
int fileSizeSmall = 1230;
int fileAmountSizeSmall = 2;
int fileAmountSizeBig = 3;
List<File> files = TestFileUtil.createRandomFilesInDirectory(tempDir, fileSizeSmall, fileAmountSizeSmall);
files.addAll(TestFileUtil.createRandomFilesInDirectory(tempDir, fileSizeBig, fileAmountSizeBig));
logger.log(Level.INFO, "- In " + tempDir + " ...");
Set<MultiChunk> resultMultiChunks = chunkFileIntoMultiChunks(tempDir, files, chunker, multiChunker, new NoTransformer());
long totalFilesSize = (fileSizeBig * fileAmountSizeBig) + (fileSizeSmall * fileAmountSizeSmall);
assertEquals(totalFilesSize / minMultiChunkSize / 1024, resultMultiChunks.size());
TestFileUtil.deleteDirectory(tempDir);
}
Aggregations