Class DefaultResourceRetriever
- java.lang.Object
-
- com.itextpdf.styledxmlparser.resolver.resource.DefaultResourceRetriever
-
- All Implemented Interfaces:
IResourceRetriever
- Direct Known Subclasses:
NoDuplicatesResourceRetriever
public class DefaultResourceRetriever extends java.lang.Object implements IResourceRetriever
Default implementation of theIResourceRetrieverinterface, which can set a limit on the size of retrieved resources using input stream with a limit on the number of bytes read.
-
-
Field Summary
Fields Modifier and Type Field Description private intconnectTimeoutprivate static intDEFAULT_CONNECT_TIMEOUTprivate static intDEFAULT_READ_TIMEOUTprivate static org.slf4j.Loggerloggerprivate intreadTimeoutprivate longresourceSizeByteLimit
-
Constructor Summary
Constructors Constructor Description DefaultResourceRetriever()Creates a newDefaultResourceRetrieverinstance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description byte[]getByteArrayByUrl(java.net.URL url)Gets the byte array that are retrieved from the source URL.intgetConnectTimeout()Gets the connect timeout.java.io.InputStreamgetInputStreamByUrl(java.net.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.intgetReadTimeout()Gets the read timeout.longgetResourceSizeByteLimit()Gets the resource size byte limit.IResourceRetrieversetConnectTimeout(int connectTimeout)Sets the connect timeout.IResourceRetrieversetReadTimeout(int readTimeout)Sets the read timeout.IResourceRetrieversetResourceSizeByteLimit(long resourceSizeByteLimit)Sets the resource size byte limit.protected booleanurlFilter(java.net.URL url)Method for filtering resources by URL.
-
-
-
Field Detail
-
logger
private static final org.slf4j.Logger logger
-
resourceSizeByteLimit
private long resourceSizeByteLimit
-
connectTimeout
private int connectTimeout
-
readTimeout
private int readTimeout
-
DEFAULT_CONNECT_TIMEOUT
private static final int DEFAULT_CONNECT_TIMEOUT
- See Also:
- Constant Field Values
-
DEFAULT_READ_TIMEOUT
private static final int DEFAULT_READ_TIMEOUT
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
DefaultResourceRetriever
public DefaultResourceRetriever()
Creates a newDefaultResourceRetrieverinstance. The limit on the size of retrieved resources is by default equal toLong.MAX_VALUEbytes.
-
-
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
IResourceRetrieverinstance
-
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
IResourceRetrieverinstance
-
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
IResourceRetrieverinstance
-
getInputStreamByUrl
public java.io.InputStream getInputStreamByUrl(java.net.URL url) throws java.io.IOExceptionGets 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:
getInputStreamByUrlin interfaceIResourceRetriever- 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.IOExceptionGets the byte array that are retrieved from the source URL.- Specified by:
getByteArrayByUrlin 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:
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
-
-