Class Copy

java.lang.Object
  |
  +--Copy

public class Copy
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 unterdrücken. 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= Copy 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 nicht finden)
          at java.io.FileInputStream.open(Native Method)
          at java.io.FileInputStream.(FileInputStream.java:68)
          at Copy.copy(Copy.java:80)
  WAS CAUSING:
  Copy$CopyFailure: {inFileName}=eingabe  {outFileName}=ausgabe
          at Copy.copy(Copy.java:93)
          at Copy.main(Copy.java:49)
          at ...
  C:\>


Inner Class Summary
static interface Copy.CopyFailure
          Indicates failure of a file copy operation
static interface Copy.StartedExc
          Indicates, that this test driver has been started.
 
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
 

Method Detail

main

public static void main(java.lang.String[] i_args)
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 Copy.CopyFailure
Effect: Copies the file i_inFileName in binary mode to file i_outFileName.