Package org.jfree.io
Class IOUtils
java.lang.Object
org.jfree.io.IOUtils
The IOUtils provide some IO related helper methods.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
copyStreams
(InputStream in, OutputStream out) Copies the InputStream into the OutputStream, until the end of the stream has been reached.void
copyStreams
(InputStream in, OutputStream out, int buffersize) Copies the InputStream into the OutputStream, until the end of the stream has been reached.void
copyWriter
(Reader in, Writer out) Copies the contents of the Reader into the Writer, until the end of the stream has been reached.void
copyWriter
(Reader in, Writer out, int buffersize) Copies the contents of the Reader into the Writer, until the end of the stream has been reached.createRelativeURL
(URL url, URL baseURL) Creates a relative url by stripping the common parts of the the url.private String
formatName
(List name, String query) Transforms the name list back into a single string, separated with "/".getFileExtension
(String file) Returns the file extension of the given file name.getFileName
(URL url) Extracts the file name from the URL.static IOUtils
Gets the singleton instance of the utility package.private String
Implements the JDK 1.3 method URL.getPath().private String
Implements the JDK 1.3 method URL.getPath().private boolean
isFileStyleProtocol
(URL url) Checks, whether the URL uses a file based protocol.private boolean
Returnstrue
if the URL represents a path, andfalse
otherwise.private boolean
isSameService
(URL url, URL baseUrl) Checks, whether the URL points to the same service.boolean
isSubDirectory
(File base, File child) Checks, whether the child directory is a subdirectory of the base directory.private List
Parses the given name and returns the name elements as List of Strings.private int
startsWithUntil
(List baseName, List urlName) Compares both name lists, and returns the last common index shared between the two lists.stripFileExtension
(String file) Removes the file extension from the given file name.
-
Field Details
-
instance
the singleton instance of the utility package.
-
-
Constructor Details
-
IOUtils
private IOUtils()DefaultConstructor.
-
-
Method Details
-
getInstance
Gets the singleton instance of the utility package.- Returns:
- the singleton instance.
-
isFileStyleProtocol
Checks, whether the URL uses a file based protocol.- Parameters:
url
- the url.- Returns:
- true, if the url is file based.
-
parseName
Parses the given name and returns the name elements as List of Strings.- Parameters:
name
- the name, that should be parsed.- Returns:
- the parsed name.
-
formatName
Transforms the name list back into a single string, separated with "/".- Parameters:
name
- the name list.query
- the (optional) query for the URL.- Returns:
- the constructed name.
-
startsWithUntil
Compares both name lists, and returns the last common index shared between the two lists.- Parameters:
baseName
- the name created using the base url.urlName
- the target url name.- Returns:
- the number of shared elements.
-
isSameService
Checks, whether the URL points to the same service. A service is equal if the protocol, host and port are equal.- Parameters:
url
- a urlbaseUrl
- an other url, that should be compared.- Returns:
- true, if the urls point to the same host and port and use the same protocol, false otherwise.
-
createRelativeURL
Creates a relative url by stripping the common parts of the the url.- Parameters:
url
- the to be stripped urlbaseURL
- the base url, to which theurl
is relative to.- Returns:
- the relative url, or the url unchanged, if there is no relation beween both URLs.
-
isPath
Returnstrue
if the URL represents a path, andfalse
otherwise.- Parameters:
baseURL
- the URL.- Returns:
- A boolean.
-
getQuery
Implements the JDK 1.3 method URL.getPath(). The path is defined as URL.getFile() minus the (optional) query.- Parameters:
url
- the URL- Returns:
- the path
-
getPath
Implements the JDK 1.3 method URL.getPath(). The path is defined as URL.getFile() minus the (optional) query.- Parameters:
url
- the URL- Returns:
- the path
-
copyStreams
Copies the InputStream into the OutputStream, until the end of the stream has been reached. This method uses a buffer of 4096 kbyte.- Parameters:
in
- the inputstream from which to read.out
- the outputstream where the data is written to.- Throws:
IOException
- if a IOError occurs.
-
copyStreams
Copies the InputStream into the OutputStream, until the end of the stream has been reached.- Parameters:
in
- the inputstream from which to read.out
- the outputstream where the data is written to.buffersize
- the buffer size.- Throws:
IOException
- if a IOError occurs.
-
copyWriter
Copies the contents of the Reader into the Writer, until the end of the stream has been reached. This method uses a buffer of 4096 kbyte.- Parameters:
in
- the reader from which to read.out
- the writer where the data is written to.- Throws:
IOException
- if a IOError occurs.
-
copyWriter
Copies the contents of the Reader into the Writer, until the end of the stream has been reached.- Parameters:
in
- the reader from which to read.out
- the writer where the data is written to.buffersize
- the buffer size.- Throws:
IOException
- if a IOError occurs.
-
getFileName
Extracts the file name from the URL.- Parameters:
url
- the url.- Returns:
- the extracted filename.
-
stripFileExtension
Removes the file extension from the given file name.- Parameters:
file
- the file name.- Returns:
- the file name without the file extension.
-
getFileExtension
Returns the file extension of the given file name. The returned value will contain the dot.- Parameters:
file
- the file name.- Returns:
- the file extension.
-
isSubDirectory
Checks, whether the child directory is a subdirectory of the base directory.- Parameters:
base
- the base directory.child
- the suspected child directory.- Returns:
- true, if the child is a subdirectory of the base directory.
- Throws:
IOException
- if an IOError occured during the test.
-