- Content type class java
- ContentType
- ContentType
- ContentType
- getPrimaryType
- getSubType
- getBaseType
- getParameter
- getParameterList
- setPrimaryType
- setSubType
- setParameter
- setParameterList
- toString
- match
- match
- Annotation Interface ContentType
- Content type class java
- Constructor Summary
- Method Summary
- Methods inherited from class java.lang.Object
- Constructor Detail
- ContentType
- ContentType
- ContentType
- Method Detail
- getPrimaryType
- getSubType
- getBaseType
- getParameter
- getParameterList
- setPrimaryType
- setSubType
- setParameter
- setParameterList
- toString
- match
- match
- Content type class java
- Constructor Summary
- Method Summary
- Methods inherited from class java.lang.Object
- Constructor Detail
- ContentType
- ContentType
- ContentType
- Method Detail
- getPrimaryType
- getSubType
- getBaseType
- getParameter
- getParameterList
- setPrimaryType
- setSubType
- setParameter
- setParameterList
- toString
- match
- match
- Content type class java
- Class ContentType
- Field Summary
- Method Summary
- Methods inherited from class java.lang.Object
- Field Detail
- APPLICATION_ATOM_XML
- APPLICATION_FORM_URLENCODED
- APPLICATION_JSON
- APPLICATION_NDJSON
- APPLICATION_OCTET_STREAM
- APPLICATION_PDF
- APPLICATION_SOAP_XML
- APPLICATION_SVG_XML
- APPLICATION_XHTML_XML
- APPLICATION_XML
- APPLICATION_PROBLEM_JSON
- APPLICATION_PROBLEM_XML
- APPLICATION_RSS_XML
- IMAGE_BMP
- IMAGE_GIF
Content type class java
This class represents a MIME ContentType value. It provides methods to parse a ContentType string into individual components and to generate a MIME style ContentType string.
Constructor Summary | |
---|---|
ContentType () No-arg Constructor. | |
ContentType (java.lang.String s) Constructor that takes a Content-Type string. | |
ContentType (java.lang.String primaryType, java.lang.String subType, ParameterList list) Constructor. |
Method Summary | |
---|---|
java.lang.String | getBaseType () Return the MIME type string, without the parameters. |
java.lang.String | getParameter (java.lang.String name) Return the specified parameter value. |
ParameterList | getParameterList () Return a ParameterList object that holds all the available parameters. |
java.lang.String | getPrimaryType () Return the primary type. |
java.lang.String | getSubType () Return the subType. |
boolean | match (ContentType cType) Match with the specified ContentType object. |
boolean | match (java.lang.String s) Match with the specified content-type string. |
void | setParameter (java.lang.String name, java.lang.String value) Set the specified parameter. |
void | setParameterList (ParameterList list) Set a new ParameterList. |
void | setPrimaryType (java.lang.String primaryType) Set the primary type. |
void | setSubType (java.lang.String subType) Set the subType. |
java.lang.String | toString () Retrieve a RFC2045 style string representation of this Content-Type. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
ContentType
ContentType
Parameters: primaryType — primary type subType — subType list — ParameterList
ContentType
Constructor that takes a Content-Type string. The String is parsed into its constituents: primaryType, subType and parameters. A ParseException is thrown if the parse fails.
Parameters: s — the Content-Type string. Throws: ParseException — if the parse fails.
Method Detail |
---|
getPrimaryType
public java.lang.String getPrimaryType()
getSubType
public java.lang.String getSubType()
getBaseType
public java.lang.String getBaseType()
Return the MIME type string, without the parameters. The returned value is basically the concatenation of the primaryType, the ‘/’ character and the secondaryType.
getParameter
public java.lang.String getParameter(java.lang.String name)
getParameterList
Return a ParameterList object that holds all the available parameters. Returns null if no parameters are available.
setPrimaryType
public void setPrimaryType(java.lang.String primaryType)
Parameters: primaryType — primary type
setSubType
public void setSubType(java.lang.String subType)
Parameters: subType — the subType
setParameter
public void setParameter(java.lang.String name, java.lang.String value)
Parameters: name — parameter name value — parameter value
setParameterList
Parameters: list — ParameterList
toString
public java.lang.String toString()
Retrieve a RFC2045 style string representation of this Content-Type. Returns null if the conversion failed.
Overrides: toString in class java.lang.Object Returns: RFC2045 style string
match
Match with the specified ContentType object. This method compares only the primaryType and subType . The parameters of both operands are ignored.
For example, this method will return true when comparing the ContentTypes for «text/plain» and «text/plain; charset=foobar». If the subType of either operand is the special character ‘*’, then the subtype is ignored during the match. For example, this method will return true when comparing the ContentTypes for «text/plain» and «text/*»
Parameters: cType — ContentType to compare this against
match
public boolean match(java.lang.String s)
Match with the specified content-type string. This method compares only the primaryType and subType . The parameters of both operands are ignored.
For example, this method will return true when comparing the ContentType for «text/plain» with «text/plain; charset=foobar». If the subType of either operand is the special character ‘*’, then the subtype is ignored during the match. For example, this method will return true when comparing the ContentType for «text/plain» with «text/*»
| ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Copyright © 2009-2011, Oracle Corporation and/or its affiliates. All Rights Reserved. Use is subject to license terms.
Generated on 10-February-2011 12:41
Annotation Interface ContentType
Meta annotation, specifies that an annotation represents a content type, such as a time span or a frequency.
The following example shows how a temperature content type can be created and used.
First declare a temperature annotation using the ContentType annotation:
@MetadataDefinition @ContentType @Name("com.example.Temperature") @Label("Temperature") @Target(ElementType.FIELD) @Retention(RetentionPolicy.RUNTIME) public @interface Temperature
@Name("com.example.CPU") @Label("CPU") @Category(< "Hardware", "CPU" >) @Period("1 s") @StackTrace(false) static public class CPUEvent extends Event < @Label("ID") String id; @Temperature(Temperature.KELVIN) @Label("Temperature") float temperature; >public static void main(String. args) throws InterruptedException < FlightRecorder.addPeriodicEvent(CPUEvent.class, () -> < for (var cpu : listCPUs()) < CPUEvent event = new CPUEvent(); event.id = cpu.id(); event.temperature = cpu.temperature(); // in Kelvin event.commit(); >>); Thread.sleep(10_000); >
void printTemperaturesInCelsius(Path file) throws IOException < for (RecordedEvent event : RecordingFile.readAllEvents(file)) < for (ValueDescriptor field : event.getEventType().getFields()) < for (AnnotationElement ae : field.getAnnotationElements()) < ContentType type = ae.getAnnotation(ContentType.class); if (type != null) < if (ae.getTypeName().equals("com.example.Temperature")) < double value = event.getDouble(field.getName()); String unit = (String) ae.getValue("value"); double celsius = switch (unit) < case "CELSIUS" ->value; case "KELVIN" -> value - 273.15; case "FAHRENHEIT" -> (value - 32) / 1.8; default -> throw new IllegalStateException("Unknown temperature unit '" + unit + "'"); >; System.out.println(celsius + " C"); > else < System.err.println("Can't format content type " + ae.getTypeName() + " for field " + field.getName()); >> > > > >
Report a bug or suggest an enhancement
For further API reference and developer documentation see the Java SE Documentation, which contains more detailed, developer-targeted descriptions with conceptual overviews, definitions of terms, workarounds, and working code examples. Other versions.
Java is a trademark or registered trademark of Oracle and/or its affiliates in the US and other countries.
Copyright © 1993, 2023, Oracle and/or its affiliates, 500 Oracle Parkway, Redwood Shores, CA 94065 USA.
All rights reserved. Use is subject to license terms and the documentation redistribution policy.
Content type class java
This class represents a MIME Content-Type value. It provides methods to parse a Content-Type string into individual components and to generate a MIME style Content-Type string.
Constructor Summary
Method Summary
Methods inherited from class java.lang.Object
Constructor Detail
ContentType
ContentType
public ContentType(String primaryType, String subType, ParameterList list)
ContentType
Constructor that takes a Content-Type string. The String is parsed into its constituents: primaryType, subType and parameters. A ParseException is thrown if the parse fails.
Method Detail
getPrimaryType
getSubType
getBaseType
Return the MIME type string, without the parameters. The returned value is basically the concatenation of the primaryType, the ‘/’ character and the secondaryType.
getParameter
getParameterList
Return a ParameterList object that holds all the available parameters. Returns null if no parameters are available.
setPrimaryType
setSubType
setParameter
setParameterList
toString
Retrieve a RFC2045 style string representation of this Content-Type. Returns an empty string if the conversion failed.
match
Match with the specified ContentType object. This method compares only the primaryType and subType . The parameters of both operands are ignored. For example, this method will return true when comparing the ContentTypes for «text/plain» and «text/plain; charset=foobar». If the subType of either operand is the special character ‘*’, then the subtype is ignored during the match. For example, this method will return true when comparing the ContentTypes for «text/plain» and «text/*»
match
Match with the specified content-type string. This method compares only the primaryType and subType . The parameters of both operands are ignored. For example, this method will return true when comparing the ContentType for «text/plain» with «text/plain; charset=foobar». If the subType of either operand is the special character ‘*’, then the subtype is ignored during the match. For example, this method will return true when comparing the ContentType for «text/plain» with «text/*»
Content type class java
This class represents a MIME Content-Type value. It provides methods to parse a Content-Type string into individual components and to generate a MIME style Content-Type string.
Constructor Summary
Method Summary
Methods inherited from class java.lang.Object
Constructor Detail
ContentType
ContentType
public ContentType(String primaryType, String subType, ParameterList list)
ContentType
Constructor that takes a Content-Type string. The String is parsed into its constituents: primaryType, subType and parameters. A ParseException is thrown if the parse fails.
Method Detail
getPrimaryType
getSubType
getBaseType
Return the MIME type string, without the parameters. The returned value is basically the concatenation of the primaryType, the ‘/’ character and the secondaryType.
getParameter
getParameterList
Return a ParameterList object that holds all the available parameters. Returns null if no parameters are available.
setPrimaryType
setSubType
setParameter
setParameterList
toString
Retrieve a RFC2045 style string representation of this Content-Type. Returns an empty string if the conversion failed.
match
Match with the specified ContentType object. This method compares only the primaryType and subType . The parameters of both operands are ignored. For example, this method will return true when comparing the ContentTypes for «text/plain» and «text/plain; charset=foobar». If the subType of either operand is the special character ‘*’, then the subtype is ignored during the match. For example, this method will return true when comparing the ContentTypes for «text/plain» and «text/*»
match
Match with the specified content-type string. This method compares only the primaryType and subType . The parameters of both operands are ignored. For example, this method will return true when comparing the ContentType for «text/plain» with «text/plain; charset=foobar». If the subType of either operand is the special character ‘*’, then the subtype is ignored during the match. For example, this method will return true when comparing the ContentType for «text/plain» with «text/*»
Content type class java
Class ContentType
@Contract(threading=IMMUTABLE) public final class ContentType extends Object implements Serializable
Content type information consisting of a MIME type and an optional charset. This class makes no attempts to verify validity of the MIME type. The input parameters of the create(String, String) method, however, may not contain characters , , reserved by the HTTP specification.
Field Summary
Modifier and Type | Field and Description |
---|---|
static ContentType | APPLICATION_ATOM_XML |
static ContentType | APPLICATION_FORM_URLENCODED |
static ContentType | APPLICATION_JSON |
static ContentType | APPLICATION_NDJSON |
Method Summary
Generates textual representation of this content type which can be used as the value of a Content-Type header.
Methods inherited from class java.lang.Object
Field Detail
APPLICATION_ATOM_XML
APPLICATION_FORM_URLENCODED
public static final ContentType APPLICATION_FORM_URLENCODED