Class DefaultResourceRetriever
java.lang.Object
com.itextpdf.styledxmlparser.resolver.resource.DefaultResourceRetriever
- All Implemented Interfaces:
-
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.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbyte[]
getByteArrayByUrl
(URL url) Gets the byte array that are retrieved from the source URL.int
Gets the connect timeout.getInputStreamByUrl
(URL url) Gets the input stream with current limit on the number of bytes read, that connect with source URL for retrieving data from that connection.int
Gets the read timeout.long
Gets the resource size byte limit.setConnectTimeout
(int connectTimeout) Sets the connect timeout.setReadTimeout
(int readTimeout) Sets the read timeout.setResourceSizeByteLimit
(long resourceSizeByteLimit) Sets the resource size byte limit.protected boolean
Method for filtering resources by URL.
-
Constructor Details
-
DefaultResourceRetriever
public DefaultResourceRetriever()Creates a newDefaultResourceRetriever
instance. The limit on the size of retrieved resources is by default equal toLong.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
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
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
-
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
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
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 interfaceIResourceRetriever
- Parameters:
-
url
- the source URL - Returns:
- the limited input stream or null if the URL was filtered
- Throws:
-
IOException
- if any input/output issue occurs
-
getByteArrayByUrl
Gets the byte array that are retrieved from the source URL.- Specified by:
-
getByteArrayByUrl
in interfaceIResourceRetriever
- 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:
-
IOException
- if any input/output issue occurs
-
urlFilter
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
-