org.erowid.sperowider
Class FileUtils

java.lang.Object
  extended byorg.erowid.sperowider.FileUtils

public class FileUtils
extends Object

Simple file utilities.

Version:
: $Header: /cvsroot/sperowider/SPEROWIDER_MODULE/javasource/org/erowid/sperowider/FileUtils.java,v 1.8 2005/06/02 06:07:58 gurustu Exp $
Author:
: $Author: gurustu $

Constructor Summary
FileUtils()
           
 
Method Summary
static boolean compare(File f1, File f2)
          Compares two files or directories and returns true if they both exist and they both have the same contents, or if neither exists.
static boolean compare(InputStream is1, InputStream is2)
          Compares two IO streams and returns true if they match.
static void copy(InputStream is, OutputStream os)
          Copies for an input stream to a file.
static void copyDirectory(File fromDir, File toDir)
          Copies the contents of one directory, recursively, to another.
static void copyFile(File source, File destination)
          Copies for an input stream to a file.
static void copyFile(File source, String destination)
          Copies for an input stream to a file.
static void copyFile(String source, File destination)
          Copies for an input stream to a file.
static void copyFile(String source, String destination)
          Copies for an input stream to a file.
static File createFile(File file)
          Creates a file at a given location.
static File createFile(String name)
          Creates a file at a given location.
static boolean deleteFilesRecursively(File repository)
          Does a recursive delete on a directory
static StringBuffer getFileContent(String fileName)
          Pumps the contents of a file into a StringBuffer.
static OutputStream getFileOutputStream(File file)
          Gets an output stream for a given file name, creating the file if necessary.
static OutputStream getFileOutputStream(String name)
          Gets an output stream for a given file name, creating the file if necessary.
static PrintWriter getFilePrintWriter(File file)
          Gets an PrintWriter for a given file name, creating the file if necessary.
static PrintWriter getFilePrintWriter(String name)
          Gets an PrintWriter for a given file name, creating the file if necessary.
static File gunzip(File source)
          Gzips a file to a file of the same name, plus .gz.
static void gunzip(File source, File destination)
          Gzips from one file to another.
static void gunzip(File source, String destination)
          Gzips to a file.
static void gunzip(InputStream is, OutputStream os)
          Gzips from the input stream to the output stream.
static String gunzip(String source)
          Gunzips a file to a file of the same name, minus .gz.
static void gunzip(String source, File destination)
          Gzips to a file.
static void gunzip(String source, String destination)
          Gzips to a file.
static File gzip(File source)
          Gzips a file to a file of the same name, plus .gz.
static File gzip(File source, File destination)
          Gzips from one file to another.
static File gzip(File source, String destination)
          Gzips to a file.
static void gzip(InputStream is, OutputStream os)
          Gzips from the input stream to the output stream.
static File gzip(String source)
          Gzips a file to a file of the same name, plus .gz.
static File gzip(String source, File destination)
          Gzips to a file.
static File gzip(String source, String destination)
          Gzips to a file.
static File[] split(File source, int segmentSize)
          Splits a file into multiple files, each equal to the passed in length, except for the last file, which will probably be smaller as it's what is left.
static int split(InputStream is, File file, int length)
          Copes length bytes from the InputStream to a file.
static File[] split(String source, int segmentSize)
          Splits a file into multiple files, each equal to the passed in length, except for the last file, which will probably be smaller as it's what is left.
static File[] splitAndCompress(File source, int segmentSize)
          Splits a file into pieces, and then gzips each piece.
static File[] splitAndCompress(String source, int segmentSize)
          Splits a file into pieces, and then gzips each piece.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileUtils

public FileUtils()
Method Detail

deleteFilesRecursively

public static boolean deleteFilesRecursively(File repository)
Does a recursive delete on a directory


copyDirectory

public static void copyDirectory(File fromDir,
                                 File toDir)
                          throws IOException
Copies the contents of one directory, recursively, to another.

Throws:
IOException

getFilePrintWriter

public static PrintWriter getFilePrintWriter(File file)
                                      throws IOException
Gets an PrintWriter for a given file name, creating the file if necessary.

Throws:
IOException

getFileOutputStream

public static OutputStream getFileOutputStream(File file)
                                        throws IOException
Gets an output stream for a given file name, creating the file if necessary.

Throws:
IOException

getFilePrintWriter

public static PrintWriter getFilePrintWriter(String name)
                                      throws IOException
Gets an PrintWriter for a given file name, creating the file if necessary.

Throws:
IOException

getFileOutputStream

