@Test public void unzipTestZip() throws FileNotFoundException, IOException { File f = new File(path + "testZip.zip"); FileInputStream s = new FileInputStream(f); byte[] b = IOUtils.toByteArray(s); s.close(); ZippedProject project = new ZippedProject(); Unzipper unzipper = new Unzipper(project, new UnzipAllTheThings()); project.setBytes(b); unzipper.unzipTo(new FileIO(path)); f = new File(path + "testFile.txt"); Scanner scanner = null; try { scanner = new Scanner(f); assertEquals("This is a test. ", scanner.nextLine()); assertEquals(false, scanner.hasNextLine()); } finally { if (scanner != null) { scanner.close(); } f.delete(); } }
public List<String> unzipTo(FileIO destinationFolder) throws IOException { List<String> projectFiles = new ArrayList<String>(); destinationFolder.createFolderTree(false); ZipInputStream zipStream = new ZipInputStream(new ByteArrayInputStream(project.getBytes())); ZipEntry zipEntry = zipStream.getNextEntry(); while (zipEntry != null) { String entryPath = FileUtil.append(destinationFolder.getPath(), zipEntry.getName()); projectFiles.add(entryPath); if (!decider.shouldUnzip(entryPath)) { zipEntry = zipStream.getNextEntry(); continue; } FileIO file = new FileIO(entryPath); file.createFolderTree(!zipEntry.isDirectory()); byte[] buffer = new byte[BUFFER_SIZE]; ByteArrayOutputStream stream = new ByteArrayOutputStream(); int read = 0; while ((read = zipStream.read(buffer)) != -1) { stream.write(buffer, 0, read); buffer = new byte[BUFFER_SIZE]; } if (!zipEntry.isDirectory()) { file.write(stream.toByteArray()); } zipEntry = zipStream.getNextEntry(); } return projectFiles; }
Unzipper { public List<String> unzipTo(FileIO destinationFolder) throws IOException { List<String> projectFiles = new ArrayList<String>(); destinationFolder.createFolderTree(false); ZipInputStream zipStream = new ZipInputStream(new ByteArrayInputStream(project.getBytes())); ZipEntry zipEntry = zipStream.getNextEntry(); while (zipEntry != null) { String entryPath = FileUtil.append(destinationFolder.getPath(), zipEntry.getName()); projectFiles.add(entryPath); if (!decider.shouldUnzip(entryPath)) { zipEntry = zipStream.getNextEntry(); continue; } FileIO file = new FileIO(entryPath); file.createFolderTree(!zipEntry.isDirectory()); byte[] buffer = new byte[BUFFER_SIZE]; ByteArrayOutputStream stream = new ByteArrayOutputStream(); int read = 0; while ((read = zipStream.read(buffer)) != -1) { stream.write(buffer, 0, read); buffer = new byte[BUFFER_SIZE]; } if (!zipEntry.isDirectory()) { file.write(stream.toByteArray()); } zipEntry = zipStream.getNextEntry(); } return projectFiles; } }
Unzipper { public List<String> unzipTo(FileIO destinationFolder) throws IOException { List<String> projectFiles = new ArrayList<String>(); destinationFolder.createFolderTree(false); ZipInputStream zipStream = new ZipInputStream(new ByteArrayInputStream(project.getBytes())); ZipEntry zipEntry = zipStream.getNextEntry(); while (zipEntry != null) { String entryPath = FileUtil.append(destinationFolder.getPath(), zipEntry.getName()); projectFiles.add(entryPath); if (!decider.shouldUnzip(entryPath)) { zipEntry = zipStream.getNextEntry(); continue; } FileIO file = new FileIO(entryPath); file.createFolderTree(!zipEntry.isDirectory()); byte[] buffer = new byte[BUFFER_SIZE]; ByteArrayOutputStream stream = new ByteArrayOutputStream(); int read = 0; while ((read = zipStream.read(buffer)) != -1) { stream.write(buffer, 0, read); buffer = new byte[BUFFER_SIZE]; } if (!zipEntry.isDirectory()) { file.write(stream.toByteArray()); } zipEntry = zipStream.getNextEntry(); } return projectFiles; } Unzipper(ZippedProject project, UnzippingDecider decider); }
Unzipper { public List<String> unzipTo(FileIO destinationFolder) throws IOException { List<String> projectFiles = new ArrayList<String>(); destinationFolder.createFolderTree(false); ZipInputStream zipStream = new ZipInputStream(new ByteArrayInputStream(project.getBytes())); ZipEntry zipEntry = zipStream.getNextEntry(); while (zipEntry != null) { String entryPath = FileUtil.append(destinationFolder.getPath(), zipEntry.getName()); projectFiles.add(entryPath); if (!decider.shouldUnzip(entryPath)) { zipEntry = zipStream.getNextEntry(); continue; } FileIO file = new FileIO(entryPath); file.createFolderTree(!zipEntry.isDirectory()); byte[] buffer = new byte[BUFFER_SIZE]; ByteArrayOutputStream stream = new ByteArrayOutputStream(); int read = 0; while ((read = zipStream.read(buffer)) != -1) { stream.write(buffer, 0, read); buffer = new byte[BUFFER_SIZE]; } if (!zipEntry.isDirectory()) { file.write(stream.toByteArray()); } zipEntry = zipStream.getNextEntry(); } return projectFiles; } Unzipper(ZippedProject project, UnzippingDecider decider); List<String> unzipTo(FileIO destinationFolder); }
Unzipper { public List<String> unzipTo(FileIO destinationFolder) throws IOException { List<String> projectFiles = new ArrayList<String>(); destinationFolder.createFolderTree(false); ZipInputStream zipStream = new ZipInputStream(new ByteArrayInputStream(project.getBytes())); ZipEntry zipEntry = zipStream.getNextEntry(); while (zipEntry != null) { String entryPath = FileUtil.append(destinationFolder.getPath(), zipEntry.getName()); projectFiles.add(entryPath); if (!decider.shouldUnzip(entryPath)) { zipEntry = zipStream.getNextEntry(); continue; } FileIO file = new FileIO(entryPath); file.createFolderTree(!zipEntry.isDirectory()); byte[] buffer = new byte[BUFFER_SIZE]; ByteArrayOutputStream stream = new ByteArrayOutputStream(); int read = 0; while ((read = zipStream.read(buffer)) != -1) { stream.write(buffer, 0, read); buffer = new byte[BUFFER_SIZE]; } if (!zipEntry.isDirectory()) { file.write(stream.toByteArray()); } zipEntry = zipStream.getNextEntry(); } return projectFiles; } Unzipper(ZippedProject project, UnzippingDecider decider); List<String> unzipTo(FileIO destinationFolder);  }