Java Utililty Methods InputStream to OutputStream

List of utility methods to do InputStream to OutputStream

Description

The list of methods to do InputStream to OutputStream are organized into topic(s).

Method

voidcopyStream(@Nonnull InputStream in, @Nonnull OutputStream out)
copy Stream
byte[] buf = new byte[8192];
int len;
while ((len = in.read(buf)) >= 0)
    out.write(buf, 0, len);
voidcopyStream(ByteArrayOutputStream source, ByteArrayOutputStream target)
Copies source stream to target.
ByteArrayOutputStream memContentStream = source;
if (memContentStream != null) {
    memContentStream.writeTo(target);
    memContentStream.flush();
} else {
    int c;
    ByteArrayInputStream inStream = new ByteArrayInputStream(source.toByteArray());
    while ((c = inStream.read()) != -1) {
...
voidcopyStream(final InputStream in, final OutputStream out)
Copies the contents of a stream to another.
int bytesRead;
byte[] b = new byte[10000];
while ((bytesRead = in.read(b)) != -1) {
    out.write(b, 0, bytesRead);
out.flush();
voidcopyStream(final InputStream in, final OutputStream out)
Copy stream.
final byte[] bytes = new byte[8192];
int cnt;
while ((cnt = in.read(bytes)) != -1) {
    out.write(bytes, 0, cnt);
voidcopyStream(final InputStream in, final OutputStream out, final int bufferSize)
Copies the contents of an java.io.InputStream to an java.io.OutputStream , using buffer size provided.
final byte[] buffer = new byte[bufferSize];
int byteRead = 0;
while ((byteRead = in.read(buffer)) >= 0) {
    out.write(buffer, 0, byteRead);
intcopyStream(final InputStream in, final OutputStream out, int iMax)
copy Stream
if (iMax < 0)
    iMax = Integer.MAX_VALUE;
final byte[] buf = new byte[8192];
int byteRead = 0;
int byteTotal = 0;
while ((byteRead = in.read(buf, 0, Math.min(buf.length, iMax - byteTotal))) > 0) {
    out.write(buf, 0, byteRead);
    byteTotal += byteRead;
...
voidcopyStream(final InputStream input, final OutputStream output, long count)
Copies count bytes from input to output.
final byte[] buffer = new byte[64 * 1024];
if (count < 0) {
    int read;
    while ((read = input.read(buffer)) != -1) {
        output.write(buffer, 0, read);
} else {
    while (count > 0) {
...
longcopyStream(final InputStream inputStream, final OutputStream out)
copy Stream
return copyStream(inputStream, out, 10240);
voidcopyStream(final InputStream inputStream, final OutputStream outputStream)
copy Stream
final byte[] buffer = new byte[1024 * 4];
int c;
while (-1 != (c = inputStream.read(buffer))) {
    outputStream.write(buffer, 0, c);
intcopyStream(final InputStream inputStream, final OutputStream outputStream)
copy Stream
if (inputStream == null) {
    return 0;
int result = 0;
final byte[] buf = new byte[DEFAULT_BUFFER_SIZE];
for (;;) {
    final int numRead = inputStream.read(buf);
    if (numRead == -1) {
...