public class IOUtils
extends java.lang.Object
Constructor and Description |
---|
IOUtils() |
Modifier and Type | Method and Description |
---|---|
static void |
copyFile(java.io.File oldFile,
java.io.File newFile,
int bufSize)
Copy a file from one location to a new location.
|
static java.lang.String |
getFile(java.io.File file)
Get the contents of a File as a String.
|
static byte[] |
getFileAsArray(java.io.File file)
Get the contents of a File as a byte array.
|
static java.lang.String |
getFileLengthAsFormattedKilobytes(long length)
Get a file length as kilobytes in the form x.y.
|
static java.lang.String |
getFormattedFileLength(long length)
Get a file length as formatted string.
|
static boolean |
getYNFromUser(java.lang.String question)
Ask a question of the User on stdout and wait for a response.
|
static void |
gzipFile(java.io.File file,
java.io.File newFile)
GZIP a file, this will move the file from the
given name to the new location.
|
static void |
streamTo(java.io.InputStream in,
java.io.OutputStream out,
int bufSize)
This method acts as a "join" between an input and an output stream, all it does is
take the input and keep reading it in and sending it directly to the output using the
specified buffer size.
|
static void |
writeBytesToFile(java.io.File file,
byte[] bytes)
Write the given bytes to a file, note that this method will just overwrite
any existing file.
|
static void |
writeBytesToFile(java.io.File file,
byte[] bytes,
int bufSize)
Write the given bytes to a file, note that this method will just overwrite
any existing file.
|
static void |
writeStringToFile(java.io.File file,
java.lang.String str,
boolean compress)
Write the given String to the File.
|
public static void copyFile(java.io.File oldFile, java.io.File newFile, int bufSize) throws java.io.IOException
oldFile
- The old file name.newFile
- The new file location.bufSize
- The buffer size to use when performing the copy.java.io.IOException
- If we can't perform the copy.public static void gzipFile(java.io.File file, java.io.File newFile) throws ChainException
file
- The existing file name of the file.newFile
- The new file location for the file.ChainException
- If we can't perform the transfer, the inner exception will
contain an IOException that is the "real" exception.public static java.lang.String getFileLengthAsFormattedKilobytes(long length)
length
- The length of the file.public static java.lang.String getFormattedFileLength(long length)
length
- The length of the file.public static void streamTo(java.io.InputStream in, java.io.OutputStream out, int bufSize) throws java.io.IOException
in
- The input stream.out
- The output stream.bufSize
- The buffer size.java.io.IOException
- If an IO exception occurs.public static void writeBytesToFile(java.io.File file, byte[] bytes, int bufSize) throws java.io.IOException
file
- The file to write to.bytes
- The byte array.bufSize
- The size of output buffer to use, set to -1 to have the buffer size set to
bytes.length.java.io.IOException
- If the array cannot be written to the file.public static void writeBytesToFile(java.io.File file, byte[] bytes) throws java.io.IOException
writeBytesToFile(File,byte[],int)
.file
- The file to write to.bytes
- The byte array.java.io.IOException
- If the array cannot be written to the file.public static void writeStringToFile(java.io.File file, java.lang.String str, boolean compress) throws java.io.IOException
file
- The file to write to.str
- The value to write.java.io.IOException
- This should never happen because PrintWriter will
catch it.public static java.lang.String getFile(java.io.File file) throws java.io.IOException
file
- The file to read in.java.io.IOException
- If there is a problem with the read.java.lang.IllegalArgumentException
- If the file length is greater than 232-1 since
the maximum size of an array is (max)int - 1.public static byte[] getFileAsArray(java.io.File file) throws java.io.IOException
file
- The file to read in.java.io.IOException
- If there is a problem with the read.java.lang.IllegalArgumentException
- If the file length is greater than 232-1 since
the maximum size of an array is (max)int - 1.public static boolean getYNFromUser(java.lang.String question) throws java.io.IOException
true
. Everything else is a no and
returns false
.question
- The question to ask.true
if they responded with y|yes etc...return
false
otherwise.java.io.IOException
- If there is an io problem.