Methods Summary |
---|
public java.lang.Object | clone()Creates a clone of this Format .
Format f = new Format(encoding);
f.copy(this);
return f;
|
protected void | copy(javax.media.Format f)Copies the attributes from the specified Format into this Format .
dataType = f.dataType;
|
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.
if (format == null || clz != ((Format)format).clz)
return false;
String otherEncoding = ((Format)format).encoding;
Class otherType = ((Format)format).dataType;
return (dataType == otherType) &&
(encoding == otherEncoding ||
((encoding != null && otherEncoding != null) &&
isSameEncoding((Format)format)));
|
public java.lang.Class | getDataType()Gets the type of the data that this Format requires.
For example, for byte array it returns "byte[].class ".
return dataType;
|
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.
return encoding;
|
private long | getEncodingCode(java.lang.String enc)
byte chars[] = enc.getBytes();
byte b;
long code = 0;
for (int i = 0; i < enc.length(); i++) {
b = chars[i];
if (b > 96 && b < 123)
b -= 32; // lower to upper
b -= 32;
if (b > 63)
return -1;
code = (code << 6) | (long) b;
}
return code;
|
public javax.media.Format | intersects(javax.media.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.
Format res;
if (clz.isAssignableFrom(other.clz))
res = (Format)other.clone();
else if (other.clz.isAssignableFrom(clz))
res = (Format)clone();
else
return null;
if (res.encoding == null)
res.encoding = (encoding != null ? encoding : other.encoding);
if (res.dataType == null)
res.dataType = (dataType != null ? dataType : other.dataType);
return res;
|
public boolean | isSameEncoding(javax.media.Format other)Checks if the encodings of both format objects are the same. Its
faster than calling String.equalsIgnoreCase to compare the two
encodings.
if (encoding == null || other == null || other.encoding == null)
return false;
// Quick checks
if (encoding == other.encoding)
return true;
if (encodingCode > 0 && other.encodingCode > 0)
return encodingCode == other.encodingCode;
// Works faster only for shorter strings of 10 chars or less.
if (encoding.length() > 10)
return encoding.equalsIgnoreCase(other.encoding);
if (encodingCode == 0) {
encodingCode = getEncodingCode(encoding);
}
// If the encoding code cannot be computed (out of bounds chars)
// or in the off chance that its all spaces.
if (encodingCode <= 0)
return encoding.equalsIgnoreCase(other.encoding);
if (other.encodingCode == 0)
return other.isSameEncoding(this);
else
return encodingCode == other.encodingCode;
|
public boolean | isSameEncoding(java.lang.String encoding)Checks if the encoding of this format is same as the parameter. Its
faster than calling String.equalsIgnoreCase to compare the two
encodings.
if (this.encoding == null || encoding == null)
return false;
// Quick check
if (this.encoding == encoding)
return true;
// Works faster only for shorter strings of 10 chars or less.
if (this.encoding.length() > 10)
return this.encoding.equalsIgnoreCase(encoding);
// Compute encoding code only once
if (encodingCode == 0) {
encodingCode = getEncodingCode(this.encoding);
}
// If the encoding code cannot be computed (out of bounds chars)
if (encodingCode < 0)
return this.encoding.equalsIgnoreCase(encoding);
long otherEncodingCode = getEncodingCode(encoding);
return encodingCode == otherEncodingCode;
|
public boolean | matches(javax.media.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.)
if( format == null) return false;
return (format.encoding == null || encoding == null ||
isSameEncoding(format)) &&
(format.dataType == null || dataType == null ||
format.dataType == dataType) &&
(clz.isAssignableFrom(format.clz) ||
format.clz.isAssignableFrom(clz));
|
public javax.media.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.
return (Format)clone();
|
public java.lang.String | toString()Gets a String representation of the Format attributes.
For example: "PCM, 44.1 KHz, Stereo, Signed".
return getEncoding();
|