Class DefaultResourceRetriever

java.lang.Object
com.itextpdf.io.resolver.resource.DefaultResourceRetriever
All Implemented Interfaces:
IAdvancedResourceRetriever, IResourceRetriever

public class DefaultResourceRetriever extends Object implements IAdvancedResourceRetriever
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.
  • Constructor Details

    • 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 Details

    • 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
    • getConnectTimeout

      public int getConnectTimeout()
      Gets the connect timeout.

      The connect timeout is used to create input stream with a limited time to establish connection to resource.

      Returns:
      the connect timeout in milliseconds
    • setConnectTimeout

      public IResourceRetriever setConnectTimeout (int connectTimeout)
      Sets the connect timeout.

      The connect timeout is used to create input stream with a limited time to establish connection to resource.

      Parameters:
      connectTimeout - the connect timeout in milliseconds
      Returns:
      the IResourceRetriever instance
    • getRequestHeaders

      public Map<String,String> getRequestHeaders()
      Gets the request headers to use in the request.
      Returns:
      the request headers to use in the request
    • setRequestHeaders

      public void setRequestHeaders (Map<String,String> headers)
      Sets the request headers to use in the request.
      Parameters:
      headers - the request headers to use in the request
    • getReadTimeout

      public int getReadTimeout()
      Gets the read timeout.

      The read timeout is used to create input stream with a limited time to receive data from resource.

      Returns:
      the read timeout in milliseconds
    • setReadTimeout

      public IResourceRetriever setReadTimeout (int readTimeout)
      Sets the read timeout.

      The read timeout is used to create input stream with a limited time to receive data from resource.

      Parameters:
      readTimeout - the read timeout in milliseconds
      Returns:
      the IResourceRetriever instance
    • getInputStreamByUrl

      public InputStream getInputStreamByUrl (URL url) throws IOException
      Gets the InputStream with the data from a provided URL by instantiating an HTTP connection to the URL.
      Specified by:
      getInputStreamByUrl in interface IResourceRetriever
      Parameters:
      url - the source URL
      Returns:
      the input stream with the retrieved data
      Throws:
      IOException - if any input/output issue occurs
    • getByteArrayByUrl

      public byte[] getByteArrayByUrl (URL url) throws IOException
      Gets the byte array with the data from a provided URL by instantiating an HTTP connection to the URL.
      Specified by:
      getByteArrayByUrl in interface IResourceRetriever
      Parameters:
      url - the source URL
      Returns:
      the byte array with the retrieved data
      Throws:
      IOException - if any input/output issue occurs
    • get

      public InputStream get (URL url, byte[] request, Map<String,String> headers) throws IOException
      Gets the InputStream with the data from a provided URL by instantiating an HTTP connection to the URL.
      Specified by:
      get in interface IAdvancedResourceRetriever
      Parameters:
      url - the source URL
      request - data to send to the URL
      headers - HTTP headers to set for the outgoing connection
      Returns:
      the input stream with the retrieved data
      Throws:
      IOException - if any input/output issue occurs
    • urlFilter

      protected boolean urlFilter (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