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