### Question:
JarFileUtils { public static byte[] readEntryFromJar(JarFile jarfile, JarEntry entry) { try (final InputStream entryStream = jarfile.getInputStream(entry)) { final byte[] buffer = new byte[2048]; ByteArrayOutputStream os = new ByteArrayOutputStream(); for (int len = entryStream.read(buffer); len != -1; len = entryStream.read(buffer)) { os.write(buffer, 0, len); } return os.toByteArray(); } catch (IOException e) { throw new JarEntryReadException(entry.getName(), e); } }  static byte[] readEntryFromJar(JarFile jarfile, JarEntry entry);  }### Answer:
@Test public void testReadEntryFromJarWorks() throws Exception { Map<String, byte[]> srcEntries = new HashMap<>(); srcEntries.put("ClassAAAAAAAAAAAAA.class","ClassAAAAAAAAAAAAA.class".getBytes()); srcEntries.put("ClassBBBBBBBBBBBB.class","ClassBBBBBBBBBBBB.class".getBytes()); srcEntries.put("/CCCC","/CCCC".getBytes()); File testFile = JarUtils.createJar(temporaryFolder, "Test.jar", srcEntries); Map<String, byte[]> entriesRead = new HashMap<>(); try (JarFile jarFile = new JarFile(testFile)) { Enumeration<JarEntry> jarEntries = jarFile.entries(); while (jarEntries.hasMoreElements()) { JarEntry entry = jarEntries.nextElement(); entriesRead.put(entry.getName(), JarFileUtils.readEntryFromJar(jarFile, entry)); } } Assert.assertEquals(3, entriesRead.size()); for(Map.Entry<String, byte[]> entry: srcEntries.entrySet()){ Assert.assertTrue(entriesRead.containsKey(entry.getKey())); Assert.assertArrayEquals(entry.getValue(), entriesRead.get(entry.getKey())); } }