Class DefaultResourceRetriever

  • All Implemented Interfaces:
    IResourceRetriever

    public class DefaultResourceRetriever
    extends java.lang.Object
    implements IResourceRetriever
    Default implementation of the IResourceRetriever interface, which can set a limit on the size of retrieved resources using input stream with a limit on the number of bytes read.
    • Field Detail

      • logger

        private static final org.slf4j.Logger logger
      • resourceSizeByteLimit

        private long resourceSizeByteLimit
    • Constructor Detail

      • DefaultResourceRetriever

        public DefaultResourceRetriever()
        Creates a new DefaultResourceRetriever instance. The limit on the size of retrieved resources is by default equal to Long.MAX_VALUE bytes.
    • Method Detail

      • getResourceSizeByteLimit

        public long getResourceSizeByteLimit()
        Gets the resource size byte limit. The resourceSizeByteLimit is used to create input stream with a limit on the number of bytes read.
        Returns:
        the resource size byte limit
      • setResourceSizeByteLimit

        public IResourceRetriever setResourceSizeByteLimit​(long resourceSizeByteLimit)
        Sets the resource size byte limit. The resourceSizeByteLimit is used to create input stream with a limit on the number of bytes read.
        Parameters:
        resourceSizeByteLimit - the resource size byte limit
        Returns:
        the IResourceRetriever instance
      • getInputStreamByUrl

        public java.io.InputStream getInputStreamByUrl​(java.net.URL url)
                                                throws java.io.IOException
        Gets the input stream with current limit on the number of bytes read, that connect with source URL for retrieving data from that connection.
        Specified by:
        getInputStreamByUrl in interface IResourceRetriever
        Parameters:
        url - the source URL
        Returns:
        the limited input stream or null if the URL was filtered
        Throws:
        java.io.IOException - if any input/output issue occurs
      • getByteArrayByUrl

        public byte[] getByteArrayByUrl​(java.net.URL url)
                                 throws java.io.IOException
        Gets the byte array that are retrieved from the source URL.
        Specified by:
        getByteArrayByUrl in interface IResourceRetriever
        Parameters:
        url - the source URL
        Returns:
        the byte array or null if the retrieving failed or the URL was filtered or the resourceSizeByteLimit was violated
        Throws:
        java.io.IOException - if any input/output issue occurs
      • urlFilter

        protected boolean urlFilter​(java.net.URL url)
        Method for filtering resources by URL. The default implementation allows for all URLs. Override this method if want to set filtering.
        Parameters:
        url - the source URL
        Returns:
        true if the resource can be retrieved and false otherwise