### Question:
ZipUtils { public static Optional<ArrayByteSource> unzipPathNameInMemory(BeanByteSource source, String relativePathName) { ArgChecker.notNull(relativePathName, "relativePathName"); try (ZipInputStream in = new ZipInputStream(source.openStream())) { ZipEntry entry = in.getNextEntry(); while (entry != null) { validateZipPathName(DUMMY_PATH, entry); if (!entry.isDirectory() && entry.getName().equals(relativePathName)) { ArrayByteSource extractedBytes = extractInputStream(in, entry.getName()); return Optional.of(extractedBytes); } in.closeEntry(); entry = in.getNextEntry(); } } catch (IOException ex) { throw new UncheckedIOException(ex); } return Optional.empty(); } private  ZipUtils(); static Set<String> unzipPathNames(BeanByteSource source); static Optional<ArrayByteSource> unzipPathNameInMemory(BeanByteSource source, String relativePathName); static void unzip(BeanByteSource source, Path path); static ArrayByteSource zipInMemory(List<? extends BeanByteSource> sources); static Map<String, ArrayByteSource> unpackInMemory(BeanByteSource source); static void unpackInMemory(BeanByteSource source, BiConsumer<String, ArrayByteSource> consumer); static Map<String, ArrayByteSource> unzipInMemory(BeanByteSource source); static void unzipInMemory(BeanByteSource source, BiConsumer<String, ArrayByteSource> consumer); static BeanByteSource decryptZip(BeanByteSource source, String password);  }### Answer:
@Test public void test_unzipPathNameInMemory() { ArrayByteSource zipFile = load("TestFolder.zip"); assertThat(ZipUtils.unzipPathNameInMemory(zipFile, "test/alpha/Alpha.txt")) .map(source -> source.readUtf8()) .hasValue("ALPHA"); assertThat(ZipUtils.unzipPathNameInMemory(zipFile, "test/beta/Beta1.txt")) .map(source -> source.readUtf8()) .hasValue("BETA1"); assertThat(ZipUtils.unzipPathNameInMemory(zipFile, "test/beta/Beta2.txt")) .map(source -> source.readUtf8()) .hasValue("BETA2"); }
@Test public void test_unzipPathNameInMemory_zipSlip() { ArrayByteSource zipFile = load("zip-slip.zip"); assertThatExceptionOfType(UncheckedIOException.class) .isThrownBy(() -> ZipUtils.unzipPathNameInMemory(zipFile, "test/alpha/Alpha.txt")); }