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
    • Field Detail

      • name_

        private final java.lang.String name_
      • mtype_

        private final java.lang.String mtype_
      • ctypes_

        private final java.lang.String[] ctypes_
      • 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.
      • RESOURCE_TYPES

        private static final ResourceType[] RESOURCE_TYPES
      • logger_

        private static final java.util.logging.Logger logger_
    • 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
      • getMimeResourceType

        private static ResourceType getMimeResourceType​(java.lang.String contentType)
        Try to identify a resource type from its MIME type.
        Parameters:
        contentType - content-type header
        Returns:
        resource type, or null if not known
      • getMagicResourceType

        private static ResourceType getMagicResourceType​(byte[] magic)
        Try to identify a resource type from its magic number.
        Parameters:
        magic - buffer containing first few bytes of resource content
        Returns:
        resource type, or null if not known
      • createVOTableResourceType

        private static ResourceType createVOTableResourceType()
        Returns a ResourceType instance suitable for the table.load.votable SAMP MType.
        Returns:
        VOTable resource type
      • createFitsImageResourceType

        private static ResourceType createFitsImageResourceType()
        Returns a ResourceType instance suitable for the image.load.fits SAMP MType.
        Returns:
        FITS image resource type
      • createCdfTableResourceType

        private static ResourceType createCdfTableResourceType()
        Returns a ResourceType instance suitable for the table.load.cdf SAMP Mtype.
        Returns:
        CDF table resource type