/** * Get the contents of a <code>Reader</code> as a <code>byte[]</code>. */ public static byte[] toByteArray( final Reader input ) throws IOException { return toByteArray( input, DEFAULT_BUFFER_SIZE ); }
/** * Get the contents of a <code>String</code> as a <code>byte[]</code>. */ public static byte[] toByteArray( final String input ) throws IOException { return toByteArray( input, DEFAULT_BUFFER_SIZE ); }
/** * Get the contents of an <code>InputStream</code> as a <code>byte[]</code>. */ public static byte[] toByteArray( final InputStream input ) throws IOException { return toByteArray( input, DEFAULT_BUFFER_SIZE ); }
/** * Get the contents of a <code>String</code> as a <code>byte[]</code>. */ public static byte[] toByteArray( final String input ) throws IOException { return toByteArray( input, DEFAULT_BUFFER_SIZE ); }
/** * Get the contents of a <code>Reader</code> as a <code>byte[]</code>. */ public static byte[] toByteArray( final Reader input ) throws IOException { return toByteArray( input, DEFAULT_BUFFER_SIZE ); }
/** * Get the contents of an <code>InputStream</code> as a <code>byte[]</code>. */ public static byte[] toByteArray( final InputStream input ) throws IOException { return toByteArray( input, DEFAULT_BUFFER_SIZE ); }
@Override public void run() { InputStream urlis = null; try { urlis = url.openStream(); byte[] arr = IOUtil.toByteArray(urlis); synchronized (AuxPropsImpl.this) { //#174401 ByteArrayInputStream bais = new ByteArrayInputStream(arr); copyToCacheDir(bais); recheck = true; } } catch (IOException ex) { ex.printStackTrace(); } finally { IOUtil.close(urlis); } } });
private void addMavenCapletClasses(final JarOutputStream jar) throws IOException { if (resolveApp || resolveCompileDep || resolveRuntimeDep || resolveProvidedDep || resolveSystemDep || resolveTestDep) { // get capsule maven classes final JarInputStream capsuleJarInputStream = new JarInputStream(new FileInputStream(resolveCapsuleMaven())); JarEntry entry; while ((entry = capsuleJarInputStream.getNextJarEntry()) != null) { if (entry.getName().contains("capsule") || entry.getName().equals(DEFAULT_CAPSULE_MAVEN_CLASS)) { addToJar(entry.getName(), new ByteArrayInputStream(IOUtil.toByteArray(capsuleJarInputStream)), jar); } } info("\t[Maven Caplet] Embedded Maven Caplet classes v" + capsuleMavenVersion + " (so capsule can resolve at launch)"); } }
private void addCapsuleClass(final JarOutputStream jar) throws IOException { final JarInputStream capsuleJarInputStream = new JarInputStream(new FileInputStream(resolveCapsule())); JarEntry entry; while ((entry = capsuleJarInputStream.getNextJarEntry()) != null) // look for Capsule.class if (entry.getName().equals(DEFAULT_CAPSULE_CLASS)) addToJar(DEFAULT_CAPSULE_CLASS, new ByteArrayInputStream(IOUtil.toByteArray(capsuleJarInputStream)), jar); }
@Override public ArtifactDelta getDelta(InputStream baseline, InputStream reactor, MojoExecution mojo) throws IOException { byte[] baselineBytes = IOUtil.toByteArray(baseline); byte[] reactorBytes = IOUtil.toByteArray(reactor); String baselineDisassemble = null; String reactorDisassemble = null; boolean equal; try { baselineDisassemble = disassemble(baselineBytes); reactorDisassemble = disassemble(reactorBytes); equal = baselineDisassemble.equals(reactorDisassemble); } catch (RuntimeException e) { // asm could not disassemble one of the classes, fallback to byte-to-byte comparison equal = Arrays.equals(baselineBytes, reactorBytes); } return !equal ? new SimpleArtifactDelta("different", baselineDisassemble, reactorDisassemble) : null; }
protected void copyIfChanged(InputStream input, Path output) throws IOException { InputStream source = input; if (Files.exists(output)) { byte[] fileContent = IOUtil.toByteArray(input); ByteArrayInputStream bufferedInput = new ByteArrayInputStream(fileContent); // compare content first try (InputStream outputContent = Files.newInputStream(output)) { if (IOUtil.contentEquals(bufferedInput, outputContent)) { return; } } // rewind input and use it bufferedInput.reset(); source = bufferedInput; } Files.copy(source, output, StandardCopyOption.REPLACE_EXISTING); }
public String getResponseBody( final ClientResponse response ) { try { final byte[] body = IOUtil.toByteArray( response.getEntityInputStream() ); response.setEntityInputStream( new ByteArrayInputStream( body ) ); return IOUtil.toString( body, "UTF-8" ); } catch ( IOException e ) { throw new IllegalStateException( "Jersey unexpectedly refused to rewind buffered entity." ); } }
byte[] content = IOUtil.toByteArray( in );
static synchronized AggregationHelper getAggregationHelper() throws RBeanFactoryException, IOException { if (aggregationHelper == null) { ClassLoader targetClassLoader = MavenSession.class.getClassLoader(); synchronized (targetClassLoader) { try { targetClassLoader.loadClass(AggregationHelper.IMPL_CLASS); } catch (ClassNotFoundException ex) { ClassLoaderRBean targetClassLoaderRBean = new RBeanFactory(ClassLoaderRBean.class).createRBean(ClassLoaderRBean.class, targetClassLoader); ClassLoader sourceClassLoader = AggregationHelperFactory.class.getClassLoader(); for (String className : classesToInject) { try (InputStream in = sourceClassLoader.getResourceAsStream(className.replace('.', '/') + ".class")) { byte[] data = IOUtil.toByteArray(in); targetClassLoaderRBean.defineClass(className, data, 0, data.length); } } } } aggregationHelper = new RBeanFactory(targetClassLoader, AggregationHelper.class).createRBean(AggregationHelper.class); } return aggregationHelper; } }