Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.apache.commons.transaction.util
Class FileHelper

    java.lang.Object
      org.apache.commons.transaction.util.FileHelper

public final class FileHelper
extends Object

Helper methods for file manipulation. All methods are thread safe.

Version:
  $Revision$

Constructor Summary
`FileHelper()`

Method Summary
`static long` | `copy(File input, File output)` Copies one file to another using `copy(InputStream, OutputStream)`.
`static long` | `copy(File input, File output, byte[] copyBuffer)` Copies one file to another using the supplied buffer.
`static long` | `copy(InputStream in, File outputFile)` Copies an `InputStream` to a file using `copy(InputStream, OutputStream)`.
`static long` | `copy(InputStream in, OutputStream out)` Copies an `InputStream` to an `OutputStream` using a local internal buffer for performance.
`static long` | `copy(InputStream in, OutputStream out, byte[] copyBuffer)` Copies an `InputStream` to an `OutputStream` using the specified buffer.
`static void` | `copyRec(File source, File target)` Copies one directory or file to another.
`static boolean` | `createFile(String path)` Creates a file specified by a path.
`static boolean` | `deleteFile(String path)` Deletes a file specified by a path.
`static boolean` | `fileExists(String path)` Checks if a file specified by a path exits.
`static long` | `globalBufferCopy(InputStream in, OutputStream out)` Copies an `InputStream` to an `OutputStream` using a global internal buffer for performance.
`static void` | `moveRec(File source, File target)` Moves one directory or file to another.
`static void` | `removeRec(File toRemove)` Removes a file.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### FileHelper

    public FileHelper()

Method Detail

### deleteFile

    public static boolean deleteFile(String path)

  Deletes a file specified by a path.

  Parameters:
    `path` - path of file to be deleted
  Returns:
    `true` if file has been deleted, `false` otherwise

### fileExists

    public static boolean fileExists(String path)

  Checks if a file specified by a path exits.

  Parameters:
    `path` - path of file to be checked
  Returns:
    `true` if file exists, `false` otherwise

### createFile

    public static boolean createFile(String path)
                              throws IOException

  Creates a file specified by a path. All necessary directories will be created.

  Parameters:
    `path` - path of file to be created
  Returns:
    `true` if file has been created, `false` if the file already exists
  Throws:
    `IOException` - If an I/O error occurred

### removeRec

    public static void removeRec(File toRemove)

  Removes a file. If the specified file is a directory all contained files will be removed recursively as well.

  Parameters:
    `toRemove` - file to be removed

### moveRec

    public static void moveRec(File source,
                               File target)
                        throws IOException

  Moves one directory or file to another. Existing files will be replaced.

  Parameters:
    `source` - file to move from
    `target` - file to move to
  Throws:
    `IOException` - if an I/O error occurs (may result in partially done work)

### copyRec

    public static void copyRec(File source,
                               File target)
                        throws IOException

  Copies one directory or file to another. Existing files will be replaced.

  Parameters:
    `source` - directory or file to copy from
    `target` - directory or file to copy to
  Throws:
    `IOException` - if an I/O error occurs (may result in partially done work)

### copy

    public static long copy(File input,
                            File output)
                     throws IOException

  Copies one file to another using `copy(InputStream, OutputStream)`.

  Parameters:
    `input` - source file
    `output` - destination file
  Returns:
    the number of bytes copied
  Throws:
    `IOException` - if an I/O error occurs (may result in partially done work)
  See Also:
    `copy(InputStream, OutputStream)`

### copy

    public static long copy(File input,
                            File output,
                            byte[] copyBuffer)
                     throws IOException

  Copies one file to another using the supplied buffer.

  Parameters:
    `input` - source file
    `output` - destination file
    `copyBuffer` - buffer used for copying
  Returns:
    the number of bytes copied
  Throws:
    `IOException` - if an I/O error occurs (may result in partially done work)
  See Also:
    `copy(InputStream, OutputStream)`

### copy

    public static long copy(InputStream in,
                            File outputFile)
                     throws IOException

  Copies an `InputStream` to a file using `copy(InputStream, OutputStream)`.

  Parameters:
    `in` - stream to copy from
    `outputFile` - file to copy to
  Returns:
    the number of bytes copied
  Throws:
    `IOException` - if an I/O error occurs (may result in partially done work)
  See Also:
    `copy(InputStream, OutputStream)`

### copy

    public static long copy(InputStream in,
                            OutputStream out)
                     throws IOException

  Copies an `InputStream` to an `OutputStream` using a local internal buffer for performance. Compared to `globalBufferCopy(InputStream, OutputStream)` this method allows for better concurrency, but each time it is called generates a buffer which will be garbage.

  Parameters:
    `in` - stream to copy from
    `out` - stream to copy to
  Returns:
    the number of bytes copied
  Throws:
    `IOException` - if an I/O error occurs (may result in partially done work)
  See Also:
    `globalBufferCopy(InputStream, OutputStream)`

### globalBufferCopy

    public static long globalBufferCopy(InputStream in,
                                        OutputStream out)
                                 throws IOException

  Copies an `InputStream` to an `OutputStream` using a global internal buffer for performance. Compared to `copy(InputStream, OutputStream)` this method generated no garbage, but decreases concurrency.

  Parameters:
    `in` - stream to copy from
    `out` - stream to copy to
  Returns:
    the number of bytes copied
  Throws:
    `IOException` - if an I/O error occurs (may result in partially done work)
  See Also:
    `copy(InputStream, OutputStream)`

### copy

    public static long copy(InputStream in,
                            OutputStream out,
                            byte[] copyBuffer)
                     throws IOException

  Copies an `InputStream` to an `OutputStream` using the specified buffer.

  Parameters:
    `in` - stream to copy from
    `out` - stream to copy to
    `copyBuffer` - buffer used for copying
  Returns:
    the number of bytes copied
  Throws:
    `IOException` - if an I/O error occurs (may result in partially done work)
  See Also:
    `globalBufferCopy(InputStream, OutputStream)`, `copy(InputStream, OutputStream)`

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2004 The Apache Software Foundation. All Rights Reserved.