Class UrlResource

java.lang.Object
org.jmxtrans.agent.util.io.AbstractResource
org.jmxtrans.agent.util.io.UrlResource
All Implemented Interfaces:
Resource

public class UrlResource
extends AbstractResource
implements Resource
Resource for http://..., https://... or file://....
Author:
Cyrille Le Clerc
  • Field Summary

    Fields
    Modifier and Type Field Description
    protected Logger logger  
  • Constructor Summary

    Constructors
    Constructor Description
    UrlResource​(java.lang.String url)  
  • Method Summary

    Modifier and Type Method Description
    protected void configureUrlConnection​(java.net.URLConnection conn)  
    boolean exists()
    This implementation checks whether a File can be opened, falling back to whether an InputStream can be opened.
    java.lang.String getDescription()
    Return a description for this resource, to be used for error output when working with the resource.
    java.io.File getFile()
    Return a File handle for this resource.
    java.io.InputStream getInputStream()
    Return an InputStream.
    long lastModified()
    Determine the last-modified timestamp for this resource.

    Methods inherited from class org.jmxtrans.agent.util.io.AbstractResource

    getURI, getURL, toString

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

    Methods inherited from interface org.jmxtrans.agent.util.io.Resource

    getURI, getURL
  • Field Details

    • logger

      protected final Logger logger
  • Constructor Details

    • UrlResource

      public UrlResource​(@Nonnull java.lang.String url)
  • Method Details

    • getFile

      @Nonnull public java.io.File getFile()
      Description copied from interface: Resource
      Return a File handle for this resource.
      Specified by:
      getFile in interface Resource
      Overrides:
      getFile in class AbstractResource
    • exists

      public boolean exists()
      Description copied from class: AbstractResource
      This implementation checks whether a File can be opened, falling back to whether an InputStream can be opened. This will cover both directories and content resources.
      Specified by:
      exists in interface Resource
      Overrides:
      exists in class AbstractResource
    • lastModified

      public long lastModified()
      Description copied from interface: Resource
      Determine the last-modified timestamp for this resource.
      Specified by:
      lastModified in interface Resource
      Overrides:
      lastModified in class AbstractResource
    • configureUrlConnection

      protected void configureUrlConnection​(java.net.URLConnection conn)
    • getInputStream

      @Nonnull public java.io.InputStream getInputStream()
      Description copied from interface: Resource
      Return an InputStream.

      It is expected that each call creates a fresh stream.

      Specified by:
      getInputStream in interface Resource
      Returns:
      the input stream for the underlying resource (must not be null)
    • getDescription

      public java.lang.String getDescription()
      Description copied from interface: Resource
      Return a description for this resource, to be used for error output when working with the resource.

      Implementations are also encouraged to return this value from their toString method.

      Specified by:
      getDescription in interface Resource
      See Also:
      Object.toString()