public class IOUtils
extends java.lang.Object
Modifier and Type | Method and Description |
---|---|
void |
copyStreams(java.io.InputStream in,
java.io.OutputStream out)
Copies the InputStream into the OutputStream, until the end of the stream has been reached.
|
void |
copyStreams(java.io.InputStream in,
java.io.OutputStream out,
int buffersize)
Copies the InputStream into the OutputStream, until the end of the stream has been reached.
|
void |
copyWriter(java.io.Reader in,
java.io.Writer out)
Copies the contents of the Reader into the Writer, until the end of the stream has been reached.
|
void |
copyWriter(java.io.Reader in,
java.io.Writer out,
int buffersize)
Copies the contents of the Reader into the Writer, until the end of the stream has been reached.
|
java.lang.String |
createRelativePath(java.lang.String targetFile,
java.lang.String baseFile)
Creates a relative url by stripping the common parts of the the url.
|
java.lang.String |
createRelativeURL(java.net.URL url,
java.net.URL baseURL)
Creates a relative url by stripping the common parts of the the url.
|
java.io.File |
findFileOnClassPath(java.lang.String name)
Returns a reference to a file with the specified name that is located somewhere on the classpath.
|
java.lang.String |
getAbsolutePath(java.lang.String targetFile,
java.lang.String baseFile)
Computes the absolute filename for the target file using the baseFile as root directory.
|
java.lang.String |
getFileExtension(java.lang.String file)
Returns the file extension of the given file name.
|
java.lang.String |
getFileName(java.lang.String path)
Extracts the last file name from the given pathname.
|
java.lang.String |
getFileName(java.net.URL url)
Extracts the file name from the URL.
|
static IOUtils |
getInstance()
Gets the singleton instance of the utility package.
|
java.lang.String |
getPath(java.lang.String path)
Returns the path-portion of the given path (anything before the last slash or backslash) or an empty string.
|
boolean |
isSubDirectory(java.io.File base,
java.io.File child)
Checks, whether the child directory is a subdirectory of the base directory.
|
void |
readFully(java.io.InputStream in,
byte[] data,
int offset,
int length)
Reads the given number of bytes into the target array.
|
java.lang.String |
stripFileExtension(java.lang.String file)
Removes the file extension from the given file name.
|
public static IOUtils getInstance()
public java.lang.String createRelativePath(java.lang.String targetFile, java.lang.String baseFile)
targetFile
- the to be stripped urlbaseFile
- the base url, to which the url
is relative to.public java.lang.String createRelativeURL(java.net.URL url, java.net.URL baseURL)
url
- the to be stripped urlbaseURL
- the base url, to which the url
is relative to.public void copyStreams(java.io.InputStream in, java.io.OutputStream out) throws java.io.IOException
in
- the inputstream from which to read.out
- the outputstream where the data is written to.java.io.IOException
- if a IOError occurs.public void copyStreams(java.io.InputStream in, java.io.OutputStream out, int buffersize) throws java.io.IOException
in
- the inputstream from which to read.out
- the outputstream where the data is written to.buffersize
- the buffer size.java.io.IOException
- if a IOError occurs.public void copyWriter(java.io.Reader in, java.io.Writer out) throws java.io.IOException
in
- the reader from which to read.out
- the writer where the data is written to.java.io.IOException
- if a IOError occurs.public void copyWriter(java.io.Reader in, java.io.Writer out, int buffersize) throws java.io.IOException
in
- the reader from which to read.out
- the writer where the data is written to.buffersize
- the buffer size.java.io.IOException
- if a IOError occurs.public void readFully(java.io.InputStream in, byte[] data, int offset, int length) throws java.io.IOException
in
- the inputstream from where to read.data
- the array where to store the data.offset
- the offset in the array where to store the data.length
- the number of bytes to be read.java.io.IOException
- if an IO error occured or the End of the stream has been reached.public java.lang.String getFileName(java.net.URL url)
url
- the url.public java.lang.String getFileName(java.lang.String path)
path
- the path name.public java.lang.String stripFileExtension(java.lang.String file)
file
- the file name.public java.lang.String getFileExtension(java.lang.String file)
file
- the file name.public boolean isSubDirectory(java.io.File base, java.io.File child) throws java.io.IOException
base
- the base directory.child
- the suspected child directory.java.io.IOException
- if an IOError occured during the test.public java.io.File findFileOnClassPath(java.lang.String name) throws java.lang.SecurityException
name
- the filename.null
if no file could be found.java.lang.SecurityException
- if access to the system properties or filesystem is forbidden.public java.lang.String getAbsolutePath(java.lang.String targetFile, java.lang.String baseFile)
targetFile
- the target file name.baseFile
- the base file (can be null).public java.lang.String getPath(java.lang.String path)
path
- the path or filename from where to extract the path name.