Class CopyNP

java.lang.Object
  |
  +--CopyNP

public class CopyNP
extends java.lang.Object

Kopiert eine Datei, siehe Methode main(). Dient als Demo zur Umdefinition einer von unten kommenden Ausnahme in eine Ausnahme der eigenen Abstraktionsebene, ohne die Diagnoseinformationen der verursachenden Ausnahme zu unterdruecken. Hier wird in copy() jede IOException umdefiniert nach CopyFailure. Da CopyFailure Failure beerbt und die verursachende Ausnahme ueber seinen Konstruktor an Failure weitergibt, kann bei Nichtbehandlung von CopyFailure durch den Aufrufer main() mittels printStackTrace() die gesamte Diagnoseinfo sowohl der verursachenden IOException als auch des abstrahierten Kopierfehlers gemeldet werden. Ausserdem hat CopyFailure zwei Parameter:
{inFileName}=Name der Eingabedatei, {outFileName}=Name der Ausgabedatei Beispieldialog:


C:\>java -Djava.compiler= CopyNP eingabe ausgabe
The file "eingabe" could not be copied to "ausgabe"
CAUSE: java.io.FileNotFoundException: eingabe (Das System kann die angegebene Datei nicht finden)
-----Stack trace follows-----
java.io.FileNotFoundException: eingabe (Das System kann die angegebene Datei nic
ht finden)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.(FileInputStream.java:68)
at CopyNP.copy(CopyNP.java:80)
WAS CAUSING:
CopyNP$CopyFailure: {inFileName}=eingabe  {outFileName}=ausgabe
at CopyNP.copy(CopyNP.java:93)
at CopyNP.main(CopyNP.java:49)
at ...
C:\>


Inner Class Summary
static interface CopyNP.CopyFailure
           
 
Constructor Summary
CopyNP()
           
 
Method Summary
static void copy(java.lang.String i_inFileName, java.lang.String i_outFileName)
          Effect: Copies the file i_inFileName in binary mode to file i_outFileName.
static void main(java.lang.String[] i_args)
          Effect: Copies the file i_args[0] in binary mode to file i_args[1].
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CopyNP

public CopyNP()
Method Detail

main

public static void main(java.lang.String[] i_args)
                 throws CopyNP.CopyFailure
Effect: Copies the file i_args[0] in binary mode to file i_args[1].

copy

public static void copy(java.lang.String i_inFileName,
                        java.lang.String i_outFileName)
                 throws CopyNP.CopyFailure
Effect: Copies the file i_inFileName in binary mode to file i_outFileName.