Package org.astrogrid.samp.util
Class ResourceType
- java.lang.Object
-
- org.astrogrid.samp.util.ResourceType
-
public abstract class ResourceType extends java.lang.ObjectDefines 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
Fields Modifier and Type Field Description private java.lang.String[]ctypes_private static java.util.logging.Loggerlogger_private static intMAGIC_SIZEprivate java.lang.Stringmtype_private java.lang.Stringname_private static ResourceType[]RESOURCE_TYPESstatic ResourceTypeRTYPE_CDFResource type for table.load.cdf.static ResourceTypeRTYPE_FITSResource type for image.load.fits.static ResourceTypeRTYPE_VOTABLEResource type for table.load.votable.
-
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 private static ResourceTypecreateCdfTableResourceType()Returns a ResourceType instance suitable for the table.load.cdf SAMP Mtype.private static ResourceTypecreateFitsImageResourceType()Returns a ResourceType instance suitable for the image.load.fits SAMP MType.MessagecreateMessage(java.net.URL url)Returns a Message object that will forward a given URL to SAMP clients.private static ResourceTypecreateVOTableResourceType()Returns a ResourceType instance suitable for the table.load.votable SAMP MType.static ResourceType[]getKnownResourceTypes()Returns the known resource types.private static ResourceTypegetMagicResourceType(byte[] magic)Try to identify a resource type from its magic number.private static ResourceTypegetMimeResourceType(java.lang.String contentType)Try to identify a resource type from its MIME type.java.lang.StringgetMType()Returns the MType of the message to be constructed.java.lang.StringgetName()Returns the name of this resource type.booleanisContentType(java.lang.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 ResourceTypereadContentResourceType(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 ResourceTypereadHeadResourceType(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.StringtoString()
-
-
-
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
-
MAGIC_SIZE
private static final int MAGIC_SIZE
- See Also:
- Constant Field Values
-
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 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 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:
toStringin classjava.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
-
-