APIdia Launch Partner
Top Description Inners Fields Constructors Methods
javax.print

pack-priv Class MimeType

extends Object
implements Serializable, Cloneable
Class Inheritance
All Implemented Interfaces
java.lang.Cloneable, java.io.Serializable
Imports
java.io.Serial, .Serializable, java.util.AbstractMap, .AbstractSet, .ArrayList, .Iterator, .Map, .NoSuchElementException, .Set

Class MimeType encapsulates a Multipurpose Internet Mail Extensions (MIME) media type as defined in RFC 2045 and RFC 2046. A MIME type object is part of a DocFlavor object and specifies the format of the print data.

Class MimeType is similar to the like-named class in package java.awt.datatransfer. Class java.awt.datatransfer.MimeType is not used in the Jini Print Service API for two reasons:

  1. Since not all Java profiles include the AWT, the Jini Print Service should not depend on an AWT class.
  2. The implementation of class java.awt.datatransfer.MimeType does not guarantee that equivalent MIME types will have the same serialized representation. Thus, since the Jini Lookup Service (JLUS) matches service attributes based on equality of serialized representations, JLUS searches involving MIME types encapsulated in class java.awt.datatransfer.MimeType may incorrectly fail to match.
Class MimeType's serialized representation is based on the following canonical form of a MIME type string. Thus, two MIME types that are not identical but that are equivalent (that have the same canonical form) will be considered equal by the JLUS's matching algorithm.
Author
Alan Kaminsky
External Specification
https://www.rfc-editor.org/info/rfc2045, https://www.rfc-editor.org/info/rfc2046

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
MimeType.LexicalAnalyzer

Class for a lexical analyzer.

private class
MimeType.ParameterMap

Parameter map.

private class
MimeType.ParameterMapEntry

Parameter map entry.

private class
MimeType.ParameterMapEntrySet

Parameter map entry set.

private class
MimeType.ParameterMapEntrySetIterator

Parameter map entry set iterator.

Field Summary

Modifier and TypeField and Description
private static final int
private static final int
private transient MimeType.ParameterMapEntrySet
myEntrySet

Parameter map entry set.

private transient MimeType.ParameterMap
myParameterMap

Parameter map.

private String[]
myPieces

Array of strings that hold pieces of this MIME type's canonical form.

private transient String
myStringValue

String value for this MIME type.

private static final int
private static final long
serialVersionUID

Use serialVersionUID from JDK 1.4 for interoperability.

private static final int
private static final int

Constructor Summary

AccessConstructor and Description
public
MimeType(String
MIME media type string
s
)

Construct a new MIME type object from the given string.

Method Summary

Modifier and TypeMethod and Description
private static String

Returns:

the string surrounded by quotes and with interior quotes preceded by a backslash
addQuotes
(String
the string
s
)

Returns a version of the string surrounded by quotes and with interior quotes preceded by a backslash.

public boolean

Returns:

true if this MIME type object equals obj, false otherwise
equals
(Object
object to test
obj
)

Overrides java.lang.Object.equals.

Determine if this MIME type object is equal to the given object.

public String

Returns:

the media subtype
getMediaSubtype
()

Returns this MIME type object's media subtype.

public String

Returns:

the media type
getMediaType
()

Returns this MIME type object's media type.

public String

Returns:

the mime type
getMimeType
()

Returns this MIME type object's MIME type string based on the canonical form.

public Map<String, String>

Returns:

parameter map for this MIME type object
getParameterMap
()

Returns an unmodifiable map view of the parameters in this MIME type object.

private String

Returns:

the MIME type's string value in canonical form
getStringValue
()

Returns this MIME type's string value in canonical form.

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code for this MIME type object.

private void
parse(String
MIME media type string
s
)

Parses the given string into canonical pieces and stores the pieces in myPieces.

private static String

Returns:

the string with backslashes removed
removeBackslashes
(String
the string
s
)

Returns a version of the given string with backslashes removed.

public String

Returns:

MIME type string based on the canonical form. Each parameter value is enclosed in quotes.
toString
()

Overrides java.lang.Object.toString.

Converts this MIME type object to a string.

private static String

Returns:

the lowercase version of the string
toUnicodeLowerCase
(String
the string
s
)

Returns a lowercase version of the given string.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

EOF_LEXEMEback to summary
private static final int EOF_LEXEME
ILLEGAL_LEXEMEback to summary
private static final int ILLEGAL_LEXEME
myEntrySetback to summary
private transient MimeType.ParameterMapEntrySet myEntrySet

