List of usage examples for org.apache.commons.net.io CopyStreamListener bytesTransferred
public void bytesTransferred(long totalBytesTransferred, int bytesTransferred, long streamSize);
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;//from w w w . j a va 2 s .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 .ja v a2 s . co 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); } }
From source file:org.openconcerto.ftp.IFtp.java
private boolean __storeFile(int command, String remote, InputStream local) throws IOException { OutputStream output;/*from w w w. j a v a 2 s . c om*/ Socket socket; if ((socket = _openDataConnection_(command, remote)) == null) return false; output = new BufferedOutputStream(socket.getOutputStream(), getBufferSize()); // __fileType is private, if we really want we could subclass setFileType() to have access // if (__fileType == ASCII_FILE_TYPE) // output = new ToNetASCIIOutputStream(output); // Treat everything else as binary for now try { final CopyStreamListener l = this.streamListeners.get(); final long size = CopyStreamEvent.UNKNOWN_STREAM_SIZE; if (l != null) { // copyStream() doesn't pass 0 l.bytesTransferred(0, 0, size); } Util.copyStream(local, output, getBufferSize(), size, l, false); } catch (IOException e) { try { socket.close(); } catch (IOException f) { } throw e; } output.close(); socket.close(); return completePendingCommand(); }