ProfileDiskAction { public void load(final Path source, final Path destination, ProgressObserver observer) throws IOException { if (Files.exists(destination)) { FileUtil.deleteQuietly(destination); } final ZipFile zip = new ZipFile(source.toFile()); try { long totalSize = 0L; for (final Enumeration<? extends ZipEntry> it = zip.entries(); it .hasMoreElements();) { ZipEntry e = it.nextElement(); totalSize += e.getSize(); } long bytesSoFar = 0L; for (final Enumeration<? extends ZipEntry> it = zip.entries(); it .hasMoreElements();) { ZipEntry entry = it.nextElement(); final String entryName = getPlatformSpecificPath(entry.getName()); final Path expandedFile = destination.resolve(entryName); Files.createDirectories(expandedFile.getParent()); try (final InputStream in = new BufferedInputStream(zip.getInputStream(entry)); final OutputStream out = new BufferedOutputStream(Files.newOutputStream(expandedFile))) { bytesSoFar = readFile(in, out, observer, bytesSoFar, totalSize); } } observer.onProgress(UNITY_PERCENT); } finally { zip.close(); } }  void saveProfile(final Path baseDir, final Path destination,
            final ProgressObserver callback); void load(final Path source, final Path destination, ProgressObserver observer);  }
@Test public void testLoadProfileFromFile() throws Exception { final Path source = Paths.get("test-profiles/saved.drd"); assertTrue(Files.exists(source)); ProgressObserver observer = mock(ProgressObserver.class); ProfileDiskAction profileDiskAction = new ProfileDiskAction(); profileDiskAction.load(source, profileToLoadDir, observer); assertTrue(Files.isDirectory(profileToLoadDir)); assertTrue(Files.isRegularFile(profileToLoadDir.resolve("profile.xml"))); assertTrue(Files.isDirectory(profileToLoadDir.resolve("db"))); assertTrue(Files.isRegularFile(profileToLoadDir.resolve("db/file2"))); assertTrue(Files.isRegularFile(profileToLoadDir.resolve("db/file3"))); assertTrue(Files.isRegularFile(profileToLoadDir.resolve("db/file4"))); String profileXml = profilesDir.getAbsolutePath() + "/myProfile/profile.xml"; InputStream in = new FileInputStream(profileXml); StringBuilder sb = new StringBuilder(); int bytesIn = 0; byte[] readBuffer = new byte[20]; while ((bytesIn = in.read(readBuffer)) != -1) { sb.append(new String(readBuffer, 0, bytesIn)); } in.close(); String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<profiles/>"; assertEquals(xml, sb.toString()); verify(observer, atLeastOnce()).onProgress(AdditionalMatchers.leq(100)); verify(observer, atLeastOnce()).onProgress(100); }