for (FileData fd : archive.getFileData())
public void load() throws IOException { InterfaceLoader loader = new InterfaceLoader(); Storage storage = store.getStorage(); Index index = store.getIndex(IndexType.INTERFACES); int max = index.getArchives().stream().mapToInt(a -> a.getArchiveId()).max().getAsInt(); interfaces = new InterfaceDefinition[max + 1][]; for (Archive archive : index.getArchives()) { int archiveId = archive.getArchiveId(); byte[] archiveData = storage.loadArchive(archive); ArchiveFiles files = archive.getFiles(archiveData); InterfaceDefinition[] ifaces = interfaces[archiveId]; if (ifaces == null) { ifaces = interfaces[archiveId] = new InterfaceDefinition[archive.getFileData().length]; } for (FSFile file : files.getFiles()) { int fileId = file.getFileId(); int widgetId = (archiveId << 16) + fileId; InterfaceDefinition iface = loader.load(widgetId, file.getContents()); ifaces[fileId] = iface; } } }
public IndexData toIndexData() { IndexData data = new IndexData(); data.setProtocol(protocol); data.setRevision(revision); data.setNamed(named); ArchiveData[] archiveDatas = new ArchiveData[archives.size()]; data.setArchives(archiveDatas); int idx = 0; for (Archive archive : archives) { ArchiveData ad = archiveDatas[idx++] = new ArchiveData(); ad.setId(archive.getArchiveId()); ad.setNameHash(archive.getNameHash()); ad.setCrc(archive.getCrc()); ad.setRevision(archive.getRevision()); FileData[] files = archive.getFileData(); ad.setFiles(files); } return data; } }
FileData[] fileData = archive.getFileData(); FileData file = fileData[i] = new FileData(); file.setNameHash(random.nextInt(Integer.MAX_VALUE)); FileData[] fileData = archive2.getFileData(); FileData file = fileData[i] = new FileData(); file.setNameHash(random.nextInt(Integer.MAX_VALUE)); FileData[] fileData = archive3.getFileData(); FileData file = fileData[i] = new FileData(); file.setNameHash(random.nextInt(Integer.MAX_VALUE));
@Test public void testManyFiles() throws IOException { Random random = new Random(42L); File root = folder.newFolder(); try (Store store = new Store(root)) { Index index = store.addIndex(0); Archive archive = index.addArchive(0); archive.setNameHash(random.nextInt()); archive.setFileData(new FileData[NUMBER_OF_FILES]); for (int i = 0; i < NUMBER_OF_FILES; ++i) { FileData[] fileData = archive.getFileData(); FileData file = fileData[i] = new FileData(); file.setId(i); file.setNameHash(random.nextInt()); } store.save(); try (Store store2 = new Store(root)) { store2.load(); Assert.assertEquals(store, store2); } } }
@Override public void save(Store store) throws IOException { for (Index index : store.getIndexes()) { IndexEntry entry = cacheDao.createIndex(con, cacheEntry, index.getId(), index.getCrc(), index.getRevision()); for (Archive archive : index.getArchives()) { ArchiveEntry archiveEntry = cacheDao.findArchive(con, entry, archive.getArchiveId(), archive.getNameHash(), archive.getCrc(), archive.getRevision()); if (archiveEntry == null) { byte[] hash = archive.getHash(); archiveEntry = cacheDao.createArchive(con, entry, archive.getArchiveId(), archive.getNameHash(), archive.getCrc(), archive.getRevision(), hash); for (FileData file : archive.getFileData()) { cacheDao.associateFileToArchive(con, archiveEntry, file.getId(), file.getNameHash()); } } cacheDao.associateArchiveToIndex(con, archiveEntry, entry); } } }
@Test public void testOneFile() throws IOException { try (Store store = new Store(folder.getRoot())) { Index index = store.addIndex(0); Archive archive = index.addArchive(0); archive.setFileData(new FileData[1]); FileData fileData = archive.getFileData()[0] = new FileData(); fileData.setId(42); fileData.setNameHash(7); store.save(); try (Store store2 = new Store(folder.getRoot())) { store2.load(); Assert.assertEquals(store, store2); } } }