| 64 | } |
| 65 | |
| 66 | public void testUnpackEntryFromStreamToFile() throws IOException { |
| 67 | final String name = "foo"; |
| 68 | final byte[] contents = "bar".getBytes(); |
| 69 | |
| 70 | File file = File.createTempFile("temp", null); |
| 71 | try { |
| 72 | // Create the ZIP file |
| 73 | ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(file)); |
| 74 | try { |
| 75 | zos.putNextEntry(new ZipEntry(name)); |
| 76 | zos.write(contents); |
| 77 | zos.closeEntry(); |
| 78 | } |
| 79 | finally { |
| 80 | IOUtils.closeQuietly(zos); |
| 81 | } |
| 82 | |
| 83 | FileInputStream fis = new FileInputStream(file); |
| 84 | |
| 85 | File outputFile = File.createTempFile("temp-output", null); |
| 86 | |
| 87 | boolean result = ZipUtil.unpackEntry(fis, name, outputFile); |
| 88 | assertTrue(result); |
| 89 | |
| 90 | BufferedInputStream bis = new BufferedInputStream(new FileInputStream(outputFile)); |
| 91 | byte[] actual = new byte[1024]; |
| 92 | int read = bis.read(actual); |
| 93 | bis.close(); |
| 94 | |
| 95 | assertEquals(new String(contents), new String(actual, 0, read)); |
| 96 | } |
| 97 | // 1 |
| 98 | |
| 99 | // 2 |
| 100 | |
| 101 | // 3 |
| 102 | finally { |
| 103 | FileUtils.deleteQuietly(file); |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | public void testUnpackEntryFromStream() throws IOException { |
| 108 | final String name = "foo"; |