public class IOUtils
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
private static IOUtils |
instance
the singleton instance of the utility package.
|
Modifier | Constructor and Description |
---|---|
private |
IOUtils()
DefaultConstructor.
|
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 |
createRelativeURL(java.net.URL url,
java.net.URL baseURL)
Creates a relative url by stripping the common parts of the the url.
|
private java.lang.String |
formatName(java.util.List name,
java.lang.String query)
Transforms the name list back into a single string, separated with "/".
|
java.lang.String |
getFileExtension(java.lang.String file)
Returns the file extension of the given file name.
|
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.
|
private java.lang.String |
getPath(java.net.URL url)
Implements the JDK 1.3 method URL.getPath().
|
private java.lang.String |
getQuery(java.net.URL url)
Implements the JDK 1.3 method URL.getPath().
|
private boolean |
isFileStyleProtocol(java.net.URL url)
Checks, whether the URL uses a file based protocol.
|
private boolean |
isPath(java.net.URL baseURL)
Returns
true if the URL represents a path, and
false otherwise. |
private boolean |
isSameService(java.net.URL url,
java.net.URL baseUrl)
Checks, whether the URL points to the same service.
|
boolean |
isSubDirectory(java.io.File base,
java.io.File child)
Checks, whether the child directory is a subdirectory of the base
directory.
|
private java.util.List |
parseName(java.lang.String name)
Parses the given name and returns the name elements as List of Strings.
|
private int |
startsWithUntil(java.util.List baseName,
java.util.List urlName)
Compares both name lists, and returns the last common index shared
between the two lists.
|
java.lang.String |
stripFileExtension(java.lang.String file)
Removes the file extension from the given file name.
|
private static IOUtils instance
public static IOUtils getInstance()
private boolean isFileStyleProtocol(java.net.URL url)
url
- the url.private java.util.List parseName(java.lang.String name)
name
- the name, that should be parsed.private java.lang.String formatName(java.util.List name, java.lang.String query)
name
- the name list.query
- the (optional) query for the URL.private int startsWithUntil(java.util.List baseName, java.util.List urlName)
baseName
- the name created using the base url.urlName
- the target url name.private boolean isSameService(java.net.URL url, java.net.URL baseUrl)
url
- a urlbaseUrl
- an other url, that should be compared.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.private boolean isPath(java.net.URL baseURL)
true
if the URL represents a path, and
false
otherwise.baseURL
- the URL.private java.lang.String getQuery(java.net.URL url)
url
- the URLprivate java.lang.String getPath(java.net.URL url)
url
- the URLpublic 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 java.lang.String getFileName(java.net.URL url)
url
- the url.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.