Parameter map entry set. Computed when needed and cached.

myParameterMapback to summary
private transient MimeType.ParameterMap myParameterMap

Parameter map. Computed when needed and cached.

myPiecesback to summary
private String[] myPieces

Array of strings that hold pieces of this MIME type's canonical form. If the MIME type has n parameters, n >= 0, then the strings in the array are:
Index 0 -- Media type.
Index 1 -- Media subtype.
Index 2i+2 -- Name of parameter i, i=0,1,...,n-1.
Index 2i+3 -- Value of parameter i, i=0,1,...,n-1.
Parameters are arranged in ascending order of parameter name.

myStringValueback to summary
private transient String myStringValue

String value for this MIME type. Computed when needed and cached.

QUOTED_STRING_LEXEMEback to summary
private static final int QUOTED_STRING_LEXEME
serialVersionUIDback to summary
private static final long serialVersionUID

Use serialVersionUID from JDK 1.4 for interoperability.

Annotations
@Serial
TOKEN_LEXEMEback to summary
private static final int TOKEN_LEXEME
TSPECIAL_LEXEMEback to summary
private static final int TSPECIAL_LEXEME

Constructor Detail

MimeTypeback to summary
public MimeType(String s)

Construct a new MIME type object from the given string. The given string is converted into canonical form and stored internally.

Parameters
s:String

MIME media type string

Exceptions
NullPointerException:
if s is null
IllegalArgumentException:
if s does not obey the syntax for a MIME media type string

Method Detail

addQuotesback to summary
private static String addQuotes(String s)

Returns a version of the string surrounded by quotes and with interior quotes preceded by a backslash.

Parameters
s:String

the string

Returns:String

the string surrounded by quotes and with interior quotes preceded by a backslash

equalsback to summary
public boolean equals(Object obj)

Overrides java.lang.Object.equals.

Determine if this MIME type object is equal to the given object. The two are equal if the given object is not null, is an instance of class javax.print.data.MimeType, and has the same canonical form as this MIME type object (that is, has the same type, subtype, and parameters). Thus, if two MIME type objects are the same except for comments, they are considered equal. However, "text/plain" and "text/plain; charset=us-ascii" are not considered equal, even though they represent the same media type (because the default character set for plain text is US-ASCII).

Parameters
obj:Object

object to test

Returns:boolean

true if this MIME type object equals obj, false otherwise

getMediaSubtypeback to summary
public String getMediaSubtype()

Returns this MIME type object's media subtype.

Returns:String

the media subtype

getMediaTypeback to summary
public String getMediaType()

Returns this MIME type object's media type.

Returns:String

the media type

getMimeTypeback to summary
public String getMimeType()

Returns this MIME type object's MIME type string based on the canonical form. Each parameter value is enclosed in quotes.

Returns:String

the mime type

getParameterMapback to summary
public Map<String, String> getParameterMap()

Returns an unmodifiable map view of the parameters in this MIME type object. Each entry in the parameter map view consists of a parameter name String (key) mapping to a parameter value String. If this MIME type object has no parameters, an empty map is returned.

Returns:Map<String, String>

parameter map for this MIME type object

getStringValueback to summary
private String getStringValue()

Returns this MIME type's string value in canonical form.

Returns:String

the MIME type's string value in canonical form

hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code for this MIME type object.

parseback to summary
private void parse(String s)

Parses the given string into canonical pieces and stores the pieces in myPieces.

Special rules applied:

  • If the media type is text, the value of a charset parameter is converted to lowercase.
Parameters
s:String

MIME media type string

Exceptions
NullPointerException:
if s is null
IllegalArgumentException:
if s does not obey the syntax for a MIME media type string
removeBackslashesback to summary
private static String removeBackslashes(String s)

Returns a version of the given string with backslashes removed.

Parameters
s:String

the string

Returns:String

the string with backslashes removed

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Converts this MIME type object to a string.

Returns:String

MIME type string based on the canonical form. Each parameter value is enclosed in quotes.

toUnicodeLowerCaseback to summary
private static String toUnicodeLowerCase(String s)

Returns a lowercase version of the given string. The lowercase version is constructed by applying Character.toLowerCase() to each character of the given string, which maps characters to lowercase using the rules of Unicode. This mapping is the same regardless of locale, whereas the mapping of String.toLowerCase() may be different depending on the default locale.

Parameters
s:String

the string

Returns:String

