|
|||||||||
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 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 |
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)
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 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 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.lang.String |
getAbsolutePath(java.lang.String fileName)
Get the absolute file name. |
static java.io.Reader |
getAsciiReader(java.io.InputStream in)
Wrap an input stream in a reader. |
static java.lang.String |
getFileInUserHome(java.lang.String fileName)
Get the absolute file path of a file in the user home directory. |
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 java.io.Writer |
getWriter(java.io.OutputStream out)
Create a buffered writer to write to an output stream using the UTF-8 format. |
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 |
isInDir(java.io.File file,
java.io.File dir)
Checks if a file is below a given 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.lang.String |
normalize(java.lang.String fileName)
Normalize a file name. |
static java.io.InputStream |
openFileInputStream(java.lang.String fileName)
Create an input stream to read from the file. |
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 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 boolean |
tryDelete(java.lang.String fileName)
Try to delete a file. |
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 nullpublic 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 skippingpublic 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 skippingpublic 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
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
java.io.IOException
public static long copyAndCloseInput(java.io.Reader in, java.io.Writer out) throws java.io.IOException
in
- the readerout
- the writer
java.io.IOException
public 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 nullpublic 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.IOException
public static java.io.Reader getReader(java.io.InputStream in)
in
- the input stream or null
public static java.io.Writer getWriter(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.IOException
public static java.lang.String getFileInUserHome(java.lang.String fileName)
fileName
- the file name
public static java.lang.String getFileName(java.lang.String name)
name
- the directory and file name
public static java.lang.String normalize(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.IOException
public 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 java.lang.String getAbsolutePath(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 namepublic static long getLastModified(java.lang.String fileName)
fileName
- the file name
public static boolean isInDir(java.io.File file, java.io.File dir)
file
- the file to checkdir
- the directory the file must be in
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |