multex.demo
Class File

java.lang.Object
  |
  +--multex.demo.File

public class File
extends java.lang.Object

Copies or moves a file, see methods main() and _usageExit() This program serves as a demonstration for the redefinition of an exception coming from a lower tier into a Failure-exception of the own abstraction level without suppressing the diagnostic information of the causing exception. Here the method copy() redefines each IOException into CopyFailure. CopyFailure extends Failure and passes the causing exception via the constructor to Failure. So it is possible in main() catching any Exception to report the complete diagnostic information both of the causing IOException and of the abstracted CopyFailure. Additionally CopyFailure has two parameters:

{0}=Name of the input file, {1}=Name of the output file

Example Dialog with JRE 1.4:

  C:\>java multex.demo.File -c eingabe ausgabe
  File 'input' could not be copied to 'output'
  CAUSE: java.io.FileNotFoundException: input (The system can't find the indicated file)
  -----Stack trace follows-----
  java.io.FileNotFoundException: input (The system can't find the indicated file)
          at java.io.FileInputStream.open(Native Method)
          at java.io.FileInputStream.(FileInputStream.java:68)
          at File.copy(File.java:140)
  WAS CAUSING:
  multex.demo.File$CopyFailure: File ''{0}'' could not be copied to ''{1}''
      {0} = 'input'
      {1} = 'output'
          at File.copy(File.java:154)
          at File.main(File.java:83)
          at ...
  C:\>
 

The shorter way to capture low level diagnostic information is used in method move(inFileName, outFileName).

See Also:
move(String, String)

Nested Class Summary
static class File.CopyFailure
          Indicates failure of a file copy operation.
static class File.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 or moves file i_args[1] in binary mode to file i_args[2].
static void move(java.lang.String i_inFileName, java.lang.String i_outFileName)
          Effect: Moves the file i_inFileName to file i_outFileName.
 
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 or moves file i_args[1] in binary mode to file i_args[2].


copy

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

File.CopyFailure

move

public static void move(java.lang.String i_inFileName,
                        java.lang.String i_outFileName)
                 throws Failure
Effect: Moves the file i_inFileName to file i_outFileName. This method firstly copies the input file in binary mode and then deletes it.

Throws:
Failure - if its is not possible to move file i_inFileName to file i_outFileName; This way of directly throwing a multex.Failure exception is less writing; You can nevertheless provide an individual message text with parameterization; Internationalization is not possible this way.
See Also:
File.CopyFailure