    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
    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 */
    029public class CopyStreamException extends IOException
    030{
    031    private static final long serialVersionUID = -2602899129433221532L;
    032
    033    private final long totalBytesTransferred;
    034
    035    /**
    036     * Creates a new CopyStreamException instance.
    037     * @param message  A message describing the error.
    038     * @param bytesTransferred  The total number of bytes transferred before
    039     *        an exception was thrown in a copy operation.
    040     * @param exception  The IOException thrown during a copy operation.
    041     */
    042    public CopyStreamException(String message,
    043                               long bytesTransferred,
    044                               IOException exception)
    045    {
    046        super(message);
    047        initCause(exception); // merge this into super() call once we need 1.6+
    048        totalBytesTransferred = bytesTransferred;
    049    }
    050
    051    /**
    052     * Returns the total number of bytes confirmed to have
    053     * been transferred by a failed copy operation.
    054     * @return The total number of bytes confirmed to have
    055     * been transferred by a failed copy operation.
    056     */
    057    public long getTotalBytesTransferred()
    058    {
    059        return totalBytesTransferred;
    060    }
    061
    062    /**
    063     * Returns the IOException responsible for the failure of a copy operation.
    064     * @return The IOException responsible for the failure of a copy operation.
    065     */
    066    public IOException getIOException()
    067    {
    068        return (IOException) getCause(); // cast is OK because it was initialised with an IOException
    069    }
    070}