|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.Objectorg.h2.util.IOUtils
public class IOUtils
This utility class contains input/output functions.
| Method Summary | |
|---|---|
static boolean |
canWrite(java.lang.String fileName)
Check if the file is writable. |
static void |
closeSilently(java.io.InputStream in)
Close an input stream without throwing an exception. |
static void |
closeSilently(java.io.OutputStream out)
Close an output stream without throwing an exception. |
static void |
closeSilently(java.io.Reader reader)
Close a reader without throwing an exception. |
static void |
closeSilently(java.io.Writer writer)
Close a writer without throwing an exception. |
static long |
copy(java.io.InputStream in,
java.io.OutputStream out)
Copy all data from the input stream to the output stream. |
static long |
copy(java.io.InputStream in,
java.io.OutputStream out,
long length)
Copy all data from the input stream to the output stream. |
static void |
copy(java.lang.String original,
java.lang.String copy)
Copy a file from one directory to another, or to another file. |
static long |
copyAndClose(java.io.InputStream in,
java.io.OutputStream out)
Copy all data from the input stream to the output stream and close both streams. |
static long |
copyAndCloseInput(java.io.InputStream in,
java.io.OutputStream out)
Copy all data from the input stream to the output stream and close the input stream. |
static long |
copyAndCloseInput(java.io.Reader in,
java.io.Writer out,
long length)
Copy all data from the reader to the writer and close the reader. |
static void |
createDirs(java.lang.String fileName)
Create all required directories that are required for this file. |
static boolean |
createNewFile(java.lang.String fileName)
Create a new file. |
static java.lang.String |
createTempFile(java.lang.String prefix,
java.lang.String suffix,
boolean deleteOnExit,
boolean inTempDir)
Create a new temporary file. |
static void |
delete(java.lang.String fileName)
Delete a file. |
static void |
deleteRecursive(java.lang.String directory,
boolean tryOnly)
Delete a directory or file and all subdirectories and files. |
static boolean |
exists(java.lang.String fileName)
Checks if a file exists. |
static boolean |
fileStartsWith(java.lang.String fileName,
java.lang.String prefix)
Check if a file starts with a given prefix. |
static java.io.Reader |
getAsciiReader(java.io.InputStream in)
Wrap an input stream in a reader. |
static java.io.Reader |
getBufferedReader(java.io.InputStream in)
Create a buffered reader to read from an input stream using the UTF-8 format. |
static java.io.Writer |
getBufferedWriter(java.io.OutputStream out)
Create a buffered writer to write to an output stream using the UTF-8 format. |
static java.lang.String |
getCanonicalPath(java.lang.String fileName)
Normalize a file name. |
static java.lang.String |
getFileName(java.lang.String name)
Get the file name (without directory part). |
static java.io.InputStream |
getInputStream(java.lang.String s)
Create an input stream to read from a string. |
static long |
getLastModified(java.lang.String fileName)
Get the last modified date of a file. |
static java.lang.String |
getParent(java.lang.String fileName)
Get the parent directory of a file or directory. |
static java.io.Reader |
getReader(java.io.InputStream in)
Create a reader to read from an input stream using the UTF-8 format. |
static java.io.Reader |
getReader(java.lang.String s)
Create a reader to read from a string. |
static boolean |
isAbsolute(java.lang.String fileName)
Check if the file name includes a path. |
static boolean |
isDirectory(java.lang.String fileName)
Check if it is a file or a directory. |
static boolean |
isReadOnly(java.lang.String fileName)
Check if a file is read-only. |
static long |
length(java.lang.String fileName)
Get the length of a file. |
static java.lang.String[] |
listFiles(java.lang.String path)
List the files in the given directory. |
static void |
mkdirs(java.io.File directory)
Create the directory and all parent directories if required. |
static java.io.InputStream |
openFileInputStream(java.lang.String fileName)
Create an input stream to read from the file. |
static FileObject |
openFileObject(java.lang.String fileName,
java.lang.String mode)
Open a random access file object. |
static java.io.OutputStream |
openFileOutputStream(java.lang.String fileName,
boolean append)
Create an output stream to write into the file. |
static byte[] |
readBytesAndClose(java.io.InputStream in,
int length)
Read a number of bytes from an input stream and close the stream. |
static int |
readFully(java.io.InputStream in,
byte[] buffer,
int off,
int max)
Try to read the given number of bytes to the buffer. |
static int |
readFully(java.io.Reader in,
char[] buffer,
int max)
Try to read the given number of characters to the buffer. |
static java.lang.String |
readStringAndClose(java.io.Reader in,
int length)
Read a number of characters from a reader and close it. |
static void |
rename(java.lang.String oldName,
java.lang.String newName)
Rename a file if this is allowed. |
static void |
setLength(java.io.RandomAccessFile file,
long newLength)
Change the length of the file. |
static boolean |
setReadOnly(java.lang.String fileName)
Disable the ability to write. |
static void |
skipFully(java.io.InputStream in,
long skip)
Skip a number of bytes in an input stream. |
static void |
skipFully(java.io.Reader reader,
long skip)
Skip a number of characters in a reader. |
static void |
trace(java.lang.String method,
java.lang.String fileName,
java.lang.Object o)
Trace input or output operations if enabled. |
static boolean |
tryDelete(java.lang.String fileName)
Try to delete a file. |
static java.lang.String |
unwrap(java.lang.String fileName)
Get the unwrapped file name (without wrapper prefixes if wrapping / delegating file systems are used). |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method Detail |
|---|
public static void closeSilently(java.io.OutputStream out)
out - the output stream or null
public static void skipFully(java.io.InputStream in,
long skip)
throws java.io.IOException
in - the input streamskip - the number of bytes to skip
java.io.EOFException - if the end of file has been reached before all bytes
could be skipped
java.io.IOException - if an IO exception occurred while skipping
public static void skipFully(java.io.Reader reader,
long skip)
throws java.io.IOException
reader - the readerskip - the number of characters to skip
java.io.EOFException - if the end of file has been reached before all
characters could be skipped
java.io.IOException - if an IO exception occurred while skipping
public static long copyAndClose(java.io.InputStream in,
java.io.OutputStream out)
throws java.io.IOException
in - the input streamout - the output stream
java.io.IOException
public static long copyAndCloseInput(java.io.InputStream in,
java.io.OutputStream out)
throws java.io.IOException
in - the input streamout - the output stream (null if writing is not required)
java.io.IOException
public static long copy(java.io.InputStream in,
java.io.OutputStream out)
throws java.io.IOException
in - the input streamout - the output stream (null if writing is not required)
java.io.IOException
public static long copy(java.io.InputStream in,
java.io.OutputStream out,
long length)
throws java.io.IOException
in - the input streamout - the output stream (null if writing is not required)length - the maximum number of bytes to copy
java.io.IOException
public static long copyAndCloseInput(java.io.Reader in,
java.io.Writer out,
long length)
throws java.io.IOException
in - the readerout - the writer (null if writing is not required)length - the maximum number of bytes to copy
java.io.IOExceptionpublic static void closeSilently(java.io.InputStream in)
in - the input stream or nullpublic static void closeSilently(java.io.Reader reader)
reader - the reader or nullpublic static void closeSilently(java.io.Writer writer)
writer - the writer or null
public static byte[] readBytesAndClose(java.io.InputStream in,
int length)
throws java.io.IOException
in - the input streamlength - the maximum number of bytes to read, or -1 to read until
the end of file
java.io.IOException
public static java.lang.String readStringAndClose(java.io.Reader in,
int length)
throws java.io.IOException
in - the readerlength - the maximum number of characters to read, or -1 to read
until the end of file
java.io.IOException
public static int readFully(java.io.InputStream in,
byte[] buffer,
int off,
int max)
throws java.io.IOException
in - the input streambuffer - the output bufferoff - the offset in the buffermax - the number of bytes to read at most
java.io.IOException
public static int readFully(java.io.Reader in,
char[] buffer,
int max)
throws java.io.IOException
in - the readerbuffer - the output buffermax - the number of characters to read at most
java.io.IOExceptionpublic static java.io.Reader getBufferedReader(java.io.InputStream in)
in - the input stream or null
public static java.io.Reader getReader(java.io.InputStream in)
in - the input stream or null
public static java.io.Writer getBufferedWriter(java.io.OutputStream out)
out - the output stream or null
public static java.io.InputStream getInputStream(java.lang.String s)
s - the string
public static java.io.Reader getReader(java.lang.String s)
s - the string or null
public static java.io.Reader getAsciiReader(java.io.InputStream in)
in - the input stream
public static void mkdirs(java.io.File directory)
throws java.io.IOException
directory - the directory
java.io.IOException
public static void setLength(java.io.RandomAccessFile file,
long newLength)
throws java.io.IOException
file - the random access filenewLength - the new length
java.io.IOExceptionpublic static java.lang.String getFileName(java.lang.String name)
name - the directory and file name
public static boolean canWrite(java.lang.String fileName)
fileName - the file name
public static boolean setReadOnly(java.lang.String fileName)
fileName - the file name
public static void copy(java.lang.String original,
java.lang.String copy)
original - the original file namecopy - the file name of the copypublic static boolean createNewFile(java.lang.String fileName)
fileName - the file name
public static FileObject openFileObject(java.lang.String fileName,
java.lang.String mode)
throws java.io.IOException
fileName - the file namemode - the access mode. Supported are r, rw, rws, rwd
java.io.IOExceptionpublic static java.lang.String getCanonicalPath(java.lang.String fileName)
fileName - the file name
public static boolean tryDelete(java.lang.String fileName)
fileName - the file name
public static boolean isReadOnly(java.lang.String fileName)
fileName - the file name
public static boolean exists(java.lang.String fileName)
fileName - the file name
public static long length(java.lang.String fileName)
fileName - the file name
public static java.lang.String createTempFile(java.lang.String prefix,
java.lang.String suffix,
boolean deleteOnExit,
boolean inTempDir)
throws java.io.IOException
prefix - the prefix of the file name (including directory name if
required)suffix - the suffixdeleteOnExit - if the file should be deleted when the virtual
machine existsinTempDir - if the file should be stored in the temporary directory
java.io.IOExceptionpublic static java.lang.String getParent(java.lang.String fileName)
fileName - the file or directory name
public static java.lang.String[] listFiles(java.lang.String path)
path - the directory
public static boolean isDirectory(java.lang.String fileName)
fileName - the file or directory name
public static boolean isAbsolute(java.lang.String fileName)
fileName - the file name
public static boolean fileStartsWith(java.lang.String fileName,
java.lang.String prefix)
fileName - the complete file nameprefix - the prefix
public static java.io.InputStream openFileInputStream(java.lang.String fileName)
throws java.io.IOException
fileName - the file name
java.io.IOException
public static java.io.OutputStream openFileOutputStream(java.lang.String fileName,
boolean append)
fileName - the file nameappend - if true, the file will grow, if false, the file will be
truncated first
public static void rename(java.lang.String oldName,
java.lang.String newName)
oldName - the old fully qualified file namenewName - the new fully qualified file namepublic static void createDirs(java.lang.String fileName)
fileName - the file name (not directory name)public static void delete(java.lang.String fileName)
fileName - the file name
public static void deleteRecursive(java.lang.String directory,
boolean tryOnly)
directory - the directorytryOnly - whether errors should be ignoredpublic static long getLastModified(java.lang.String fileName)
fileName - the file name
public static java.lang.String unwrap(java.lang.String fileName)
fileName - the file name
public static void trace(java.lang.String method,
java.lang.String fileName,
java.lang.Object o)
method - the method from where this method was calledfileName - the file nameo - the object to append to the message
|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||