// Decide whether to index the contents
boolean dedupContents = listener.onFileStart(file, i);
if (dedupContents) {
// Create chunks from file
ChunkEnumeration chunksEnum = chunker.createChunks(file);
while (chunksEnum.hasMoreElements()) {
chunk = chunksEnum.nextElement();
// old chunk
if (!listener.onChunk(chunk)) {
listener.onFileAddChunk(file, chunk);
continue;
}
// new chunk
else {
// - Check if multichunk full
if (multiChunk != null && multiChunk.isFull()) {
multiChunk.close();
listener.onMultiChunkClose(multiChunk);
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)));
listener.onMultiChunkOpen(multiChunk);
}
// - Add chunk data
multiChunk.write(chunk);
listener.onMultiChunkWrite(multiChunk, chunk);
}
listener.onFileAddChunk(file, chunk);
}
// Closing file is necessary!
chunksEnum.close();
}
if (chunk != null) {
listener.onFileEnd(file, chunk.getFileChecksum());
}