javax.media
Class Format

java.lang.Object
  |
  +--javax.media.Format
Direct Known Subclasses:
AudioFormat, ContentDescriptor, VideoFormat

public class Format
extends java.lang.Object
implements java.lang.Cloneable, java.io.Serializable

A Format abstracts an exact media format. It carries no encoding-specific parameters or timing information global to the presentation.

Comparing different formats

Not all of the attributes in a Format object have to be specified. This enables selected attributes to be specified, making it possible to locate a supported Format that meets certain requirements without needing to find an exact match.

Two methods are provided for comparing Formats. The equals method returns true if two Format objects are exactly the same--they're the same type and all of their attributes are the same. The matches method relaxes the comparison, comparing only the attributes that are explicitly specified in the Format you are comparing.

Since:
JMF 2.0
See Also:
Serialized Form

Field Summary
static java.lang.Class byteArray
          The data object required by the Format is a byte array.
protected  java.lang.Class clz
           
protected  java.lang.Class dataType
           
protected  java.lang.String encoding
           
static int FALSE
           
static java.lang.Class formatArray
          The data object required by the Format is an array of Format objects.
static java.lang.Class intArray
          The data object required by the Format is an integer array.
static int NOT_SPECIFIED
           
static java.lang.Class shortArray
          The data object required by the Format is a short array.
static int TRUE
           
 
Constructor Summary
Format(java.lang.String encoding)
          Constructs a Format that has the specified encoding type.
Format(java.lang.String encoding, java.lang.Class dataType)
          Constructs a Format that has the specified encoding and data types.
 
Method Summary
 java.lang.Object clone()
          Creates a clone of this Format.
protected  void copy(Format f)
          Copies the attributes from the specified Format into this Format.
 boolean equals(java.lang.Object format)
          Checks whether or not the specified Format is the same as this Format.
 java.lang.Class getDataType()
          Gets the type of the data that this Format requires.
 java.lang.String getEncoding()
          Gets the uniquely-qualified encoding name for this Format.
 Format intersects(Format other)
          Intersects the attributes of this format and the specified format to create a new Format object.
 boolean matches(Format format)
          Checks whether or not the specified Format matches this Format.
 Format relax()
          Generate a format that's less restrictive than this format but contains the basic attributes that will make this resulting format useful for format matching.
 java.lang.String toString()
          Gets a String representation of the Format attributes.
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

NOT_SPECIFIED

public static final int NOT_SPECIFIED

TRUE

public static final int TRUE

FALSE

public static final int FALSE

encoding

protected java.lang.String encoding

intArray

public static final java.lang.Class intArray
The data object required by the Format is an integer array.

shortArray

public static final java.lang.Class shortArray
The data object required by the Format is a short array.

byteArray

public static final java.lang.Class byteArray
The data object required by the Format is a byte array.

formatArray

public static final java.lang.Class formatArray
The data object required by the Format is an array of Format objects.

dataType

protected java.lang.Class dataType

clz

protected java.lang.Class clz
Constructor Detail

Format

public Format(java.lang.String encoding)
Constructs a Format that has the specified encoding type.
Parameters:
encoding - A String that contains the encoding type of the Format to be constructed.

Format

public Format(java.lang.String encoding,
              java.lang.Class dataType)
Constructs a Format that has the specified encoding and data types.
Parameters:
encoding - A String that contains the encoding type of the Format to be constructed.
dataType - The type of data object required by the Format to be constructed, such as: byteArray, intArray, or shortArray. For example, for a byte array the data type would be "Format.byteArray".
Method Detail

getEncoding

public java.lang.String getEncoding()
Gets the uniquely-qualified encoding name for this Format.

In the reference implementation of JMF, these strings follow the QuickTime codec strings.

Returns:
The encoding of the Format.

getDataType

public java.lang.Class getDataType()
Gets the type of the data that this Format requires. For example, for byte array it returns "byte[].class".
Returns:
The data type of this Format.

equals

public boolean equals(java.lang.Object format)
Checks whether or not the specified Format is the same as this Format. To be equal, the two Formats must be of the same type and all of their attributes must be the same.
Overrides:
equals in class java.lang.Object
Parameters:
format - The Format to compare with this one.
Returns:
true if the specified Format is the same as this one, false if it is not.

matches

public boolean matches(Format format)
Checks whether or not the specified Format matches this Format. Matches only compares the attributes that are defined in the specified Format, unspecified attributes are ignored.

The two Format objects do not have to be of the same class to match. For example, if "A" are "B" are being compared, a match is possible if "A" is derived from "B" or "B" is derived from "A". (The compared attributes must still match, or matches fails.)

Parameters:
format - The Format to compare with this one.
Returns:
true if the specified Format matches this one, false if it does not.

intersects

public Format intersects(Format other)
Intersects the attributes of this format and the specified format to create a new Format object. The two objects being intersected should either be of the same type or one should be a subclass of the other. The resulting object will be the same type as the subclass.

Common attributes are intersected as follows: If both objects have NOT_SPECIFIED values for an attribute, the result will also have a NOT_SPECIFIED value. If one of them has a NOT_SPECIFIED value then the result will have the value that is specified in the other object. If both objects have specified values then the value in this object will be used.

Attributes that are specific to the subclass will be carried forward to the result.

Parameters:
other - The Format object to intersect with this Format.
Returns:
A Format object with its attributes set to those attributes common to both Format objects.
See Also:
matches(javax.media.Format)

relax

public Format relax()
Generate a format that's less restrictive than this format but contains the basic attributes that will make this resulting format useful for format matching.
Returns:
A Format that's less restrictive than the this format.

clone

public java.lang.Object clone()
Creates a clone of this Format.
Overrides:
clone in class java.lang.Object
Returns:
A clone of this format.

copy

protected void copy(Format f)
Copies the attributes from the specified Format into this Format.
Parameters:
f - The Format to copy the attributes from.

toString

public java.lang.String toString()
Gets a String representation of the Format attributes. For example: "PCM, 44.1 KHz, Stereo, Signed".
Overrides:
toString in class java.lang.Object
Returns:
A String that describes the Format attributes.


Submit a bug or feature
Copyright 1999-2000 Sun Microsystems, Inc. 901 San Antonio Road, Palo Alto, California, 94303, U.S.A. All Rights Reserved. See the Specification License for more details.
Sun, Sun Microsystems, and Java are trademarks or registered trademarks of Sun Microsystems, Inc. in the US and other countries.