|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.qedeq.base.io.IoUtility
public final class IoUtility
A collection of useful static methods for input and output. LATER mime 20070101: use StringBuilder instead of StringBuffer if working under JDK 1.5
Method Summary | |
---|---|
static void |
close(java.io.InputStream in)
Closes input stream without exception. |
static void |
close(java.io.OutputStream out)
Closes out stream without exception. |
static void |
close(java.io.Reader reader)
Closes input reader without exception. |
static void |
close(java.io.Writer writer)
Closes writer without exception. |
static boolean |
compareFilesBinary(java.io.File from,
java.io.File with)
Compare two files binary. |
static boolean |
compareTextFiles(java.io.File from,
java.io.File with,
int startAtLine,
java.lang.String encoding)
Compare two text files. |
static boolean |
compareTextFiles(java.io.File from,
java.io.File with,
java.lang.String encoding)
Compare two text files. |
static void |
copy(java.io.File sourceLocation,
java.io.File targetLocation)
Copy one directory to another location. |
static void |
copy(java.lang.String sourceLocation,
java.lang.String targetLocation)
Copy one file or directory to another location. |
static void |
copyFile(java.io.File from,
java.io.File to)
Copies a file to a different location. |
static void |
createNecessaryDirectories(java.io.File file)
Creates necessary parent directories for a file. |
static java.lang.String |
createRelativePath(java.io.File origin,
java.io.File next)
Create relative address from origin to next . |
static boolean |
deleteDir(java.io.File directory,
boolean deleteDir)
Delete file directory recursive. |
static boolean |
deleteDir(java.io.File directory,
java.io.FileFilter filter)
Delete directory contents for all files that match the filter. |
static java.lang.String |
getDefaultEncoding()
Get default encoding for this system. |
static int[] |
getJavaVersion()
Get currently running java version and subversion numbers. |
static java.lang.String[][] |
getSortedSystemProperties()
Get key sorted list of all System Properties. |
static java.io.File |
getStartDirectory(java.lang.String application)
Get start directory for application. |
static java.io.File |
getUserHomeDirectory()
Get home directory of user. |
static java.lang.String |
getWorkingEncoding(java.lang.String encoding)
Get working Java encoding. |
static boolean |
isSymbolicLink(java.io.File file)
Determines whether the specified file is a symbolic link rather than an actual file. |
static boolean |
isWebStarted()
Was the application started by Java Webstart? |
static java.util.List |
listFilesRecursively(java.io.File sourceLocation,
java.io.FileFilter filter)
List all matching files. |
static void |
loadFile(java.io.File file,
java.lang.StringBuffer buffer)
Deprecated. Use loadFile(File, StringBuffer, String) . |
static void |
loadFile(java.io.File file,
java.lang.StringBuffer buffer,
java.lang.String encoding)
Reads contents of a file into a string buffer. |
static java.lang.String |
loadFile(java.lang.String filename,
java.lang.String encoding)
Reads a file and returns the contents as a String . |
static void |
loadFile(java.lang.String filename,
java.lang.StringBuffer buffer,
java.lang.String encoding)
Reads contents of a file into a string buffer. |
static void |
loadFile(java.net.URL url,
java.lang.StringBuffer buffer)
Deprecated. Choose correct encoding. |
static void |
loadFile(java.net.URL url,
java.lang.StringBuffer buffer,
java.lang.String encoding)
Reads contents of an URL into a StringBuffer. |
static byte[] |
loadFileBinary(java.io.File file)
Reads a file and returns the contents as a String . |
static java.util.Properties |
loadProperties(java.net.URL url)
Loads a property file from given URL. |
static void |
loadReader(java.io.Reader in,
java.lang.StringBuffer buffer)
Reads contents of a Reader into a string buffer. |
static void |
loadStream(java.io.InputStream in,
java.lang.StringBuffer buffer)
Deprecated. Use loadReader(Reader, StringBuffer) . |
static java.lang.String |
loadStreamWithoutException(java.io.InputStream in,
int maxLength)
Returns contents of a stream into a string, respecting a maximum length. |
static void |
printAllSystemProperties()
Print current system properties to System.out. |
static void |
saveFile(java.io.File file,
java.lang.String text)
Deprecated. Use saveFile(File, String, String) that has an encoding parameter. |
static void |
saveFile(java.io.File file,
java.lang.StringBuffer text)
Deprecated. Use saveFile(File, StringBuffer, String) that has an encoding
parameter. |
static void |
saveFile(java.io.File file,
java.lang.StringBuffer text,
java.lang.String encoding)
Saves a String in a file. |
static void |
saveFile(java.io.File file,
java.lang.String text,
java.lang.String encoding)
Saves a String in a file. |
static void |
saveFile(java.io.InputStream in,
java.io.File file)
Save binary contents of an input stream into a file. |
static void |
saveFile(java.lang.String filename,
java.lang.String text)
Deprecated. Use saveFile(File, String, String) that has an encoding. |
static void |
saveFile(java.lang.String filename,
java.lang.StringBuffer text)
Deprecated. Use saveFile(File, StringBuffer, String) that has an encoding. |
static void |
saveFile(java.net.URL url,
java.io.File file)
Save binary contents of an URL into a file. |
static void |
saveFileBinary(java.io.File file,
byte[] data)
Saves a data in a file. |
static void |
sleep(int ms)
Sleep my little class. |
static java.io.Reader |
stringToReader(java.lang.String data)
Convert String into a Reader . |
static void |
waitln()
Waits until a '\n' was read from System.in. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static java.lang.String getDefaultEncoding()
public static java.lang.String getWorkingEncoding(java.lang.String encoding)
encoding
- Try this encoding.
encoding
if it is supported. Or an other
encoding that is supported by this system.public static java.lang.String loadFile(java.lang.String filename, java.lang.String encoding) throws java.io.IOException
String
.
filename
- Name of the file (could include path).encoding
- Take this encoding.
java.io.IOException
- File exception occurred.public static void loadFile(java.lang.String filename, java.lang.StringBuffer buffer, java.lang.String encoding) throws java.io.IOException
filename
- Name of the file (could include path).buffer
- Buffer to fill with file contents.encoding
- Take this encoding.
java.io.IOException
- File exception occurred.public static void loadStream(java.io.InputStream in, java.lang.StringBuffer buffer) throws java.io.IOException
loadReader(Reader, StringBuffer)
.
in
- This stream will be loaded.buffer
- Buffer to fill with file contents.
java.io.IOException
- File exception occurred.public static java.lang.String loadStreamWithoutException(java.io.InputStream in, int maxLength)
in
- This stream will be loaded.maxLength
- This length is not exceeded.
null
.public static void loadReader(java.io.Reader in, java.lang.StringBuffer buffer) throws java.io.IOException
Reader
into a string buffer. Reader is not closed.
in
- This reader will be loaded.buffer
- Buffer to fill with file contents.
java.io.IOException
- File exception occurred.public static void loadFile(java.io.File file, java.lang.StringBuffer buffer) throws java.io.IOException
loadFile(File, StringBuffer, String)
.
file
- This file will be loaded.buffer
- Buffer to fill with file contents.
java.io.IOException
- File exception occurred.public static void loadFile(java.io.File file, java.lang.StringBuffer buffer, java.lang.String encoding) throws java.io.IOException
file
- This file will be loaded.buffer
- Buffer to fill with file contents.encoding
- Take this encoding.
java.io.IOException
- File exception occurred.public static final byte[] loadFileBinary(java.io.File file) throws java.io.IOException
String
.
file
- File to load from.
java.io.IOException
- File exception occurred.public static void loadFile(java.net.URL url, java.lang.StringBuffer buffer) throws java.io.IOException
All parameters should not be null
.
url
- This URL will be loaded.buffer
- Buffer to fill with file contents.
java.io.IOException
- Reading failed.public static void loadFile(java.net.URL url, java.lang.StringBuffer buffer, java.lang.String encoding) throws java.io.IOException
All parameters should not be null
.
url
- This URL will be loaded.buffer
- Buffer to fill with file contents.encoding
- Take this encoding.
java.io.IOException
- Reading failed.public static void saveFile(java.net.URL url, java.io.File file) throws java.io.IOException
url
- This URL will be loaded.file
- Write into this file.
java.io.IOException
- Reading or writing failed.public static void saveFile(java.io.InputStream in, java.io.File file) throws java.io.IOException
in
- Read this stream.file
- Write into this file.
java.io.IOException
- Reading or writing failed.public static final java.io.Reader stringToReader(java.lang.String data)
Reader
.
Bug ID: 4094886
data
- Convert this.
public static void saveFile(java.lang.String filename, java.lang.String text) throws java.io.IOException
saveFile(File, String, String)
that has an encoding.
String
into a file. Existing files are overwritten.
filename
- Name of the file (could include path).text
- Data to save in the file.
java.io.IOException
- File exception occurred.public static void saveFile(java.lang.String filename, java.lang.StringBuffer text) throws java.io.IOException
saveFile(File, StringBuffer, String)
that has an encoding.
StringBuffer
in a file. Existing files are overwritten.
filename
- Name of the file (could include path).text
- Data to save in the file.
java.io.IOException
- File exception occurred.public static void saveFile(java.io.File file, java.lang.StringBuffer text) throws java.io.IOException
saveFile(File, StringBuffer, String)
that has an encoding
parameter.
StringBuffer
in a file. Existing files are overwritten.
file
- File to save into.text
- Data to save in the file.
java.io.IOException
- File exception occurred.public static void saveFile(java.io.File file, java.lang.String text) throws java.io.IOException
saveFile(File, String, String)
that has an encoding parameter.
String
in a file. Uses default encoding. Existing files are
overwritten.
file
- File to save the data in.text
- Data to save in the file.
java.io.IOException
- File exception occurred.public static void saveFile(java.io.File file, java.lang.StringBuffer text, java.lang.String encoding) throws java.io.IOException
String
in a file. Existing files are overwritten.
file
- File to save the data in.text
- Data to save in the file.encoding
- Use this encoding.
java.io.IOException
- File exception occurred.public static void saveFile(java.io.File file, java.lang.String text, java.lang.String encoding) throws java.io.IOException
String
in a file.
file
- File to save the data in.text
- Data to save in the file.encoding
- Use this encoding.
java.io.IOException
- File exception occurred.public static void saveFileBinary(java.io.File file, byte[] data) throws java.io.IOException
data
in a file. Existing files are overwritten.
file
- File to save the data in.data
- Data to save in the file.
java.io.IOException
- File exception occurred.public static void copyFile(java.io.File from, java.io.File to) throws java.io.IOException
from
- Copy source.to
- Copy destination.
java.io.IOException
- File exception occurred.public static void copy(java.lang.String sourceLocation, java.lang.String targetLocation) throws java.io.IOException
sourceLocation
- Copy from here. This can be a file or a directory.targetLocation
- Copy to this location. If source is a file this must be a file too.
java.io.IOException
- Something went wrong.public static void copy(java.io.File sourceLocation, java.io.File targetLocation) throws java.io.IOException
sourceLocation
- Copy from here.targetLocation
- Copy to this location
java.io.IOException
- Something went wrong.public static java.util.List listFilesRecursively(java.io.File sourceLocation, java.io.FileFilter filter) throws java.io.IOException
true
for accept(File pathname)
if
pathname
is a directory if you want to search all sub directories!
If sourceLocation
is a single file, this is the only file that will
be in the resulting list.
sourceLocation
- Check all files in this directory. (Or add this single file.)filter
- Accept only these directories and files.
java.io.IOException
- Something went wrong.public static boolean compareFilesBinary(java.io.File from, java.io.File with) throws java.io.IOException
from
- Compare source. This file must be null
or be an existing file.with
- Compare with this file. This file must be null
or be an
existing file.
java.io.IOException
- File exception occurred.public static boolean compareTextFiles(java.io.File from, java.io.File with, java.lang.String encoding) throws java.io.IOException
from
- Compare source.with
- Compare with this file.encoding
- Use this character encoding. Must not be null
.
java.io.IOException
- File exception occurred or encoding is not supported.
java.lang.NullPointerException
- Is encoding different from null
?public static boolean compareTextFiles(java.io.File from, java.io.File with, int startAtLine, java.lang.String encoding) throws java.io.IOException
from
- Compare source.with
- Compare with this file.startAtLine
- Start comparing at this line (beginning with 0).encoding
- Use this character encoding. Must not be null
.
java.io.IOException
- File exception occurred or encoding is not supported.
java.lang.NullPointerException
- Is encoding different from null
?public static boolean deleteDir(java.io.File directory, boolean deleteDir)
directory
- Directory to delete. Must not be a symbolic link.deleteDir
- Delete directory itself too?
public static boolean deleteDir(java.io.File directory, java.io.FileFilter filter)
directory
- Directory to scan for files to delete.filter
- Filter files (and directories) to delete.
public static boolean isSymbolicLink(java.io.File file) throws java.io.IOException
https://svn.apache.org/repos/asf/commons/proper/io/trunk/src/main/java/org/apache/commons/io/FileUtils.java
.
file
- File to check.
java.io.IOException
- IO error while checking the file.public static void printAllSystemProperties()
public static java.io.File getUserHomeDirectory()
public static void createNecessaryDirectories(java.io.File file) throws java.io.IOException
file
- File.
java.io.IOException
- Creation failed.public static final java.lang.String createRelativePath(java.io.File origin, java.io.File next)
origin
to next
.
The resulting file path has "/" as directory name separator.
If the resulting file path is the same as origin specifies, we return "".
Otherwise the result will always have an "/" as last character.
origin
- This is the original location. Must be a directory.next
- This should be the next location. Must also be a directory.
public static void waitln()
public static void close(java.io.InputStream in)
in
- Input stream, maybe null
.public static void close(java.io.Writer writer)
writer
- Writer, maybe null
.public static void close(java.io.OutputStream out)
out
- Output stream, maybe null
.public static void close(java.io.Reader reader)
reader
- Reader, maybe null
.public static final java.io.File getStartDirectory(java.lang.String application)
new File(".")
. Otherwise the start directory is the subdirectory
"." concatenated application
within user.home
.
If a system property application + ".startDirectory"
is defined we take this
as the start directory.
application
- Application name, used for Java Webstart version. Should
be written in lowercase letters. A "." is automatically appended at
the beginning.
public static final boolean isWebStarted()
public static java.util.Properties loadProperties(java.net.URL url) throws java.io.IOException
url
- URL to load properties from. Must not be null
.
java.io.IOException
- Reading error.public static void sleep(int ms)
ms
- Milliseconds to wait.public static int[] getJavaVersion()
null
is returned.
public static java.lang.String[][] getSortedSystemProperties()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |