    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
    018package org.apache.commons.net.io;
    019
    020import java.io.IOException;
    021
    022/**
    023 * The CopyStreamException class is thrown by the org.apache.commons.io.Util copyStream() methods. It stores the number of bytes confirmed to have been
    024 * transferred before an I/O error as well as the IOException responsible for the failure of a copy operation.
    025 *
    026 * @see Util
    027 */
    028public class CopyStreamException extends IOException {
    029    private static final long serialVersionUID = -2602899129433221532L;
    030
    031    private final long totalBytesTransferred;
    032
    033    /**
    034     * Creates a new CopyStreamException instance.
    035     *
    036     * @param message          A message describing the error.
    037     * @param bytesTransferred The total number of bytes transferred before an exception was thrown in a copy operation.
    038     * @param exception        The IOException thrown during a copy operation.
    039     */
    040    public CopyStreamException(final String message, final long bytesTransferred, final IOException exception) {
    041        super(message);
    042        initCause(exception); // merge this into super() call once we need 1.6+
    043        totalBytesTransferred = bytesTransferred;
    044    }
    045
    046    /**
    047     * Returns the IOException responsible for the failure of a copy operation.
    048     *
    049     * @return The IOException responsible for the failure of a copy operation.
    050     */
    051    public IOException getIOException() {
    052        return (IOException) getCause(); // cast is OK because it was initialized with an IOException
    053    }
    054
    055    /**
    056     * Returns the total number of bytes confirmed to have been transferred by a failed copy operation.
    057     *
    058     * @return The total number of bytes confirmed to have been transferred by a failed copy operation.
    059     */
    060    public long getTotalBytesTransferred() {
    061        return totalBytesTransferred;
    062    }
    063}