public class TLcdIOUtil extends Object
retrieve an NIO Path
for an absolute file or file URI, or a file path relative to the class path
configure a source
, and check the getFileName()
and getURL()
methods.
extract the directory
path from a source.
extract the file name
without the path from a source.
Constructor and Description |
---|
TLcdIOUtil()
Creates a IO utility.
|
Modifier and Type | Method and Description |
---|---|
static URI |
createURI(String aSourceName)
Returns a URI for the given source.
|
static boolean |
getAsFileFirst()
Returns the property AsFileFirst.
|
static String |
getDirectoryPath(String aFullPathName)
Returns the path of a source (URL or file).
|
String |
getFileName()
Returns the file name value.
|
static String |
getFileName(String aFullPathName)
Return the file name of a source (URL or file) without the path.
|
static String |
getFilenameWithoutExtension(String aFullPathName,
String... aExtensions)
Return the file name of a source (URL or file) without the path.
|
URL |
getURL()
Returns the URL value.
|
static boolean |
getUseCacheDefault()
Return the property UseCacheDefault.
|
static boolean |
getUseNIO()
Returns the property UseNIO.
|
boolean |
isTraceOn()
Deprecated.
This method has been deprecated. It is recommended to use the
standard Java logging framework directly.
|
static Path |
resolve(String aSourceName)
Returns an NIO Path for the given source.
|
InputStream |
retrieveInputStream()
Deprecated.
TLcdInputStreamFactory offers more configuration options and better performance
|
static void |
setAsFileFirst(boolean aAsFileFirst)
Sets the property AsFileFirst.
|
static void |
setClassTraceOn(boolean aClassTraceOn)
Deprecated.
This method has been deprecated. It is recommended to use the
standard Java logging framework directly.
|
void |
setSourceName(String aSourceName)
Set the source where the data should be loaded from.
|
void |
setTraceOn(boolean aTraceOn)
Deprecated.
This method has been deprecated. It is recommended to use the
standard Java logging framework directly.
|
static void |
setUseCacheDefault(boolean aUseCacheDefault)
Sets the property UseCacheDefault.
|
static void |
setUseNIO(boolean aUseNIO)
Sets the property UseNIO.
|
static byte[] |
toByteArray(InputStream aInputStream)
Converts the given
InputStream to a byte array. |
public static void setClassTraceOn(boolean aClassTraceOn)
true
then all log messages are recorded, otherwise only the
informative, warning and error messages are recorded.aClassTraceOn
- if true then all log messages are recorded, otherwise only the
informative, warning and error messages are recorded.public void setTraceOn(boolean aTraceOn)
true
or false
as argument automatically turns off
tracing for all other class instances for which setTraceOn
has
not been called. If the argument is false
then only the
informative, warning and error log messages are recorded.aTraceOn
- if true then all log messages are recorded for this instance. If
false, then only the informative, warning and error log messages
are recorded.public boolean isTraceOn()
true
if tracing is enabled for this class.public static Path resolve(String aSourceName)
aSourceName
- a file URI, absolute file path or path relative to the classpathpublic static URI createURI(String aSourceName)
Returns a URI for the given source. The source does not need to exist for this method to work.
This method works for a variety of inputs. For example:
It also does an effort to correct incorrect input strings, for example:
aSourceName
- the source namenull
if the URI could not be create.public void setSourceName(String aSourceName)
aSourceName
- the source to retrieve data from.NullPointerException
- when the source is null.public InputStream retrieveInputStream() throws IOException
configured source
.
Source names ending in .zip or .gz are unzipped automatically.
The caller of this method is responsible to close the input stream returned by this method when it is no longer needed. Failing to do so may lock system resources which will eventually break down the system.
IOException
- when an I/O error occurs.setSourceName(java.lang.String)
public URL getURL()
getFileName()
public String getFileName()
getURL()
public static String getDirectoryPath(String aFullPathName)
aFullPathName
- the full path to a source.getFileName(java.lang.String)
public static String getFileName(String aFullPathName)
/
and \
.aFullPathName
- the full path to a source.getDirectoryPath(java.lang.String)
public static String getFilenameWithoutExtension(String aFullPathName, String... aExtensions)
aFullPathName
- the full path to a source.aExtensions
- The possible extensions for the format, if available.
The casing does not matter.
It doesn't matter either whether the extension starts with a "." or not.
None of these extensions should be null
.
Specify no extensions when the extensions are unknown.getDirectoryPath(java.lang.String)
public static void setUseCacheDefault(boolean aUseCacheDefault)
true
.aUseCacheDefault
- specifies whether or not to use the cache.getUseCacheDefault()
public static boolean getUseCacheDefault()
setUseCacheDefault(boolean)
public static void setAsFileFirst(boolean aAsFileFirst)
false
.aAsFileFirst
- specifies whether or not to attempt to open the source
name as a file first.getAsFileFirst()
public static boolean getAsFileFirst()
setAsFileFirst(boolean)
public static void setUseNIO(boolean aUseNIO)
false
.aUseNIO
- specifies whether or not to use the Java NIO package.getUseNIO()
public static boolean getUseNIO()
setUseNIO(boolean)
public static byte[] toByteArray(InputStream aInputStream) throws IOException
InputStream
to a byte array. Note that this method does not
close the given InputStream
. This is up to the caller of this method.aInputStream
- the input stream to convert to a byte arrayInputStream
IOException