List of usage examples for org.apache.commons.net.io CopyStreamException CopyStreamException
public CopyStreamException(String message, long bytesTransferred, IOException exception)
From source file:net.seedboxer.camel.component.file.remote.ftp2.Ftp2Operations.java
private void copyStream(InputStream source, OutputStream dest, int bufferSize, long streamSize, CopyStreamListener listener) throws CopyStreamException { int bytes;// w w w. j av a2s. co m long total; byte[] buffer; buffer = new byte[bufferSize]; total = 0; try { while ((bytes = source.read(buffer)) != -1) { if (bytes == 0) { bytes = source.read(); if (bytes < 0) { break; } dest.write(bytes); dest.flush(); ++total; if (listener != null) { listener.bytesTransferred(total, 1, streamSize); } continue; } dest.write(buffer, 0, bytes); dest.flush(); total += bytes; if (listener != null) { listener.bytesTransferred(total, bytes, streamSize); } } } catch (IOException e) { throw new CopyStreamException("IOException caught while copying.", total, e); } }
From source file:net.seedboxer.common.ftp.FtpUploaderCommons.java
private void copyStream(InputStream source, OutputStream dest, int bufferSize, long streamSize, CopyStreamListener listener) throws CopyStreamException { int bytes;/*ww w .j a v a2s.c o m*/ long total; byte[] buffer; buffer = new byte[bufferSize]; total = 0; try { while ((bytes = source.read(buffer)) != -1 || !aborted.get()) { if (bytes == 0) { bytes = source.read(); if (bytes < 0) { break; } dest.write(bytes); dest.flush(); ++total; if (listener != null) { listener.bytesTransferred(total, 1, streamSize); } continue; } dest.write(buffer, 0, bytes); dest.flush(); total += bytes; if (listener != null) { listener.bytesTransferred(total, bytes, streamSize); } } } catch (IOException e) { throw new CopyStreamException("IOException caught while copying.", total, e); } }