Package org.astrogrid.samp.util
Class ResourceType
java.lang.Object
org.astrogrid.samp.util.ResourceType
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 Summary
FieldsModifier and TypeFieldDescriptionstatic final ResourceTypeResource type for table.load.cdf.static final ResourceTypeResource type for image.load.fits.static final ResourceTypeResource type for table.load.votable. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncreateMessage(URL url) Returns a Message object that will forward a given URL to SAMP clients.static ResourceType[]Returns the known resource types.getMType()Returns the MType of the message to be constructed.getName()Returns the name of this resource type.booleanisContentType(String ctype) Indicates whether this resource type is suitable for use with a given MIME type.abstract booleanisMagic(byte[] magic) Indicates whether this resource type is suitable for use with a resource having a given magic number.static ResourceTypeAttempts to determine the resource type of a given URL by downloading the first part of its content and examining the magic number.static ResourceTypereadHeadResourceType(URL url) Attempts to determine the resource type of a given URL by making an HTTP HEAD request and looking at the Content-Type.toString()
-
Field Details
-
RTYPE_VOTABLE
Resource type for table.load.votable. -
RTYPE_FITS
Resource type for image.load.fits. -
RTYPE_CDF
Resource type for table.load.cdf.
-
-
Constructor Details
-
ResourceType
Constructor.- Parameters:
name- identifying namemtype- MType of message that will be sentctypes- MIME-types to which this corresponds, supplied in normalised form (lower case, no parameters, no whitespace)
-
-
Method Details
-
getMType
Returns the MType of the message to be constructed.- Returns:
- MType string
-
createMessage
Returns a Message object that will forward a given URL to SAMP clients.- Parameters:
url- URL of resource- Returns:
- message instance
-
isContentType
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
Returns the name of this resource type.- Returns:
- name
-
toString
-
getKnownResourceTypes
Returns the known resource types.- Returns:
- known instances of this class
-
readHeadResourceType
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
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
-