Search in sources :

Example 6 with MultiChunk

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;
}
Also used : HashMap(java.util.HashMap) MultiChunk(org.syncany.chunk.MultiChunk) ChunkChecksum(org.syncany.database.ChunkEntry.ChunkChecksum) Chunk(org.syncany.chunk.Chunk) MultiChunk(org.syncany.chunk.MultiChunk) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 7 with MultiChunk

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);
}
Also used : NoTransformer(org.syncany.chunk.NoTransformer) MultiChunk(org.syncany.chunk.MultiChunk) ZipFile(java.util.zip.ZipFile) File(java.io.File)

Aggregations

MultiChunk (org.syncany.chunk.MultiChunk)7 File (java.io.File)6 Chunk (org.syncany.chunk.Chunk)4 FileOutputStream (java.io.FileOutputStream)3 ChunkChecksum (org.syncany.database.ChunkEntry.ChunkChecksum)3 MultiChunkId (org.syncany.database.MultiChunkEntry.MultiChunkId)3 FileInputStream (java.io.FileInputStream)2 ZipFile (java.util.zip.ZipFile)2 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 MessageDigest (java.security.MessageDigest)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Test (org.junit.Test)1 Chunker (org.syncany.chunk.Chunker)1 Deduper (org.syncany.chunk.Deduper)1