Class ResourceType


  • public abstract class ResourceType
    extends java.lang.Object
    Defines one of the types of resource that can be turned into a SAMP load-type message.
    Since:
    21 Aug 2019
    Author:
    Mark Taylor
    • Constructor Summary

      Constructors 
      Constructor Description
      ResourceType​(java.lang.String name, java.lang.String mtype, java.lang.String[] ctypes)
      Constructor.
    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      Message createMessage​(java.net.URL url)
      Returns a Message object that will forward a given URL to SAMP clients.
      static ResourceType[] getKnownResourceTypes()
      Returns the known resource types.
      java.lang.String getMType()
      Returns the MType of the message to be constructed.
      java.lang.String getName()
      Returns the name of this resource type.
      boolean isContentType​(java.lang.String ctype)
      Indicates whether this resource type is suitable for use with a given MIME type.
      abstract boolean isMagic​(byte[] magic)
      Indicates whether this resource type is suitable for use with a resource having a given magic number.
      static ResourceType readContentResourceType​(java.net.URL url)
      Attempts to determine the resource type of a given URL by downloading the first part of its content and examining the magic number.
      static ResourceType readHeadResourceType​(java.net.URL url)
      Attempts to determine the resource type of a given URL by making an HTTP HEAD request and looking at the Content-Type.
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • RTYPE_VOTABLE

        public static final ResourceType RTYPE_VOTABLE
        Resource type for table.load.votable.
      • RTYPE_FITS

        public static final ResourceType RTYPE_FITS
        Resource type for image.load.fits.
      • RTYPE_CDF

        public static final ResourceType RTYPE_CDF
        Resource type for table.load.cdf.
    • Constructor Detail

      • ResourceType

        public ResourceType​(java.lang.String name,
                            java.lang.String mtype,
                            java.lang.String[] ctypes)
        Constructor.
        Parameters:
        name - identifying name
        mtype - MType of message that will be sent
        ctypes - MIME-types to which this corresponds, supplied in normalised form (lower case, no parameters, no whitespace)
    • Method Detail

      • getMType

        public java.lang.String getMType()
        Returns the MType of the message to be constructed.
        Returns:
        MType string
      • createMessage

        public Message createMessage​(java.net.URL url)
        Returns a Message object that will forward a given URL to SAMP clients.
        Parameters:
        url - URL of resource
        Returns:
        message instance
      • isContentType

        public boolean isContentType​(java.lang.String ctype)
        Indicates whether this resource type is suitable for use with a given MIME type. Note that the submitted content type may contain additional parameters and have embedded whitespace etc as permitted by RFC 2045.
        Parameters:
        ctype - content-type header value
        Returns:
        true iff this resource type is suitable for use with the given content type
      • isMagic

        public abstract boolean isMagic​(byte[] magic)
        Indicates whether this resource type is suitable for use with a resource having a given magic number.
        Parameters:
        magic - buffer containing the first few bytes of resource content
        Returns:
        true iff this resource type is suitable for use with the given content
      • getName

        public java.lang.String getName()
        Returns the name of this resource type.
        Returns:
        name
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • getKnownResourceTypes

        public static ResourceType[] getKnownResourceTypes()
        Returns the known resource types.
        Returns:
        known instances of this class
      • readHeadResourceType

        public static ResourceType readHeadResourceType​(java.net.URL url)
        Attempts to determine the resource type of a given URL by making an HTTP HEAD request and looking at the Content-Type.
        Parameters:
        url - resource location
        Returns:
        good guess at resource type, or null if can't be determined
      • readContentResourceType

        public static ResourceType readContentResourceType​(java.net.URL url)
        Attempts to determine the resource type of a given URL by downloading the first part of its content and examining the magic number.
        Parameters:
        url - resource location
        Returns:
        good guess at resource type, or null if it can't be determined