Package org.syncany.database.MultiChunkEntry

Examples of org.syncany.database.MultiChunkEntry.MultiChunkId


  private Map<MultiChunkId, MultiChunkEntry> createMultiChunkEntriesWithoutChunks(ResultSet resultSet) throws SQLException {   
    Map<MultiChunkId, MultiChunkEntry> unusedMultiChunkIds = new HashMap<MultiChunkId, MultiChunkEntry>();   
   
    while (resultSet.next()) {
      MultiChunkId multiChunkId = MultiChunkId.parseMultiChunkId(resultSet.getString("id"));
      long multiChunkSize = resultSet.getLong("size");
           
      unusedMultiChunkIds.put(multiChunkId, new MultiChunkEntry(multiChunkId, multiChunkSize));
    }
   
View Full Code Here


    return unusedMultiChunkIds;
  }
 
  private Map<MultiChunkId, MultiChunkEntry> createMultiChunkEntriesWithChunks(ResultSet resultSet) throws SQLException {
    Map<MultiChunkId, MultiChunkEntry> multiChunkEntries = new HashMap<MultiChunkId, MultiChunkEntry>();   
    MultiChunkId currentMultiChunkId = null;
   
    while (resultSet.next()) {     
      MultiChunkId multiChunkId = MultiChunkId.parseMultiChunkId(resultSet.getString("multichunk_id"));
      long multiChunkSize = resultSet.getLong("size");
     
      MultiChunkEntry multiChunkEntry = null;
     
      if (currentMultiChunkId != null && currentMultiChunkId.equals(multiChunkId)) {
View Full Code Here

    return resultMultiChunks;
  }

  private MultiChunk createNewMultiChunk(File tempDir, MultiChunker customMultiChunker, Transformer transformer) {
    FileOutputStream fos;
    MultiChunkId multiChunkId = MultiChunkId.secureRandomMultiChunkId();

    MultiChunk customChunk = null;
    try {
      fos = new FileOutputStream(tempDir.getAbsolutePath() + "/MultiChunk" + multiChunkId);
      customChunk = customMultiChunker.createMultiChunk(multiChunkId, transformer.createOutputStream(fos));
View Full Code Here

    MemoryDatabase database = new MemoryDatabase();

    // Round 1: Add chunk to multichunk
    DatabaseVersion databaseVersion1 = TestDatabaseUtil.createDatabaseVersion();

    MultiChunkEntry multiChunkP1 = new MultiChunkEntry(new MultiChunkId(new byte[] { 8, 8, 8, 8, 8, 8, 8, 8 }), 10);
    ChunkEntry chunkA1 = new ChunkEntry(new ChunkChecksum(new byte[] { 1, 2, 3, 4, 5, 7, 8, 9, 0 }), 12);

    multiChunkP1.addChunk(chunkA1.getChecksum());
    databaseVersion1.addChunk(chunkA1);
    databaseVersion1.addMultiChunk(multiChunkP1);

    database.addDatabaseVersion(databaseVersion1);

    assertEquals(chunkA1, database.getChunk(new ChunkChecksum(new byte[] { 1, 2, 3, 4, 5, 7, 8, 9, 0 })));
    assertEquals(multiChunkP1, database.getMultiChunk(new MultiChunkId(new byte[] { 8, 8, 8, 8, 8, 8, 8, 8 })));

    // Round 2: Add chunk to multichunk
    DatabaseVersion databaseVersion2 = TestDatabaseUtil.createDatabaseVersion(databaseVersion1);

    MultiChunkEntry multiChunkP2 = new MultiChunkEntry(new MultiChunkId(new byte[] { 7, 7, 7, 7, 7, 7, 7, 7, 7 }), 11);
    MultiChunkEntry multiChunkP3 = new MultiChunkEntry(new MultiChunkId(new byte[] { 5, 5, 5, 5, 5, 5, 5, 5, 5 }), 12);

    ChunkEntry chunkA2 = new ChunkEntry(new ChunkChecksum(new byte[] { 9, 2, 3, 4, 5, 7, 8, 9, 0 }), 912);
    ChunkEntry chunkA3 = new ChunkEntry(new ChunkChecksum(new byte[] { 8, 2, 3, 4, 5, 7, 8, 9, 0 }), 812);
    ChunkEntry chunkA4 = new ChunkEntry(new ChunkChecksum(new byte[] { 7, 2, 3, 4, 5, 7, 8, 9, 0 }), 712);

    multiChunkP2.addChunk(chunkA2.getChecksum());
    multiChunkP2.addChunk(chunkA3.getChecksum());
    multiChunkP3.addChunk(chunkA4.getChecksum());

    databaseVersion2.addChunk(chunkA2);
    databaseVersion2.addChunk(chunkA3);
    databaseVersion2.addChunk(chunkA4);

    databaseVersion2.addMultiChunk(multiChunkP2);
    databaseVersion2.addMultiChunk(multiChunkP3);

    database.addDatabaseVersion(databaseVersion2);

    // fail("xx");

    assertEquals(chunkA1, database.getChunk(new ChunkChecksum(new byte[] { 1, 2, 3, 4, 5, 7, 8, 9, 0 })));
    assertEquals(chunkA2, database.getChunk(new ChunkChecksum(new byte[] { 9, 2, 3, 4, 5, 7, 8, 9, 0 })));
    assertEquals(chunkA3, database.getChunk(new ChunkChecksum(new byte[] { 8, 2, 3, 4, 5, 7, 8, 9, 0 })));
    assertEquals(chunkA4, database.getChunk(new ChunkChecksum(new byte[] { 7, 2, 3, 4, 5, 7, 8, 9, 0 })));
    assertEquals(multiChunkP1, database.getMultiChunk(new MultiChunkId(new byte[] { 8, 8, 8, 8, 8, 8, 8, 8 })));
    assertEquals(multiChunkP2, database.getMultiChunk(new MultiChunkId(new byte[] { 7, 7, 7, 7, 7, 7, 7, 7, 7 })));
    assertEquals(multiChunkP3, database.getMultiChunk(new MultiChunkId(new byte[] { 5, 5, 5, 5, 5, 5, 5, 5, 5 })));
  }
View Full Code Here

      }

      @Override
      public MultiChunkId createNewMultiChunkId(Chunk firstChunk) {
        // Note: In the real implementation, this should be random
        return new MultiChunkId(firstChunk.getChecksum());
      }
     
      @Override public boolean onFileFilter(File file) { return true; }
      @Override public boolean onFileStart(File file, int index) { return file.isFile() && !FileUtil.isSymlink(file); }
      @Override public void onFileEnd(File file, byte[] checksum) { }       
View Full Code Here

    // Run
    TestSqlUtil.runSqlFromResource(databaseConnection, "test.insert.set3.sql");

    MultiChunkSqlDao multiChunkDao = new MultiChunkSqlDao(databaseConnection);
   
    MultiChunkId multiChunkId1 = multiChunkDao.getMultiChunkId(ChunkChecksum.parseChunkChecksum("eba69a8e359ce3258520138a50ed9860127ab6e0"));
    MultiChunkId multiChunkId2 = multiChunkDao.getMultiChunkId(ChunkChecksum.parseChunkChecksum("0fecbac8ac8a5f8b7aa12b2741a4ef5db88c5dea"));
    MultiChunkId multiChunkId3 = multiChunkDao.getMultiChunkId(ChunkChecksum.parseChunkChecksum("38a18897e94a901b833e750e8604d9616a02ca84"));
    MultiChunkId multiChunkIdNonExistent = multiChunkDao.getMultiChunkId(ChunkChecksum.parseChunkChecksum("beefbeefbeefbeefbeefbeefbeefbeefbeefbeef"));

    // Test
    assertNotNull(multiChunkId1);
    assertEquals("0d79eed3fd8ac866b5872ea3f3f079c46dd15ac9", multiChunkId1.toString());
   
View Full Code Here

   
    // - Multi chunk for file 254416e71ae50431fc6ced6751075b3366db7cc8
    assertNotNull(multiChunkIds1);
    assertEquals(1, multiChunkIds1.size());
   
    MultiChunkId multiChunkId1 = multiChunkIds1.get(0);
    assertEquals("51aaca5c1280b1cf95cff8a3266a6bb44b482ad4", multiChunkId1.toString());

    // - Multi chunk for file a7405a0bada0035ed52a1a44a4d381b78dc59d19
    assertNotNull(multiChunkIds2);
    assertEquals(1, multiChunkIds2.size());
   
    MultiChunkId multiChunkId2 = multiChunkIds2.get(0);
    assertEquals("53dbeafe18eb2cd6dc519f8b861cf974fda8f26a", multiChunkId2.toString());

    // - Multi chunk for non existent file
    assertNotNull(multiChunkIdsDoesNotExist);
    assertEquals(0, multiChunkIdsDoesNotExist.size());
   
View Full Code Here

              multiChunk = null;
            }

            // - Open new multichunk if non-existent
            if (multiChunk == null) {
              MultiChunkId newMultiChunkId = listener.createNewMultiChunkId(chunk);
              File multiChunkFile = listener.getMultiChunkFile(newMultiChunkId);
             
              multiChunk = multiChunker.createMultiChunk(newMultiChunkId,
                transformer.createOutputStream(new FileOutputStream(multiChunkFile)));
View Full Code Here

   
    if (fileContent != null) { // File can be empty!
      Collection<ChunkChecksum> fileChunks = fileContent.getChunks();

      for (ChunkChecksum chunkChecksum : fileChunks) {
        MultiChunkId multiChunkIdForChunk = localDatabase.getMultiChunkId(chunkChecksum);

        if (multiChunkIdForChunk == null && memoryDatabase != null) {
          multiChunkIdForChunk = memoryDatabase.getMultiChunkIdForChunk(chunkChecksum);
        }
View Full Code Here

        // and return the chunk positions in the local files ChunkPosition (chunk123 at file12, offset 200, size 250)
       
        Map<ChunkChecksum, MultiChunkId> checksumsWithMultiChunkIds = localDatabase.getMultiChunkIdsByChecksums(fileChunks);
       
        for (ChunkChecksum chunkChecksum : fileChunks) {
          MultiChunkId multiChunkIdForChunk = checksumsWithMultiChunkIds.get(chunkChecksum);
          if (multiChunkIdForChunk == null) {
            multiChunkIdForChunk = winnersDatabase.getMultiChunkIdForChunk(chunkChecksum);
           
            if (multiChunkIdForChunk == null) {
              throw new RuntimeException("Cannot find multichunk for chunk "+chunkChecksum)
View Full Code Here

TOP

Related Classes of org.syncany.database.MultiChunkEntry.MultiChunkId

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.