the lowercase version of the string

javax.print back to summary

private Class MimeType.LexicalAnalyzer

extends Object
Class Inheritance

Class for a lexical analyzer.

Field Summary

Modifier and TypeField and Description
protected int
protected int
protected int
protected int
protected String
protected int

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public String
public char
public int
public void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

myCurrentIndexback to summary
protected int myCurrentIndex
myLexemeBeginIndexback to summary
protected int myLexemeBeginIndex
myLexemeEndIndexback to summary
protected int myLexemeEndIndex
myLexemeTypeback to summary
protected int myLexemeType
mySourceback to summary
protected String mySource
mySourceLengthback to summary
protected int mySourceLength

Constructor Detail

LexicalAnalyzerback to summary
public LexicalAnalyzer(String theSource)

Method Detail

getLexemeback to summary
public String getLexeme()
getLexemeFirstCharacterback to summary
public char getLexemeFirstCharacter()
getLexemeTypeback to summary
public int getLexemeType()
nextLexemeback to summary
public void nextLexeme()
javax.print back to summary

private Class MimeType.ParameterMap

extends AbstractMap<String, String>
Class Inheritance

Parameter map.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public Set<Map.Entry<String, String>>
entrySet()

Implements abstract java.util.AbstractMap.entrySet.

Implements java.util.Map.entrySet.

Returns a Set view of the mappings contained in this map.

Inherited from java.util.AbstractMap:
clearclonecontainsKeycontainsValueequalsgethashCodeisEmptykeySetputputAllremovesizetoStringvalues

Constructor Detail

ParameterMapback to summary
private ParameterMap()

Method Detail

entrySetback to summary
public Set<Map.Entry<String, String>> entrySet()

Implements abstract java.util.AbstractMap.entrySet.

Implements java.util.Map.entrySet.

Doc from java.util.Map.entrySet.

