Class ClasspathResource


  • public class ClasspathResource
    extends java.lang.Object
    This object represents a classpath resource on the local system. It allows you to specify a location and then extract the inputstream, reader or lines of the resource. We also support GZiped files (so long as the resource ends with a .gz) and pre-caching of the data so we read only once from the classpath and close that link down. This is useful if you want to keep IO handles down but not very useful if the file is very large.
    Author:
    ayates
    • Constructor Summary

      Constructors 
      Constructor Description
      ClasspathResource​(java.lang.String location)
      Basic constructor only allowing you to specify where to find the file.
      ClasspathResource​(java.lang.String location, boolean preCache)
      Advanced constructor which allows you to optionally pre-cache the data
      ClasspathResource​(java.lang.String location, boolean preCache, boolean isGzip)
      Advanced constructor which lets you set the preCache variable and to force the type of file we are decompressing.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.io.BufferedReader getBufferedReader()
      Returns the reader representation of this classpath resource
      java.io.InputStream getInputStream()
      Returns the InputStream instance of this classpath resource
      java.util.List<java.lang.String> getList()
      Returns this resource as a list of Strings
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ClasspathResource

        public ClasspathResource​(java.lang.String location)
        Basic constructor only allowing you to specify where to find the file.
        Parameters:
        location - Specified as my/classpath/loc.txt
      • ClasspathResource

        public ClasspathResource​(java.lang.String location,
                                 boolean preCache)
        Advanced constructor which allows you to optionally pre-cache the data
        Parameters:
        location - Specified as my/classpath/loc.txt
        preCache - If set to true will cause the data to be copied to an in memory byte array and then an InputStream will be wrapped around that.
      • ClasspathResource

        public ClasspathResource​(java.lang.String location,
                                 boolean preCache,
                                 boolean isGzip)
        Advanced constructor which lets you set the preCache variable and to force the type of file we are decompressing. If this constructor is used we trust your call as to the file's compression status.
        Parameters:
        location - Specified as my/classpath/loc.txt
        preCache - If set to true will cause the data to be copied to an in memory byte array and then an InputStream will be wrapped around that.
        isGzip - Set to true or false if the file is gziped.
    • Method Detail

      • getInputStream

        public java.io.InputStream getInputStream()
        Returns the InputStream instance of this classpath resource
      • getBufferedReader

        public java.io.BufferedReader getBufferedReader()
        Returns the reader representation of this classpath resource
      • getList

        public java.util.List<java.lang.String> getList()
        Returns this resource as a list of Strings