public static OutputStream getFileOutputStream(String name)
                                        throws IOException
Gets an output stream for a given file name, creating the file if necessary.

Throws:
IOException

createFile

public static File createFile(String name)
                       throws IOException
Creates a file at a given location.

Throws:
IOException

createFile

public static File createFile(File file)
                       throws IOException
Creates a file at a given location.

Throws:
IOException

splitAndCompress

public static File[] splitAndCompress(String source,
                                      int segmentSize)
                               throws IOException
Splits a file into pieces, and then gzips each piece.

Throws:
IOException

splitAndCompress

public static File[] splitAndCompress(File source,
                                      int segmentSize)
                               throws IOException
Splits a file into pieces, and then gzips each piece.

Throws:
IOException

split

public static File[] split(String source,
                           int segmentSize)
                    throws IOException
Splits a file into multiple files, each equal to the passed in length, except for the last file, which will probably be smaller as it's what is left.

Throws:
IOException

split

public static File[] split(File source,
                           int segmentSize)
                    throws IOException
Splits a file into multiple files, each equal to the passed in length, except for the last file, which will probably be smaller as it's what is left.

Throws:
IOException

split

public static int split(InputStream is,
                        File file,
                        int length)
                 throws IOException
Copes length bytes from the InputStream to a file. Does not close the input stream.

Throws:
IOException

copy

public static void copy(InputStream is,
                        OutputStream os)
                 throws IOException
Copies for an input stream to a file.

Throws:
IOException

copyFile

public static void copyFile(String source,
                            File destination)
                     throws IOException
Copies for an input stream to a file.

Throws:
IOException

copyFile

public static void copyFile(File source,
                            String destination)
                     throws IOException
Copies for an input stream to a file.

Throws:
IOException

copyFile

public static void copyFile(String source,
                            String destination)
                     throws IOException
Copies for an input stream to a file.

Throws:
IOException

copyFile

public static void copyFile(File source,
                            File destination)
                     throws IOException
Copies for an input stream to a file.

Throws:
IOException

getFileContent

public static StringBuffer getFileContent(String fileName)
                                   throws FileNotFoundException,
                                          IOException
Pumps the contents of a file into a StringBuffer.

Throws:
FileNotFoundException
IOException

gzip

public static File gzip(String source)
                 throws IOException
Gzips a file to a file of the same name, plus .gz. Returns the name of the created file.

Throws:
IOException

gzip

public static File gzip(File source)
                 throws IOException
Gzips a file to a file of the same name, plus .gz. Returns the file created.

Throws:
IOException

gzip

public static File gzip(String source,
                        String destination)
                 throws IOException
Gzips to a file.

Throws:
IOException

gzip

public static File gzip(String source,
                        File destination)
                 throws IOException
Gzips to a file.

Throws:
IOException

gzip

public static File gzip(File source,
                        String destination)
                 throws IOException
Gzips to a file.

Throws:
IOException

gzip

public static File gzip(File source,
                        File destination)
                 throws IOException
Gzips from one file to another.

Throws:
IOException

gzip

public static void gzip(InputStream is,
                        OutputStream os)
                 throws IOException
Gzips from the input stream to the output stream.

Throws:
IOException

gunzip

public static String gunzip(String source)
                     throws IOException
Gunzips a file to a file of the same name, minus .gz. The name of the file is returned.

Throws:
IOException

gunzip

public static File gunzip(File source)
                   throws IOException
Gzips a file to a file of the same name, plus .gz. The File created is returned.

Throws:
IOException

gunzip

public static void gunzip(String source,
                          String destination)
                   throws IOException
Gzips to a file.

Throws:
IOException

gunzip

public static void gunzip(String source,
                          File destination)
                   throws IOException
Gzips to a file.

Throws:
IOException

gunzip

public static void gunzip(File source,
                          String destination)
                   throws IOException
Gzips to a file.

Throws:
IOException

gunzip

public static void gunzip(File source,
                          File destination)
                   throws IOException
Gzips from one file to another.

Throws:
IOException

gunzip

public static void gunzip(InputStream is,
                          OutputStream os)
                   throws IOException
Gzips from the input stream to the output stream.

Throws:
IOException

compare

public static boolean compare(File f1,
                              File f2)
                       throws IOException
Compares two files or directories and returns true if they both exist and they both have the same contents, or if neither exists.

Throws:
IOException

compare

public static boolean compare(InputStream is1,
                              InputStream is2)
                       throws IOException
Compares two IO streams and returns true if they match.

Throws:
IOException

spero logo small Sperowider is
© 2005 Erowid.org