org.zeroturnaround.javarebel.integration.util.IoUtil Maven / Gradle / Ivy
The newest version!
package org.zeroturnaround.javarebel.integration.util;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
/**
* I/O helper methods.
*
* @author Rein Raudjärv
*/
public class IoUtil {
private static final int BUFFER_SIZE = 4096;
public static byte[] getBytesAndClose(InputStream in) throws IOException {
if (in == null)
return null;
ByteArrayOutputStream out = new ByteArrayOutputStream();
copy(in, out);
return out.toByteArray();
}
public static void write(byte[] bytes, OutputStream out) throws IOException {
copy(new ByteArrayInputStream(bytes), out);
}
private static void copy(InputStream in, OutputStream out) throws IOException {
byte[] buffer = new byte[BUFFER_SIZE];
int read;
while ((read = in.read(buffer)) != -1) {
out.write(buffer, 0, read);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy