@Override public InputStream getData(final String name) throws IOException { try (ZipFile zip = getRoot()) { final ZipEntry entry = zip.getEntry(name.replace('.', '/') + ".class"); if (entry == null) { return null; } return StreamUtil.copyStream(zip.getInputStream(entry)); } }
public static InputStream copyStream(final InputStream in) throws IOException { final byte[] bs = streamToByteArray(in); return new ByteArrayInputStream(bs); }
public static byte[] streamToByteArray(final InputStream in) throws IOException { try (ByteArrayOutputStream result = new ByteArrayOutputStream()) { copy(in, result); return result.toByteArray(); } }
@Test public void shouldCopyContentsOfOneInputStreamToAnother() throws IOException { final byte[] expected = createByteArray(); final InputStream actualStream = StreamUtil .copyStream(new ByteArrayInputStream(createByteArray())); final byte[] actualContents = StreamUtil.streamToByteArray(actualStream); assertArrayEquals(expected, actualContents); }
private static byte[] getOriginalBytes(final Object classPath, final String name) throws IOException { try (InputStream is = returnNormalBytes(classPath,name)) { final byte[] bs = StreamUtil.streamToByteArray(is); return bs; } }
@Override public InputStream getData(final String name) throws IOException { try (ZipFile zip = getRoot()) { final ZipEntry entry = zip.getEntry(name.replace('.', '/') + ".class"); if (entry == null) { return null; } return StreamUtil.copyStream(zip.getInputStream(entry)); } }
public static byte[] streamToByteArray(final InputStream in) throws IOException { try (ByteArrayOutputStream result = new ByteArrayOutputStream()) { copy(in, result); return result.toByteArray(); } }
public byte[] getClassData(final String classname) throws IOException { try (InputStream is = this.root.getData(classname)) { if (is != null) { return StreamUtil.streamToByteArray(is); } else { return null; } } }
private String streamToString(final InputStream is) throws IOException { return new String(StreamUtil.streamToByteArray(is)); }
@Test public void shouldCopyStreamsToByteArrays() throws IOException { final byte[] expected = createByteArray(); final ByteArrayInputStream bis = new ByteArrayInputStream(expected); final byte[] actual = StreamUtil.streamToByteArray(bis); assertArrayEquals(expected, actual); }
protected void printRaw(final Class<?> clazz) throws IOException { final OtherClassLoaderClassPathRoot r = new OtherClassLoaderClassPathRoot( IsolationUtils.getContextClassLoader()); printClass(StreamUtil.streamToByteArray(r.getData(clazz.getName()))); }
public static InputStream copyStream(final InputStream in) throws IOException { final byte[] bs = streamToByteArray(in); return new ByteArrayInputStream(bs); }
public byte[] getClassData(final String classname) throws IOException { try (InputStream is = this.root.getData(classname)) { if (is != null) { return StreamUtil.streamToByteArray(is); } else { return null; } } }
private static byte[] getOriginalBytes(final Object classPath, final String name) throws IOException { try (InputStream is = returnNormalBytes(classPath,name)) { final byte[] bs = StreamUtil.streamToByteArray(is); return bs; } }