Package org.syncany.chunk

Examples of org.syncany.chunk.Chunk


    MultiChunk customMultiChunk = createNewMultiChunk(tempDir, customMultiChunker, transformer);

    for (File file : files) {
      Enumeration<Chunk> chunks = foc.createChunks(file);
      while (chunks.hasMoreElements()) {
        Chunk chunk = chunks.nextElement();
        customMultiChunk.write(chunk);

        if (customMultiChunk.isFull()) {
          customMultiChunk.close();
          resultMultiChunks.add(customMultiChunk);
View Full Code Here


    Chunker chunker = new FixedChunker(EXACT_CHUNK_SIZE, FixedChunker.DEFAULT_DIGEST_ALG);
   
    // Create chunks
    int actualChunkCount = 0;
    Enumeration<Chunk> chunkEnumeration = chunker.createChunks(inputRandom5MBFile);
    Chunk lastChunk = null;
   
    while (chunkEnumeration.hasMoreElements()) {
      actualChunkCount++;
      lastChunk = chunkEnumeration.nextElement();
     
      // Chunk size & checksum
      assertEquals("Chunk does not have the expected size.", EXPECTED_CHUNK_SIZE, lastChunk.getSize());
      assertNotNull("Chunk checksum should not be null.", lastChunk.getChecksum());
     
      outputCopyOfRandom5MBFileOutputStream.write(lastChunk.getContent());
    }
   
    outputCopyOfRandom5MBFileOutputStream.close();
   
    // Number of chunks
    assertEquals("Unexpected number of chunks when chunking", EXPECTED_NUMBER_OF_CHUNKS, actualChunkCount);

    // Checksums
    byte[] inputFileChecksum = FileUtil.createChecksum(inputRandom5MBFile, FixedChunker.DEFAULT_DIGEST_ALG);
    byte[] outputFileChecksum = FileUtil.createChecksum(outputCopyOfRandom5MBFile, FixedChunker.DEFAULT_DIGEST_ALG);
   
    assertArrayEquals("Checksums of input and output file do not match.", inputFileChecksum, outputFileChecksum);
    assertArrayEquals("Last chunk's getFileChecksum() should be the file checksum.", inputFileChecksum, lastChunk.getFileChecksum());
  }
View Full Code Here

   
    Chunker chunker = new TttdChunker(AVG_CHUNK_SIZE);
   
    // Create chunks
    Enumeration<Chunk> chunkEnumeration = chunker.createChunks(inputRandom5MBFile);
    Chunk lastChunk = null;
   
    while (chunkEnumeration.hasMoreElements()) {
      lastChunk = chunkEnumeration.nextElement();
     
      // Checksum
      assertNotNull("Chunk checksum should not be null.", lastChunk.getChecksum());
     
      outputCopyOfRandom5MBFileOutputStream.write(lastChunk.getContent(), 0, lastChunk.getSize());
    }
   
    outputCopyOfRandom5MBFileOutputStream.close();
   
    // Number of chunks
    // TODO [low] How to test the number of chunks?

    // Checksums
    byte[] inputFileChecksum = FileUtil.createChecksum(inputRandom5MBFile, TttdChunker.DEFAULT_DIGEST_ALG);
    byte[] outputFileChecksum = FileUtil.createChecksum(outputCopyOfRandom5MBFile, TttdChunker.DEFAULT_DIGEST_ALG);
   
    assertArrayEquals("Checksums of input and output file do not match.", inputFileChecksum, outputFileChecksum);
    assertArrayEquals("Last chunk's getFileChecksum() should be the file checksum.", inputFileChecksum, lastChunk.getFileChecksum());
  }
View Full Code Here

      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;
  }
View Full Code Here

    File repoMultiChunksFolder = new File(testConnection.getPath(), "multichunks");
    File multiChunkFile = repoMultiChunksFolder.listFiles()[0];
   
    MultiChunk multiChunk = clientA.getConfig().getMultiChunker().createMultiChunk(
      clientA.getConfig().getTransformer().createInputStream(new FileInputStream(multiChunkFile)));   
    Chunk chunk = multiChunk.read();
    multiChunk.close();
   
    // Flip byte in chunk and write new "altered" multichunk
    File alteredMultiChunkFile = new File(multiChunkFile + "-altered");
    MultiChunk alteredMultiChunk = clientA.getConfig().getMultiChunker().createMultiChunk(
      multiChunk.getId(), clientA.getConfig().getTransformer().createOutputStream(new FileOutputStream(alteredMultiChunkFile)));
   
    chunk.getContent()[0] ^= 0x01; // Flip one byte!
    alteredMultiChunk.write(chunk);
    alteredMultiChunk.close();
   
    // Now delete old multichunk, and swap by "altered" file
    multiChunkFile.delete();
View Full Code Here

TOP

Related Classes of org.syncany.chunk.Chunk

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.