TrueZIP Kernel 7.0-rc2

de.schlichtherle.truezip.io
Class SequentialIOException

java.lang.Object
  extended by java.lang.Throwable
      extended by java.lang.Exception
          extended by java.io.IOException
              extended by de.schlichtherle.truezip.io.SequentialIOException
All Implemented Interfaces:
Serializable, Cloneable
Direct Known Subclasses:
FsSyncException

public class SequentialIOException
extends IOException
implements Cloneable

Represents a chain of subsequently occured IOExceptions which have not caused each other.

This class supports chaining I/O exceptions for reasons other than causes (which is a functionality already provided by J2SE 1.4 and later). A chainable I/O exception can be used to implement an algorithm which must be able to continue with some work although one or more I/O exceptions have occured.

For example, when looping through a list of files, an algorithm might encounter an I/O exception when processing a file element in the list. However, it may still be required to process the remaining files in the list before actually throwing the corresponding I/O exception. Hence, whenever this algorithm encounters an I/O exception, it would catch the I/O exception, create a chainable I/O exception for it and continue processing the remainder of the list. Finally, at the end of the algorithm, if any I/O exceptions have occured, the chainable I/O exception would get sorted according to priority (see getPriority() and sortPriority()) and finally thrown. This would allow a client application to filter the I/O exceptions by priority with a simple try-catch statement, ensuring that no other exception of higher priority is in the catched exception chain.

This class is thread-safe.

Author:
Christian Schlichtherle
See Also:
Serialized Form

Field Summary
private  int index
           
(package private) static Comparator<SequentialIOException> INDEX_COMP
          Compares two chainable I/O exceptions in descending order of their appearance.
(package private)  int maxIndex
           
private static int maxPrintExceptions
           
private  SequentialIOException predecessor
          The tail of this exception chain.
private  int priority
           
(package private) static Comparator<SequentialIOException> PRIORITY_COMP
          Compares two chainable I/O exceptions in descending order of their priority.
private static long serialVersionUID
           
 
Constructor Summary
SequentialIOException()
           
SequentialIOException(int priority)
           
SequentialIOException(String message)
           
SequentialIOException(String message, int priority)
           
SequentialIOException(String message, Throwable cause)
           
SequentialIOException(String message, Throwable cause, int priority)
          Constructs a new chainable I/O exception with the given message, cause and priority.
SequentialIOException(Throwable cause)
           
SequentialIOException(Throwable cause, int priority)
           
 
Method Summary
 SequentialIOException clone()
          Returns a shallow clone of this exception.
static int getMaxPrintExceptions()
           
private  int getNumExceptions()
           
 SequentialIOException getPredecessor()
          Returns the exception chain represented by the predecessing exception, or null if no predecessing exception exists or this property hasn't been initialized yet.
 int getPriority()
          Returns the priority of this exception.
 SequentialIOException initCause(Throwable cause)
           
 SequentialIOException initPredecessor(SequentialIOException predecessor)
          Initializes the predecessor of this chainable exception to the given object.
private  SequentialIOException insert(SequentialIOException element, Comparator<SequentialIOException> cmp)
           
 void printStackTrace(PrintStream s)
          Prints up to getMaxPrintExceptions() exceptions in this chain to the provided PrintStream.
 void printStackTrace(PrintStream s, int maxExceptions)
          Prints up to maxExceptions() exceptions in this chain to the provided PrintStream.
 void printStackTrace(PrintWriter s)
          Prints up to getMaxPrintExceptions() exceptions in this chain to the provided PrintStream.
 void printStackTrace(PrintWriter s, int maxExceptions)
          Prints up to maxExceptions() exceptions in this chain to the provided PrintStream.
static void setMaxPrintExceptions(int maxPrintExcepions)
           
private  void setPredecessor(SequentialIOException predecessor)
           
private  SequentialIOException sort(Comparator<SequentialIOException> cmp)
           
 SequentialIOException sortAppearance()
          Sorts the elements of this exception chain in descending order of their appearance.
 SequentialIOException sortPriority()
          Sorts the elements of this exception chain in descending order of their priority.
 
Methods inherited from class java.lang.Throwable
fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, printStackTrace, setStackTrace, toString
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

serialVersionUID

private static final long serialVersionUID
See Also:
Constant Field Values

maxPrintExceptions

private static int maxPrintExceptions

PRIORITY_COMP

static final Comparator<SequentialIOException> PRIORITY_COMP
Compares two chainable I/O exceptions in descending order of their priority. If the priority is equal, the elements are compared in descending order of their appearance.


INDEX_COMP

static final Comparator<SequentialIOException> INDEX_COMP
Compares two chainable I/O exceptions in descending order of their appearance.


predecessor

private SequentialIOException predecessor
The tail of this exception chain. Maybe this if the predecessor hasn't been initPredecessor(SequentialIOException) initialized yet or null if there are no more exceptions in this chain.


priority

private final int priority

index

private int index

maxIndex

int maxIndex
Constructor Detail

SequentialIOException

public SequentialIOException()

SequentialIOException

public SequentialIOException(String message)

SequentialIOException

public SequentialIOException(Throwable cause)

SequentialIOException

public SequentialIOException(String message,
                             Throwable cause)

SequentialIOException

