Example usage for org.apache.commons.net.io CopyStreamException CopyStreamException

List of usage examples for org.apache.commons.net.io CopyStreamException CopyStreamException

Introduction

In this page you can find the example usage for org.apache.commons.net.io CopyStreamException CopyStreamException.

Prototype

public CopyStreamException(String message, long bytesTransferred, IOException exception) 

Source Link

Document

Creates a new CopyStreamException instance.

Usage

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);
    }
}