Package org.astrogrid.samp.util

# Class ResourceType

java.lang.Object
org.astrogrid.samp.util.ResourceType

public abstract class ResourceType extends 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 Summary

Fields
Modifier and Type
Field
Description
`static final ResourceType`
`RTYPE_CDF`
Resource type for table.load.cdf.
`static final ResourceType`
`RTYPE_FITS`
Resource type for image.load.fits.
`static final ResourceType`
`RTYPE_VOTABLE`
Resource type for table.load.votable.

## Constructor Summary

Constructors
Constructor
Description
`ResourceType(String name, String mtype, String[] ctypes)`
Constructor.

## Method Summary

Modifier and Type
Method
Description
`Message`
`createMessage(URL url)`
Returns a Message object that will forward a given URL to SAMP clients.
`static ResourceType[]`
`getKnownResourceTypes()`
Returns the known resource types.
`String`
`getMType()`
Returns the MType of the message to be constructed.
`String`
`getName()`
Returns the name of this resource type.
`boolean`
`isContentType(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(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(URL url)`
Attempts to determine the resource type of a given URL by making an HTTP HEAD request and looking at the Content-Type.
`String`
`toString()`

### Methods inherited from class java.lang.Object

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

## Field Details

### 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 Details

### ResourceType

public ResourceType(String name, String mtype, 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 Details

### getMType

public String getMType()
Returns the MType of the message to be constructed.

Returns:
  MType string

### createMessage

public Message createMessage(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(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 String getName()
Returns the name of this resource type.

Returns:
  name

### toString

public String toString()

Overrides:
  `toString` in class `Object`

### getKnownResourceTypes

public static ResourceType[] getKnownResourceTypes()
Returns the known resource types.

Returns:
  known instances of this class

### readHeadResourceType

public static ResourceType readHeadResourceType(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(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