Package com.luciad.io

Class TLcdIOUtil

java.lang.Object
com.luciad.io.TLcdIOUtil

public class TLcdIOUtil extends Object
IO utility class to facilitate the handling of URLs, absolute file paths or paths relative to the classpath. This class has methods to:
  • Constructor Details

    • TLcdIOUtil

      public TLcdIOUtil()
      Creates a IO utility.
  • Method Details

    • setClassTraceOn

      public static void setClassTraceOn(boolean aClassTraceOn)
      Deprecated.
      This method has been deprecated. It is recommended to use the standard Java logging framework directly.
      Enables tracing for all instances of this class. If the argument is true then all log messages are recorded, otherwise only the informative, warning and error messages are recorded.
      Parameters:
      aClassTraceOn - if true then all log messages are recorded, otherwise only the informative, warning and error messages are recorded.
    • setTraceOn

      public void setTraceOn(boolean aTraceOn)
      Deprecated.
      This method has been deprecated. It is recommended to use the standard Java logging framework directly.
      Enables tracing for this class instance. Calling this method with either 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.
      Parameters:
      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.
    • isTraceOn

      public boolean isTraceOn()
      Deprecated.
      This method has been deprecated. It is recommended to use the standard Java logging framework directly.
      Returns true if tracing is enabled for this class.
      Returns:
      true if tracing is enabled for this class, false otherwise.
    • resolve

      public static Path resolve(String aSourceName)
      Returns an NIO Path for the given file source. This works for an absolute file path, a file URI, or a path relative to the classpath, but not for a JAR resource. Paths relative to the working directory are not resolved.
      Parameters:
      aSourceName - a file URI, absolute file path or path relative to the classpath
      Returns:
      a Path, or null if the source could not be parsed as a file path or valid file URI
      Since:
      2017.0
    • createURI

      public 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:

      • absolute file paths
      • URLs (file, http, etc...)
      • paths relative to the class path or the current directory

      It also does an effort to correct incorrect input strings, for example:

      • file:////xxx
      • file:/mnt/server/xxx
      Parameters:
      aSourceName - the source name
      Returns:
      a URI, or null if the URI could not be create.
      Since:
      2017.1
    • setSourceName

      public void setSourceName(String aSourceName)
      Set the source where the data should be loaded from. This can be a URL, an absolute file path or a path relative to the classpath.
      Parameters:
      aSourceName - the source to retrieve data from.
      Throws:
      NullPointerException - when the source is null.
    • retrieveInputStream

      public InputStream retrieveInputStream() throws IOException
      Deprecated.
      TLcdInputStreamFactory offers more configuration options and better performance
      Returns an input stream for the 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.

      Returns:
      an InputStream to the resource set in setSourceName.
      Throws:
      IOException - when an I/O error occurs.
      See Also:
    • getURL

      public URL getURL()
      Returns the URL value.
      Returns:
      not null if the source name set was a URL, or could be retrieved through the classpath. null if the source name was interpreted as a file.
      See Also:
    • getFileName

      public String getFileName()
      Returns the file name value.
      Returns:
      null if the source name was interpreted as a URL, derived from the source name otherwise.
      See Also:
    • getDirectoryPath

      public static String getDirectoryPath(String aFullPathName)
      Returns the path of a source (URL or file). This is the counterpart for the static method getFileName(). The result includes the last file separator, if there are any.
      Parameters:
      aFullPathName - the full path to a source.
      Returns:
      the path of a source (URL or file).
      See Also:
    • getFileName

      public static String getFileName(String aFullPathName)
      Return the file name of a source (URL or file) without the path. This is the part of the input string that comes after the last occurrence of a file separator. A file separator can be both / and \.
      Parameters:
      aFullPathName - the full path to a source.
      Returns:
      the file name of a source (URL or file) without the path.
      See Also:
    • getFilenameWithoutExtension

      public static String getFilenameWithoutExtension(String aFullPathName, String... aExtensions)
      Return the file name of a source (URL or file) without the path.
      Parameters:
      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.
      Returns:
      the file name of a source (URL or file) without the path.
      Since:
      2017.0
      See Also:
    • setUseCacheDefault

      public static void setUseCacheDefault(boolean aUseCacheDefault)
      Sets the property UseCacheDefault. This property ensures using the cache of a browser for URL connections. Whether or not this cache is actually used depends on the implementation of the JVM (e.g. in web browsers). The default is true.
      Parameters:
      aUseCacheDefault - specifies whether or not to use the cache.
      See Also:
    • getUseCacheDefault

      public static boolean getUseCacheDefault()
      Return the property UseCacheDefault.
      Returns:
      whether to use the cache for URL connections.
      See Also:
    • setAsFileFirst

      public static void setAsFileFirst(boolean aAsFileFirst)
      Sets the property AsFileFirst. This property ensures that IOUtil will try to open sources as files first, thus possibly avoiding costly URL/HTTP connections. The default is false.
      Parameters:
      aAsFileFirst - specifies whether or not to attempt to open the source name as a file first.
      See Also:
    • getAsFileFirst

      public static boolean getAsFileFirst()
      Returns the property AsFileFirst.
      Returns:
      whether to address sources a files first.
      See Also:
    • setUseNIO

      public static void setUseNIO(boolean aUseNIO)
      Sets the property UseNIO. This property specifies whether IOUtil can use the Java NIO package to read data from files. The NIO package can significantly speed up reading large files. The default is false.
      Parameters:
      aUseNIO - specifies whether or not to use the Java NIO package.
      See Also:
    • getUseNIO

      public static boolean getUseNIO()
      Returns the property UseNIO.
      Returns:
      whether the Java NIO package can be used.
      See Also:
    • toByteArray

      public static byte[] toByteArray(InputStream aInputStream) throws IOException
      Converts the given InputStream to a byte array. Note that this method does not close the given InputStream. This is up to the caller of this method.
      Parameters:
      aInputStream - the input stream to convert to a byte array
      Returns:
      a byte array with the contents of the given InputStream
      Throws:
      IOException