private Map<FileChecksum, FileContent> createFileContents(ResultSet resultSet) throws SQLException { 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; } return fileContents; }
private void writeFileContents(IndentXmlStreamWriter xmlOut, Collection<FileContent> fileContents) throws XMLStreamException { if (fileContents.size() > 0) { xmlOut.writeStartElement("fileContents"); for (FileContent fileContent : fileContents) { xmlOut.writeStartElement("fileContent"); xmlOut.writeAttribute("checksum", fileContent.getChecksum().toString()); xmlOut.writeAttribute("size", fileContent.getSize()); xmlOut.writeStartElement("chunkRefs"); Collection<ChunkChecksum> fileContentChunkChunks = fileContent.getChunks(); for (ChunkChecksum chunkChecksum : fileContentChunkChunks) { xmlOut.writeEmptyElement("chunkRef"); xmlOut.writeAttribute("ref", chunkChecksum.toString()); } xmlOut.writeEndElement(); // </chunkRefs> xmlOut.writeEndElement(); // </fileContent> } xmlOut.writeEndElement(); // </fileContents> } }
private void writeFileContentChunkRefs(Connection connection, FileContent fileContent) throws SQLException { PreparedStatement preparedStatement = getStatement(connection, "filecontent.insert.all.writeFileContentChunkRefs.sql"); int order = 0; for (ChunkChecksum chunkChecksum : fileContent.getChunks()) { preparedStatement.setString(1, fileContent.getChecksum().toString()); preparedStatement.setString(2, chunkChecksum.toString()); preparedStatement.setInt(3, order); preparedStatement.addBatch(); order++; } preparedStatement.executeBatch(); preparedStatement.close(); }
private FileContent getFileContentWithoutChunkChecksums(FileChecksum fileChecksum) { 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; } } return null; } catch (SQLException e) { throw new RuntimeException(e); } }
PreparedStatement preparedStatement = getStatement(connection, "filecontent.insert.all.writeFileContents.sql"); preparedStatement.setString(1, fileContent.getChecksum().toString()); preparedStatement.setLong(2, databaseVersionId); preparedStatement.setLong(3, fileContent.getSize());
fileContent.setSize(fileProperties.getSize()); fileContent.setChecksum(fileProperties.getChecksum());
public void addFileContent(FileContent content) { fileContents.put(content.getChecksum(), content); }
List<ChunkChecksum> fileChunks = winningFileContent.getChunks();
@Override public void onFileAddChunk(File file, Chunk chunk) { logger.log(Level.FINER, "- Chunk > FileContent: {0} > {1}", new Object[] { StringUtil.toHex(chunk.getChecksum()), file }); fileContent.addChunk(new ChunkChecksum(chunk.getChecksum())); }
@Override public boolean onFileFilter(File file) { logger.log(Level.FINER, "- +File {0}", file); startFileProperties = fileVersionComparator.captureFileProperties(file, null, false); // Check if file has vanished if (!startFileProperties.exists() || startFileProperties.isLocked()) { logger.log(Level.FINER, "- /File: {0}", file); logger.log(Level.INFO, " * NOT ADDING because file has VANISHED (exists = {0}) or is LOCKED (locked = {1}).", new Object[] { startFileProperties.exists(), startFileProperties.isLocked() }); resetFileEnd(); return false; } // Content if (startFileProperties.getType() == FileType.FILE) { logger.log(Level.FINER, "- +FileContent: {0}", file); fileContent = new FileContent(); } return true; }
Collection<ChunkChecksum> fileChunks = fileContent.getChunks(); byte[] reconstructedFileExpectedChecksum = fileContent.getChecksum().getBytes(); byte[] reconstructedFileActualChecksum = reconstructedFileChecksum.digest();
if (fullDatabaseVersionCache.getFileContent(sourceFileContent.getChecksum()) == null) { fullDatabaseVersionCache.addFileContent(sourceFileContent);
Map<ChunkChecksum, MultiChunkId> multiChunks = localDatabase.getMultiChunkIdsByChecksums(fileContent.getChunks());
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; } } catch (SQLException e) { throw new RuntimeException(e); } }
long size = Long.parseLong(attributes.getValue("size")); fileContent = new FileContent(); fileContent.setChecksum(FileChecksum.parseFileChecksum(checksumStr)); fileContent.setSize(size); fileContent.addChunk(ChunkChecksum.parseChunkChecksum(chunkChecksumStr));