Package net.sf.saxon.resource
Class ResourceLoader
java.lang.Object
net.sf.saxon.resource.ResourceLoader
The class provides a static method for loading resources from a URL.
This method follows HTTP 301 and 302 redirects.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic int
The maximum number of redirects to follow before throwing an IOException. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic BufferedReader
getReaderFromStream
(InputStream inputStream, String resourceEncoding) static URLConnection
urlConnection
(URL url) Open a URLConnection to the resource identified by the URI.static Reader
Open a reader to retrieve the content identified by the URI.static InputStream
Open a stream to retrieve the content identified by the URI.
-
Field Details
-
MAX_REDIRECTS
public static int MAX_REDIRECTSThe maximum number of redirects to follow before throwing an IOException. If you allow the underlying Java URL class to follow redirects, it gives up after 20 hops.
-
-
Constructor Details
-
ResourceLoader
public ResourceLoader()
-
-
Method Details
-
urlConnection
Open a URLConnection to the resource identified by the URI. For HTTP URIs, this method will follow up to MAX_REDIRECTS redirects or until it detects a loop; the connection returned in this case is to the first resource that did not return a 301 or 302 response code.- Parameters:
url
- The URL to retrieve.- Returns:
- An InputStream for the resource content.
- Throws:
IOException
- If more than MAX_REDIRECTS are occur or if a loop is detected.
-
urlStream
Open a stream to retrieve the content identified by the URI. For HTTP URIs, this method will follow up to MAX_REDIRECTS redirects or until it detects a loop. This method automatically accepts and decompresses gzip encoded responses.- Parameters:
url
- The URL to retrieve.- Returns:
- An InputStream for the resource content.
- Throws:
IOException
- If more than MAX_REDIRECTS are occur or if a loop is detected.
-
urlReader
Open a reader to retrieve the content identified by the URI. This handles HTTP redirects in the same way asurlStream(URL)
, but then it also wraps the stream in a Reader, using the logic prescribed for thefn:unparsed-text
function.- Parameters:
url
- The URL to retrieve.requestedEncoding
- The requested encoding. This is used only as a fallback, following the rules of thefn:unparsed-text
specification- Returns:
- A Reader for the resource content.
- Throws:
IOException
- If more than MAX_REDIRECTS are occur or if a loop is detected.
-
getReaderFromStream
public static BufferedReader getReaderFromStream(InputStream inputStream, String resourceEncoding) throws UnsupportedEncodingException - Throws:
UnsupportedEncodingException
-