org.securegraph.util.StreamUtils Maven / Gradle / Ivy
The newest version!
package org.securegraph.util;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
public class StreamUtils {
private static final int DEFAULT_BUFFER_SIZE = 1024 * 4;
public static long copy(InputStream input, OutputStream output) throws IOException {
byte[] buffer = new byte[DEFAULT_BUFFER_SIZE];
long count = 0;
int n;
while (-1 != (n = input.read(buffer))) {
output.write(buffer, 0, n);
count += n;
}
return count;
}
public static byte[] toBytes(InputStream in) throws IOException {
ByteArrayOutputStream out = new ByteArrayOutputStream();
copy(in, out);
return out.toByteArray();
}
public static String toString(InputStream in) throws IOException {
return new String(toBytes(in));
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy