|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.ccg.io.Copy
public class Copy
Some static methods to aid in the copying of files.
This class provides some helper methods related to copying files (or streams of information).
| Constructor Summary | |
|---|---|
Copy()
|
|
| Method Summary | |
|---|---|
static boolean |
fileToDir(File from,
File dir)
Copies the contents of one File to a directory. |
static boolean |
fileToFile(File from,
File to)
Copies the contents of one File to another File. |
static void |
fileToStream(File from,
OutputStream to)
Copies the contents of a File to a OutputStream. |
static boolean |
smartFileToFile(File from,
File to)
A "smart" copy of one File to another File. |
static void |
streamToFile(InputStream from,
File to)
Copies the contents of a InputStream to a
File. |
static void |
streamToStream(InputStream from,
OutputStream to)
Copies contents of a InputStream to a OutputStream. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public Copy()
| Method Detail |
|---|
public static void streamToStream(InputStream from,
OutputStream to)
throws IOException
InputStream to a OutputStream.
This method uses buffered stream wrappers around the streams passed to copy data from one stream to the other. After it finishes the copy (even it an exception occurs) an attempt will be made to close BOTH streams.
from - The InputStream to copy data from (must
not be null).to - The OutputStream to copy data to (must
not be null).
IOException - If there is a problem copying the data or closing one of the
files (both files will be closed prior to throwing the
exception).streamToFile(java.io.InputStream, java.io.File),
fileToStream(java.io.File, java.io.OutputStream),
fileToFile(java.io.File, java.io.File)
public static void streamToFile(InputStream from,
File to)
throws IOException
InputStream to a
File.
This method converts the File object passed into a
OutputStream and then invokes streamToStream(java.io.InputStream, java.io.OutputStream) to copy the data from the stream to the file.
from - The InputStream to copy data from (must
not be null).to - The File to copy data to (must not be null).
IOException - If there is a problem copying the data or closing one of the
files (both files will be closed prior to throwing the
exception).streamToStream(java.io.InputStream, java.io.OutputStream)
public static void fileToStream(File from,
OutputStream to)
throws IOException
File to a OutputStream.
This method converts the File object passed into a
InputStream and then invokes streamToStream(java.io.InputStream, java.io.OutputStream) to copy the data from the file to the stream.
from - The File to copy the data from (must not be null).to - The OutputStream to copy data fo (must
not be null).
IOException - If there is a problem copying the data or closing one of the
files (both files will be closed prior to throwing the
exception).streamToStream(java.io.InputStream, java.io.OutputStream)
public static boolean fileToFile(File from,
File to)
throws IOException
File to another File.
This method copies one file to another.
In addtion, after the file is copied, we then attempt to set the last modification time on the resulting file to match the source.
If the two files you specify are "equal", nothing is done (we just return false indicating that we couldn't copy one file on top of the other).
This method takes a all or nothing approach (if it is unable to copy the entire file, then nothing is copied and a error is thrown).
from - The File to copy the data from (must not be null).to - The File to copy data to (must not be null).
IOException - If there is a problem copying the data or closing one of the
files (both files will be closed prior to throwing the
exception).streamToStream(java.io.InputStream, java.io.OutputStream),
smartFileToFile(java.io.File, java.io.File)
public static boolean fileToDir(File from,
File dir)
throws IOException
File to a directory.
This method copies one source file to a specified destination directory (preserving the file name). The destination directory (and any parent directories) will be created if they do not yet exist.
In addtion, after the file is copied, we then attempt to set the last modification time on the resulting file to match the source.
If the resulting destination file turns out to be the same as the source file, nothing is done (we just return false indicating that we couldn't copy one file on top of the other).
from - The File to copy the data from (must not be null).dir - The directory where we should copy the file to.
It will be created if it doesn't yet exist - including parent
directories.
IOException - If there is a problem copying the data or closing one of the
files or unable to use directory specified (both files will be
closed prior to throwing the exception).fileToFile(java.io.File, java.io.File),
smartFileToFile(java.io.File, java.io.File)
public static boolean smartFileToFile(File from,
File to)
throws IOException
File to another File.
This method copies the contents of a source File
to destination File, but only if the modification
time of the source file is more recent than the destination file
or the file sizes differ between the two files.
In addtion, after the file is copied, we then attempt to set the last modification time on the resulting file to match the source.
If the two files you specify are "equal", nothing is done (we just return false indicating that we couldn't copy one file on top of the other). However, in this case we consider two files equal if they have the same modificaton time and size.
from - The File to copy the data from (must not be null).to - The File to copy data to (must not be null).
IOException - If there is a problem copying the data or closing one of the
files (both files will be closed prior to throwing the
exception).fileToFile(java.io.File, java.io.File)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||