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

net.yapbam.data.xml.task.PipeTask Maven / Gradle / Ivy

There is a newer version: 1.9.1
Show newest version
package net.yapbam.data.xml.task;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.concurrent.Callable;

import net.yapbam.util.StreamUtils;

/** A task that reads the content of an input stream and outputs it to an output stream.
 */
public class PipeTask implements Callable {
	private InputStream in;
	private OutputStream out;

	/** Constructor. 
	 * @param in The input stream (will be closed by the task)
	 * @param out The output stream (will remain opened)
	 */
	public PipeTask (InputStream in, OutputStream out) {
		this.in = in;
		this.out = out;
	}

	@Override
	public Void call() throws IOException {
		try {
			byte[] buffer = new byte[FilterTask.BUFFER_SIZE];
			StreamUtils.copy(in, out, buffer);
			return null;
		} finally {
			in.close();
		}
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy