Package org.syncany.database

Examples of org.syncany.database.FileContent$FileChecksum


   
    MultiChunkEntry newMultiChunkEntry = new MultiChunkEntry(MultiChunkId.parseMultiChunkId("1234567890987654321234567876543456555555"), 10);
    newMultiChunkEntry.addChunk(newChunkEntry.getChecksum());
    newDatabaseVersion.addMultiChunk(newMultiChunkEntry);
   
    FileContent newFileContent = new FileContent();
    newFileContent.setChecksum(FileChecksum.parseFileChecksum("aaaaaaaaaaaaaaaaaaaaab2b263ffa4cc48e282f"));
    newFileContent.setSize(1L);   
    newFileContent.addChunk(newChunkEntry.getChecksum());
    newDatabaseVersion.addFileContent(newFileContent);   
   
    // c. Persist database version
    databaseVersionDao.persistDatabaseVersion(newDatabaseVersion);
   
View Full Code Here


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

    FileContentSqlDao fileContentDao = new FileContentSqlDao(databaseConnection);

    FileContent fileContent1WithChunks = fileContentDao.getFileContent(FileChecksum.parseFileChecksum("eba69a8e359ce3258520138a50ed9860127ab6e0"), true);
    FileContent fileContent1WithoutChunks = fileContentDao.getFileContent(FileChecksum.parseFileChecksum("eba69a8e359ce3258520138a50ed9860127ab6e0"), false);

    FileContent fileContent2WithChunks = fileContentDao.getFileContent(FileChecksum.parseFileChecksum("254416e71ae50431fc6ced6751075b3366db7cc8"), true);
    FileContent fileContent2WithoutChunks = fileContentDao.getFileContent(FileChecksum.parseFileChecksum("254416e71ae50431fc6ced6751075b3366db7cc8"), false);

    FileContent fileContentNonExistingWithChunks = fileContentDao.getFileContent(FileChecksum.parseFileChecksum("beefbeefbeefbeefbeefbeefbeefbeefbeefbeef"), true);
    FileContent fileContentNonExistingWithoutChunks = fileContentDao.getFileContent(FileChecksum.parseFileChecksum("beefbeefbeefbeefbeefbeefbeefbeefbeefbeef"), false);
   
    FileContent fileContentNullChecksum = fileContentDao.getFileContent(null, false);
   
    // Test
    assertNotNull(fileContent1WithChunks);
    assertEquals(1, fileContent1WithChunks.getChunks().size());
    assertEquals("eba69a8e359ce3258520138a50ed9860127ab6e0", fileContent1WithChunks.getChecksum().toString());
View Full Code Here

    try (PreparedStatement preparedStatement = getStatement("filecontent.select.all.getFileContentByChecksumWithoutChunkChecksums.sql")) {
      preparedStatement.setString(1, fileChecksum.toString());

      try (ResultSet resultSet = preparedStatement.executeQuery()) {
        if (resultSet.next()) {
          FileContent fileContent = new FileContent();
 
          fileContent.setChecksum(FileChecksum.parseFileChecksum(resultSet.getString("checksum")));
          fileContent.setSize(resultSet.getLong("size"));
 
          return fileContent;
        }
      }
View Full Code Here

  private FileContent getFileContentWithChunkChecksums(FileChecksum fileChecksum) {
    try (PreparedStatement preparedStatement = getStatement("filecontent.select.all.getFileContentByChecksumWithChunkChecksums.sql")) {
      preparedStatement.setString(1, fileChecksum.toString());

      try (ResultSet resultSet = preparedStatement.executeQuery()) {
        FileContent fileContent = null;
       
        while (resultSet.next()) {
          if (fileContent == null) {
            fileContent = new FileContent();
           
            fileContent.setChecksum(FileChecksum.parseFileChecksum(resultSet.getString("checksum")));
            fileContent.setSize(resultSet.getLong("size"));
          }
         
          // Add chunk references
          ChunkChecksum chunkChecksum = ChunkChecksum.parseChunkChecksum(resultSet.getString("chunk_checksum"));
          fileContent.addChunk(chunkChecksum);
        }
 
        return fileContent;
      }
    }
View Full Code Here

    Map<FileChecksum, FileContent> fileContents = new HashMap<FileChecksum, FileContent>()
    FileChecksum currentFileChecksum = null;
   
    while (resultSet.next()) {   
      FileChecksum fileChecksum = FileChecksum.parseFileChecksum(resultSet.getString("checksum"));
      FileContent fileContent = null;
     
      if (currentFileChecksum != null && currentFileChecksum.equals(fileChecksum)) {
        fileContent = fileContents.get(fileChecksum)
      }
      else {
        fileContent = new FileContent();
       
        fileContent.setChecksum(fileChecksum);
        fileContent.setSize(resultSet.getLong("size"));
      }
     
      ChunkChecksum chunkChecksum = ChunkChecksum.parseChunkChecksum(resultSet.getString("chunk_checksum"));
      fileContent.addChunk(chunkChecksum);

      fileContents.put(fileChecksum, fileContent);
      currentFileChecksum = fileChecksum;
    }
   
View Full Code Here

   */
  public File assembleToCache(FileVersion fileVersion) throws Exception {
    File reconstructedFileInCache = config.getCache().createTempFile("reconstructedFileVersion");
    logger.log(Level.INFO, "     - Creating file " + fileVersion.getPath() + " to " + reconstructedFileInCache + " ...");

    FileContent fileContent = localDatabase.getFileContent(fileVersion.getChecksum(), true);

    if (fileContent == null && memoryDatabase != null) {
      fileContent = memoryDatabase.getContent(fileVersion.getChecksum());
    }
   
    // Check consistency!
    if (fileContent == null && fileVersion.getChecksum() != null) {
      throw new Exception("Cannot determine file content for checksum "+fileVersion.getChecksum());
    }

    // Create empty file
    if (fileContent == null) {
      FileUtils.touch(reconstructedFileInCache)
      return reconstructedFileInCache;
    }
       
    // Create non-empty file
    Chunker chunker = config.getChunker();
    MultiChunker multiChunker = config.getMultiChunker();
   
    FileOutputStream reconstructedFileOutputStream = new FileOutputStream(reconstructedFileInCache);   
    MessageDigest reconstructedFileChecksum = MessageDigest.getInstance(chunker.getChecksumAlgorithm());
   
    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);
        }

        File decryptedMultiChunkFile = config.getCache().getDecryptedMultiChunkFile(multiChunkIdForChunk);

        MultiChunk multiChunk = multiChunker.createMultiChunk(decryptedMultiChunkFile);
        InputStream chunkInputStream = multiChunk.getChunkInputStream(chunkChecksum.getBytes());

            byte[] buffer = new byte[4096];
            int read = 0;

            while (-1 != (read = chunkInputStream.read(buffer))) {
              reconstructedFileChecksum.update(buffer, 0, read);
                reconstructedFileOutputStream.write(buffer, 0, read);
            }
           
        chunkInputStream.close();
        multiChunk.close();
      }
    }

    reconstructedFileOutputStream.close();

    // Validate checksum
    byte[] reconstructedFileExpectedChecksum = fileContent.getChecksum().getBytes();
    byte[] reconstructedFileActualChecksum = reconstructedFileChecksum.digest();
   
    if (!Arrays.equals(reconstructedFileActualChecksum, reconstructedFileExpectedChecksum)) {
      throw new Exception("Checksums do not match: actual " + fileVersion.getChecksum() + " != expected "
          + StringUtil.toHex(reconstructedFileActualChecksum));
View Full Code Here

      }

      // Content
      if (startFileProperties.getType() == FileType.FILE) {
        logger.log(Level.FINER, "- +FileContent: {0}", file);
        fileContent = new FileContent();
      }

      return true;
    }
View Full Code Here

      if (fileProperties.getChecksum() != null && fileContent != null) {
        fileContent.setSize(fileProperties.getSize());
        fileContent.setChecksum(fileProperties.getChecksum());

        // Check if content already exists, throw gathered content away if it does!
        FileContent existingContent = localDatabase.getFileContent(fileProperties.getChecksum(), false);

        if (existingContent == null) {
          newDatabaseVersion.addFileContent(fileContent);
        }
        else {
View Full Code Here

    if (multiChunkIds.size() > 0) {
      multiChunksToDownload.addAll(multiChunkIds);
    }
    else {
      // Second: We don't know it locally; must be from the winners database
      FileContent winningFileContent = winnersDatabase.getContent(fileVersion.getChecksum());     
      boolean winningFileHasContent = winningFileContent != null;

      if (winningFileHasContent) { // File can be empty!
        List<ChunkChecksum> fileChunks = winningFileContent.getChunks();
       
        // TODO [medium] Instead of just looking for multichunks to download here, we should look for chunks in local files as well
        // and return the chunk positions in the local files ChunkPosition (chunk123 at file12, offset 200, size 250)
       
        Map<ChunkChecksum, MultiChunkId> checksumsWithMultiChunkIds = localDatabase.getMultiChunkIdsByChecksums(fileChunks);
View Full Code Here

    try {
      FileHistoryId fileHistoryId = FileHistoryId.parseFileId(concreteRequest.getFileHistoryId());
      long version = concreteRequest.getVersion();

      FileVersion fileVersion = localDatabase.getFileVersion(fileHistoryId, version);
      FileContent fileContent = localDatabase.getFileContent(fileVersion.getChecksum(), true);
      Map<ChunkChecksum, MultiChunkId> multiChunks = localDatabase.getMultiChunkIdsByChecksums(fileContent.getChunks());

      TransferManager transferManager = config.getTransferPlugin().createTransferManager(config.getConnection(), config);
      Downloader downloader = new Downloader(config, transferManager);
      Assembler assembler = new Assembler(config, localDatabase);
View Full Code Here

TOP

Related Classes of org.syncany.database.FileContent$FileChecksum

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.