All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.xqbase.util.Streams Maven / Gradle / Ivy

There is a newer version: 0.2.18
Show newest version
package com.xqbase.util;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

/** Copy from an {@link InputStream} to an {@link OutputStream} */
public class Streams {
	private static final int BUFFER_SIZE = 2048;

	/**
	 * Copy from an {@link InputStream} to an {@link OutputStream}
	 *
	 * @param flush true to flush OutputStream during copy
	 */
	public static void copy(InputStream in,
			OutputStream out, boolean flush) throws IOException {
		byte[] buffer = new byte[BUFFER_SIZE];
		int bytesRead;
		while ((bytesRead = in.read(buffer)) > 0) {
			out.write(buffer, 0, bytesRead);
			if (flush) {
				out.flush();
			}
		}
	}

	/**
	 * Copy from an {@link InputStream} to an {@link OutputStream}
	 * without flushing OutputStream during copy
	 */
	public static void copy(InputStream in,
			OutputStream out) throws IOException {
		copy(in, out, false);
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy