Class ParsedURLData

java.lang.Object
io.sf.carte.echosvg.util.ParsedURLData
All Implemented Interfaces:
Serializable

public class ParsedURLData extends Object implements Serializable
Holds the data for more URLs.

WARNING: Beware that several of the public fields will be made package-visible in the future. Please use the getters and setters instead.

See Also:
  • Field Details

    • HTTP_USER_AGENT_HEADER

      protected static final String HTTP_USER_AGENT_HEADER
      See Also:
    • HTTP_ACCEPT_HEADER

      protected static final String HTTP_ACCEPT_HEADER
      See Also:
    • HTTP_ACCEPT_LANGUAGE_HEADER

      protected static final String HTTP_ACCEPT_LANGUAGE_HEADER
      See Also:
    • HTTP_ACCEPT_ENCODING_HEADER

      protected static final String HTTP_ACCEPT_ENCODING_HEADER
      See Also:
    • acceptedEncodings

      protected static List<String> acceptedEncodings
    • GZIP_MAGIC

      public static final byte[] GZIP_MAGIC
      GZIP header magic number bytes, like found in a gzipped files, which are encoded in Intel format (i.e. little indian).
    • protocol

      public String protocol
    • host

      public String host
    • port

      public int port
    • path

      public String path
    • ref

      public String ref
    • contentType

      public String contentType
    • contentEncoding

      public String contentEncoding
    • stream

      public transient InputStream stream
    • hasBeenOpened

      public transient boolean hasBeenOpened
    • contentTypeMediaType

      protected String contentTypeMediaType
      The extracted type/subtype from the Content-Type header.
    • contentTypeCharset

      protected String contentTypeCharset
      The extracted charset parameter from the Content-Type header.
    • postConnectionURL

      protected URL postConnectionURL
      The URL that was ultimately used to fetch the resource.
  • Constructor Details

    • ParsedURLData

      public ParsedURLData()
      Void constructor
    • ParsedURLData

      public ParsedURLData(URL url)
      Build from an existing URL.
  • Method Details

    • checkGZIP

      public static InputStream checkGZIP(InputStream is) throws IOException
      This is a utility function others can call that checks if is is a GZIP stream if so it returns a GZIPInputStream that will decode the contents, otherwise it returns (or a buffered version of is) untouched.
      Parameters:
      is - Stream that may potentially be a GZIP stream.
      Throws:
      IOException
    • buildURL

      protected URL buildURL() throws MalformedURLException
      Attempts to build a normal java.net.URL instance from this URL.
      Throws:
      MalformedURLException
    • getConnectTimeout

      public static int getConnectTimeout()
      Gets the connect timeout.
      Returns:
      the connect timeout.
    • setConnectTimeout

      public static void setConnectTimeout(int connectTimeout)
      Sets the connect timeout.

      Default is 10 seconds.

      Parameters:
      connectTimeout - the connect timeout.
      Throws:
      IllegalArgumentException - if the argument is negative.
    • getReadTimeout

      public static int getReadTimeout()
      Gets the read timeout.
      Returns:
      the read timeout.
    • setReadTimeout

      public static void setReadTimeout(int readTimeout)
      Sets the read timeout.
      Parameters:
      readTimeout - the read timeout.
      Throws:
      IllegalArgumentException - if the argument is negative.
    • hashCode

      public int hashCode()
      Implement Object.hashCode.
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Implement Object.equals for ParsedURLData.
      Overrides:
      equals in class Object
    • getContentType

      public String getContentType(String userAgent)
      Returns the content type if available. This is only available for some protocols.
    • getContentTypeMediaType

      public String getContentTypeMediaType(String userAgent)
      Returns the content type's type/subtype, if available. This is only available for some protocols.
    • getContentTypeCharset

      public String getContentTypeCharset(String userAgent)
      Returns the content type's charset parameter, if available. This is only available for some protocols.
    • hasContentTypeParameter

      public boolean hasContentTypeParameter(String userAgent, String param)
      Returns whether the Content-Type header has the given parameter.
    • extractContentTypeParts

      protected void extractContentTypeParts(String userAgent)
      Extracts the type/subtype and charset parameter from the Content-Type header.
    • getContentEncoding

      public String getContentEncoding(String userAgent)
      Returns the content encoding if available. This is only available for some protocols.
    • getHost

      public String getHost()
      Get the host part of the URL.
      Returns:
      the host, or null if there is no host.
    • setHost

      public void setHost(String host)
    • getPort

      public int getPort()
      Get the port.
      Returns:
      the port number, or -1 if the default port.
    • setPort

      public void setPort(int port)
      Set the port number.
      Parameters:
      port - the port number, or -1 for the default.
    • getProtocol

      public String getProtocol()
    • getPath

      public String getPath()
      Get the path of this URL.
      Returns:
      the path, or null if there is no path.
    • setPath

      public void setPath(String path)
      Sets the path of this URL.
      Parameters:
      path - the path, or null for no path.
    • getRef

      public String getRef()
    • setRef

      public void setRef(String ref)
    • complete

      public boolean complete()
      Returns true if the URL looks well formed and complete. This does not guarantee that the stream can be opened but is a good indication that things aren't totally messed up.
    • openStream

      public InputStream openStream(String userAgent, Iterator<String> mimeTypes) throws IOException
      Open the stream and check for common compression types. If the stream is found to be compressed with a standard compression type it is automatically decompressed.
      Parameters:
      userAgent - The user agent opening the stream (may be null).
      mimeTypes - The expected mime types of the content in the returned InputStream (mapped to Http accept header among other possability). The elements of the iterator must be strings (may be null)
      Throws:
      IOException
    • openStreamRaw

      public InputStream openStreamRaw(String userAgent, Iterator<String> mimeTypes) throws IOException
      Open the stream and returns it. No checks are made to see if the stream is compressed or encoded in any way.
      Parameters:
      userAgent - The user agent opening the stream (may be null).
      mimeTypes - The expected mime types of the content in the returned InputStream (mapped to Http accept header among other possability). The elements of the iterator must be strings (may be null)
      Throws:
      IOException
    • openStreamInternal

      protected InputStream openStreamInternal(String userAgent, Iterator<String> mimeTypes, Iterator<String> encodingTypes) throws IOException
      Throws:
      IOException
    • getPortStr

      public String getPortStr()
      Returns the URL up to and include the port number on the host. Does not include the path or fragment pieces.
    • sameFile

      protected boolean sameFile(ParsedURLData other)
    • toString

      public String toString()
      Return a string representation of the data.
      Overrides:
      toString in class Object
    • getPostConnectionURL

      public String getPostConnectionURL()
      Returns the URL that was ultimately used to fetch the resource represented by the ParsedURL.