Cyberduck Mountain Duck CLI

Changeset 20573


Ignore:
Timestamp:
May 20, 2016 1:11:10 PM (2 years ago)
Author:
dkocher
Message:

Fix #9512. Fix #9552.

Location:
shelves/05.2016/core/src/main/java/ch/cyberduck/core
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • shelves/05.2016/core/src/main/java/ch/cyberduck/core/io/StreamCopier.java

    r19106 r20573  
    1818 */
    1919
     20import ch.cyberduck.core.BytecountStreamListener;
     21import ch.cyberduck.core.DefaultIOExceptionMappingService;
     22import ch.cyberduck.core.exception.BackgroundException;
    2023import ch.cyberduck.core.exception.ConnectionCanceledException;
    2124import ch.cyberduck.core.preferences.PreferencesFactory;
     
    2730import java.io.OutputStream;
    2831
    29 /**
    30  * @version $Id$
    31  */
    3232public final class StreamCopier {
    3333    private static final Logger log = Logger.getLogger(StreamCopier.class);
     
    3737    private StreamProgress progress;
    3838
    39     private StreamListener listener
    40             = new DisabledStreamListener();
     39    private BytecountStreamListener listener
     40            = new BytecountStreamListener(new DisabledStreamListener());
    4141
    4242    /**
     
    5050    private Long limit = -1L;
    5151
    52     private boolean keepFlushing
    53             = PreferencesFactory.get().getBoolean("connection.flush");
    54 
    5552    public StreamCopier(final StreamCancelation cancel, final StreamProgress progress) {
    5653        this.cancel = cancel;
    5754        this.progress = progress;
    58     }
    59 
    60     public StreamCopier withFlushing(boolean keepFlushing) {
    61         this.keepFlushing = keepFlushing;
    62         return this;
    6355    }
    6456
     
    6961
    7062    public StreamCopier withListener(final StreamListener listener) {
    71         this.listener = listener;
     63        this.listener = new BytecountStreamListener(listener);
    7264        return this;
    7365    }
     
    9385     * @param out The stream to write to
    9486     */
    95     public void transfer(final InputStream in, final OutputStream out)
    96             throws IOException, ConnectionCanceledException {
    97         if(offset > 0) {
    98             skip(in, offset);
    99         }
     87    public void transfer(final InputStream in, final OutputStream out) throws BackgroundException {
    10088        try {
     89            if(offset > 0) {
     90                skip(in, offset);
     91            }
    10192            final byte[] buffer = new byte[chunksize];
    10293            long total = 0;
     
    118109                    listener.recv(read);
    119110                    out.write(buffer, 0, read);
    120                     if(keepFlushing) {
    121                         out.flush();
    122                     }
    123111                    progress.progress(read);
    124112                    listener.sent(read);
     
    137125            }
    138126        }
     127        catch(IOException e) {
     128            // Discard sent bytes if there is an error reply.
     129            final long sent = listener.getSent();
     130            progress.progress(-sent);
     131            listener.sent(-sent);
     132            final long recv = listener.getRecv();
     133            listener.recv(-recv);
     134            throw new DefaultIOExceptionMappingService().map(e);
     135        }
    139136        finally {
    140             if(!keepFlushing) {
    141                 out.flush();
    142             }
     137            final StreamCloser c = new DefaultStreamCloser();
     138            c.close(in);
     139            c.close(out);
    143140        }
    144141        if(cancel.isCanceled()) {
  • shelves/05.2016/core/src/main/java/ch/cyberduck/core/preferences/Preferences.java

    r20547 r20573  
    950950        defaults.put("connection.buffer", String.valueOf(8192));
    951951        /**
    952          * Always flush output stream after writing
    953          */
    954         defaults.put("connection.flush", String.valueOf(false));
    955         /**
    956952         * SO_SNDBUF
    957953         */
Note: See TracChangeset for help on using the changeset viewer.
swiss made software