Returns a Set view of the mappings contained in this map. The set is backed by the map, so changes to the map are reflected in the set, and vice-versa. If the map is modified while an iteration over the set is in progress (except through the iterator's own remove operation, or through the setValue operation on a map entry returned by the iterator) the results of the iteration are undefined. The set supports element removal, which removes the corresponding mapping from the map, via the Iterator.remove, Set.remove, removeAll, retainAll and clear operations. It does not support the add or addAll operations.

javax.print back to summary

private Class MimeType.ParameterMapEntry

extends Object
implements Map.Entry<String, String>
Class Inheritance
All Implemented Interfaces
java.util.Map.Entry

Parameter map entry.

Field Summary

Modifier and TypeField and Description
private int
myIndex

The index of the entry.

Constructor Summary

AccessConstructor and Description
public
ParameterMapEntry(int
the index of the entry
theIndex
)

Constructs a new parameter map entry.

Method Summary

Modifier and TypeMethod and Description
public boolean
equals(Object o)

Overrides java.lang.Object.equals.

Implements java.util.Map.Entry.equals.

Compares the specified object with this entry for equality.

public String
getKey()

Implements java.util.Map.Entry.getKey.

Returns the key corresponding to this entry.

public String
getValue()

Implements java.util.Map.Entry.getValue.

Returns the value corresponding to this entry.

public int
hashCode()

Overrides java.lang.Object.hashCode.

Implements java.util.Map.Entry.hashCode.

Returns the hash code value for this map entry.

public String
setValue(String value)

Implements java.util.Map.Entry.setValue.

Replaces the value corresponding to this entry with the specified value (optional operation).

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAlltoStringwaitwaitwait

Field Detail

myIndexback to summary
private int myIndex

The index of the entry.

Constructor Detail

ParameterMapEntryback to summary
public ParameterMapEntry(int theIndex)

Constructs a new parameter map entry.

Parameters
theIndex:int

the index of the entry

Method Detail

equalsback to summary
public boolean equals(Object o)

Overrides java.lang.Object.equals.

Implements java.util.Map.Entry.equals.

Doc from java.util.Map.Entry.equals.

Compares the specified object with this entry for equality. Returns true if the given object is also a map entry and the two entries represent the same mapping. More formally, two entries e1 and e2 represent the same mapping if

    (e1.getKey()==null ?
     e2.getKey()==null : e1.getKey().equals(e2.getKey()))  &&
    (e1.getValue()==null ?
     e2.getValue()==null : e1.getValue().equals(e2.getValue()))
This ensures that the equals method works properly across different implementations of the Map.Entry interface.
getKeyback to summary
public String getKey()

Implements java.util.Map.Entry.getKey.

Doc from java.util.Map.Entry.getKey.

Returns the key corresponding to this entry.

getValueback to summary
public String getValue()

Implements java.util.Map.Entry.getValue.

Doc from java.util.Map.Entry.getValue.

Returns the value corresponding to this entry. If the mapping has been removed from the backing map (by the iterator's remove operation), the results of this call are undefined.

hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Implements java.util.Map.Entry.hashCode.

Doc from java.util.Map.Entry.hashCode.

Returns the hash code value for this map entry. The hash code of a map entry e is defined to be:

    (e.getKey()==null   ? 0 : e.getKey().hashCode()) ^
    (e.getValue()==null ? 0 : e.getValue().hashCode())
This ensures that e1.equals(e2) implies that e1.hashCode()==e2.hashCode() for any two Entries e1 and e2, as required by the general contract of Object.hashCode.
setValueback to summary
public String setValue(String value)

Implements java.util.Map.Entry.setValue.

Doc from java.util.Map.Entry.setValue.

Replaces the value corresponding to this entry with the specified value (optional operation). (Writes through to the map.) The behavior of this call is undefined if the mapping has already been removed from the map (by the iterator's remove operation).

javax.print back to summary

private Class MimeType.ParameterMapEntrySet

extends AbstractSet<Map.Entry<String, String>>
Class Inheritance

Parameter map entry set.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public Iterator<Map.Entry<String, String>>
iterator()

Implements abstract java.util.AbstractCollection.iterator.

Implements java.util.Set.iterator, java.util.Collection.iterator.

Returns an iterator over the elements in this set.

public int
size()

Implements abstract java.util.AbstractCollection.size.

Implements java.util.Set.size, java.util.Collection.size.

Returns the number of elements in this set (its cardinality).

Inherited from java.util.AbstractSet:
equalshashCoderemoveAll

Constructor Detail

ParameterMapEntrySetback to summary
private ParameterMapEntrySet()

Method Detail

iteratorback to summary
public Iterator<Map.Entry<String, String>> iterator()

Implements abstract java.util.AbstractCollection.iterator.

Implements java.util.Set.iterator, java.util.Collection.iterator.

Doc from java.util.Set.iterator.

Returns an iterator over the elements in this set. The elements are returned in no particular order (unless this set is an instance of some class that provides a guarantee).

sizeback to summary
public int size()

Implements abstract java.util.AbstractCollection.size.

Implements java.util.Set.size, java.util.Collection.size.

Doc from java.util.Set.size.

Returns the number of elements in this set (its cardinality). If this set contains more than Integer.MAX_VALUE elements, returns Integer.MAX_VALUE.

javax.print back to summary

private Class MimeType.ParameterMapEntrySetIterator

extends Object
implements Iterator<Map.Entry<String, String>>
Class Inheritance
All Implemented Interfaces
java.util.Iterator

Parameter map entry set iterator.

Field Summary

Modifier and TypeField and Description
private int
myIndex

The current index of the iterator.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public boolean
hasNext()

Implements java.util.Iterator.hasNext.

Returns true if the iteration has more elements.

public Map.Entry<String, String>
next()

Implements java.util.Iterator.next.

Returns the next element in the iteration.

public void
remove()

Overrides default java.util.Iterator.remove.

Removes from the underlying collection the last element returned by this iterator (optional operation).

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

myIndexback to summary
private int myIndex

The current index of the iterator.

Constructor Detail

ParameterMapEntrySetIteratorback to summary
private ParameterMapEntrySetIterator()

Method Detail

hasNextback to summary
public boolean hasNext()

Implements java.util.Iterator.hasNext.

Doc from java.util.Iterator.hasNext.

Returns true if the iteration has more elements. (In other words, returns true if next would return an element rather than throwing an exception.)

nextback to summary
public Map.Entry<String, String> next()

Implements java.util.Iterator.next.

Doc from java.util.Iterator.next.

Returns the next element in the iteration.

removeback to summary
public void remove()

Overrides default java.util.Iterator.remove.

Doc from java.util.Iterator.remove.

Removes from the underlying collection the last element returned by this iterator (optional operation). This method can be called only once per call to next.

The behavior of an iterator is unspecified if the underlying collection is modified while the iteration is in progress in any way other than by calling this method, unless an overriding class has specified a concurrent modification policy.

The behavior of an iterator is unspecified if this method is called after a call to the forEachRemaining method.