public SequentialIOException(int priority)

SequentialIOException

public SequentialIOException(String message,
                             int priority)

SequentialIOException

public SequentialIOException(Throwable cause,
                             int priority)

SequentialIOException

public SequentialIOException(String message,
                             Throwable cause,
                             int priority)
Constructs a new chainable I/O exception with the given message, cause and priority. The predecessor of this exception remains unknown until initiliazed by calling the method initPredecessor(SequentialIOException).

Parameters:
message - The message for this exception.
cause - The cause exception. A null value is permitted, and indicates that the cause for this exception is nonexistent.
priority - The priority of this exception to be used for priority sorting.
Method Detail

clone

public SequentialIOException clone()
Returns a shallow clone of this exception.

Overrides:
clone in class Object

initCause

public SequentialIOException initCause(Throwable cause)
Overrides:
initCause in class Throwable

initPredecessor

public final SequentialIOException initPredecessor(SequentialIOException predecessor)
Initializes the predecessor of this chainable exception to the given object. This method can be called at most once unless the given predecessor is the same as the previously initialized predecessor.

Parameters:
predecessor - An exception that happened before and is not the cause for this exception! Must be null to indicate that a predecessor does not exist.
Returns:
A reference to this object.
Throws:
IllegalStateException - If the predecessor has already been set.
IllegalArgumentException - If the given predecessor is this instance or has not been initialized with a predecessor itself.

setPredecessor

private void setPredecessor(SequentialIOException predecessor)

getPredecessor

public final SequentialIOException getPredecessor()
Returns the exception chain represented by the predecessing exception, or null if no predecessing exception exists or this property hasn't been initialized yet.


getPriority

public final int getPriority()
Returns the priority of this exception.


sortPriority

public SequentialIOException sortPriority()
Sorts the elements of this exception chain in descending order of their priority. If the priority of two elements is equal, they are sorted in descending order of their appearance.

Returns:
The sorted exception chain, consisting of cloned elements where required to enforce the immutability of this class. This is a non-destructive sort, i.e. elements already in order are guaranteed not to get rearranged. If and only if all elements are in order, this exception chain is returned and no elements are cloned.

sortAppearance

public SequentialIOException sortAppearance()
Sorts the elements of this exception chain in descending order of their appearance.

Returns:
The sorted exception chain, consisting of cloned elements where required to enforce the immutability of this class. This is a non-destructive sort, i.e. elements already in order are guaranteed not to get rearranged. If and only if all elements are in order, this exception chain is returned and no elements are cloned.

sort

private SequentialIOException sort(Comparator<SequentialIOException> cmp)

insert

private SequentialIOException insert(SequentialIOException element,
                                     Comparator<SequentialIOException> cmp)

printStackTrace

public void printStackTrace(PrintStream s)
Prints up to getMaxPrintExceptions() exceptions in this chain to the provided PrintStream.

Exceptions are printed in ascending order of this chain. If this chain has not been sorted, this results in the exceptions being printed in order of their appearance.

If more exceptions are in this chain than are allowed to be printed, then the printed message starts with a line indicating the number of exceptions which have been omitted from the beginning of this chain. Thus, this exception is always printed as the last exception in the list.

Overrides:
printStackTrace in class Throwable

printStackTrace

public void printStackTrace(PrintStream s,
                            int maxExceptions)
Prints up to maxExceptions() exceptions in this chain to the provided PrintStream.

Exceptions are printed in ascending order of this chain. If this chain has not been sorted, this results in the exceptions being printed in order of their appearance.

If more exceptions are in this chain than are allowed to be printed, then the printed message starts with a line indicating the number of exceptions which have been omitted from the beginning of this chain. Thus, this exception is always printed as the last exception in the list.


getNumExceptions

private int getNumExceptions()

printStackTrace

public void printStackTrace(PrintWriter s)
Prints up to getMaxPrintExceptions() exceptions in this chain to the provided PrintStream.

Exceptions are printed in ascending order of this chain. If this chain has not been sorted, this results in the exceptions being printed in order of their appearance.

If more exceptions are in this chain than are allowed to be printed, then the printed message starts with a line indicating the number of exceptions which have been omitted from the beginning of this chain. Thus, this exception is always printed as the last exception in the list.

Overrides:
printStackTrace in class Throwable

printStackTrace

public void printStackTrace(PrintWriter s,
                            int maxExceptions)
Prints up to maxExceptions() exceptions in this chain to the provided PrintStream.

Exceptions are printed in ascending order of this chain. If this chain has not been sorted, this results in the exceptions being printed in order of their appearance.

If more exceptions are in this chain than are allowed to be printed, then the printed message starts with a line indicating the number of exceptions which have been omitted from the beginning of this chain. Thus, this exception is always printed as the last exception in the list.


getMaxPrintExceptions

public static int getMaxPrintExceptions()
See Also:
printStackTrace(PrintStream), printStackTrace(PrintWriter)

setMaxPrintExceptions

public static void setMaxPrintExceptions(int maxPrintExcepions)
See Also:
printStackTrace(PrintStream), printStackTrace(PrintWriter)

TrueZIP Kernel 7.0-rc2

Copyright © 2005-2011 Schlichtherle IT Services. All Rights Reserved.