    001    /*
    002     * Licensed to the Apache Software Foundation (ASF) under one or more
    003     * contributor license agreements.  See the NOTICE file distributed with
    004     * this work for additional information regarding copyright ownership.
    005     * The ASF licenses this file to You under the Apache License, Version 2.0
    006     * (the "License"); you may not use this file except in compliance with
    007     * the License.  You may obtain a copy of the License at
    008     *
    009     *      http://www.apache.org/licenses/LICENSE-2.0
    010     *
    011     * Unless required by applicable law or agreed to in writing, software
    012     * distributed under the License is distributed on an "AS IS" BASIS,
    013     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    014     * See the License for the specific language governing permissions and
    015     * limitations under the License.
    016     */
    017
    018    package org.apache.commons.net.io;
    019
    020    import java.io.IOException;
    021
    022    /**
    023     * The CopyStreamException class is thrown by the org.apache.commons.io.Util
    024     * copyStream() methods.  It stores the number of bytes confirmed to
    025     * have been transferred before an I/O error as well as the IOException
    026     * responsible for the failure of a copy operation.
    027     * @see Util
    028     * @version $Id: CopyStreamException.java 1088720 2011-04-04 18:52:00Z dfs $
    029     */
    030    public class CopyStreamException extends IOException
    031    {
    032        private static final long serialVersionUID = -2602899129433221532L;
    033
    034        private final long totalBytesTransferred;
    035        private final IOException ioException;
    036
    037        /**
    038         * Creates a new CopyStreamException instance.
    039         * @param message  A message describing the error.
    040         * @param bytesTransferred  The total number of bytes transferred before
    041         *        an exception was thrown in a copy operation.
    042         * @param exception  The IOException thrown during a copy operation.
    043         */
    044        public CopyStreamException(String message,
    045                                   long bytesTransferred,
    046                                   IOException exception)
    047        {
    048            super(message);
    049            totalBytesTransferred = bytesTransferred;
    050            ioException = exception;
    051        }
    052
    053        /**
    054         * Returns the total number of bytes confirmed to have
    055         * been transferred by a failed copy operation.
    056         * @return The total number of bytes confirmed to have
    057         * been transferred by a failed copy operation.
    058         */
    059        public long getTotalBytesTransferred()
    060        {
    061            return totalBytesTransferred;
    062        }
    063
    064        /**
    065         * Returns the IOException responsible for the failure of a copy operation.
    066         * @return The IOException responsible for the failure of a copy operation.
    067         */
    068        public IOException getIOException()
    069        {
    070            return ioException;
    071        }
    072    }