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 * https://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 /** 032 * The total number of bytes confirmed to have been transferred by a failed copy operation. 033 */ 034 private final long totalBytesTransferred; 035 036 /** 037 * Creates a new CopyStreamException instance. 038 * 039 * @param message A message describing the error. 040 * @param bytesTransferred The total number of bytes transferred before an exception was thrown in a copy operation. 041 * @param exception The IOException thrown during a copy operation. 042 */ 043 public CopyStreamException(final String message, final long bytesTransferred, final IOException exception) { 044 super(message, exception); 045 totalBytesTransferred = bytesTransferred; 046 } 047 048 /** 049 * Gets the IOException responsible for the failure of a copy operation. 050 * 051 * @return The IOException responsible for the failure of a copy operation. 052 */ 053 public IOException getIOException() { 054 return (IOException) getCause(); // cast is OK because it was initialized with an IOException 055 } 056 057 /** 058 * Gets the total number of bytes confirmed to have been transferred by a failed copy operation. 059 * 060 * @return The total number of bytes confirmed to have been transferred by a failed copy operation. 061 */ 062 public long getTotalBytesTransferred() { 063 return totalBytesTransferred; 064 } 065}