@Override public void saveArchive(Archive archive, byte[] bytes) throws IOException { data.put((long) archive.getIndex().getId() << 32 | archive.getArchiveId(), bytes); } }
@Override public byte[] loadArchive(Archive archive) throws IOException { return data.get((long) archive.getIndex().getId() << 32 | archive.getArchiveId()); }
@Override public byte[] loadArchive(Archive archive) throws IOException { Index index = archive.getIndex(); IndexFile indexFile = getIndex(index.getId()); assert indexFile.getIndexFileId() == index.getId(); IndexEntry entry = indexFile.read(archive.getArchiveId()); if (entry == null) { logger.debug("can't read archive " + archive.getArchiveId() + " from index " + index.getId()); return null; } assert entry.getId() == archive.getArchiveId(); logger.trace("Loading archive {} for index {} from sector {} length {}", archive.getArchiveId(), index.getId(), entry.getSector(), entry.getLength()); byte[] archiveData = data.read(index.getId(), entry.getId(), entry.getSector(), entry.getLength()); return archiveData; }
@Override public void saveArchive(Archive a, byte[] archiveData) throws IOException { Index index = a.getIndex(); IndexFile indexFile = getIndex(index.getId()); assert indexFile.getIndexFileId() == index.getId(); DataFileWriteResult res = data.write(index.getId(), a.getArchiveId(), archiveData); indexFile.write(new IndexEntry(indexFile, a.getArchiveId(), res.sector, res.compressedLength)); byte compression = archiveData[0]; int compressedSize = Ints.fromBytes(archiveData[1], archiveData[2], archiveData[3], archiveData[4]); // don't crc the appended revision, if it is there int length = 1 // compression type + 4 // compressed size + compressedSize + (compression != CompressionType.NONE ? 4 : 0); Crc32 crc = new Crc32(); crc.update(archiveData, 0, length); a.setCrc(crc.getHash()); logger.trace("Saved archive {}/{} at sector {}, compressed length {}", index.getId(), a.getArchiveId(), res.sector, res.compressedLength); } }
archive.getIndex().getId(), archive.getArchiveId(), hash, archive.getCrc()); throw new RuntimeException("crc mismatch");