FileDocCategorySizeDatePackage
COMRID3V2Frame.javaAPI Docjid3 0.4616035Sun Feb 06 18:11:20 GMT 2005org.blinkenlights.jid3.v2

COMRID3V2Frame

public class COMRID3V2Frame extends ID3V2Frame
author
paul Frame containing commercials for the recording in this track.

Fields Summary
public static final byte
RECEIVED_AS_OTHER
public static final byte
RECEIVED_AS_STANDARD_ALBUM
public static final byte
RECEIVED_AS_COMPRESSED_AUDIO_ON_CD
public static final byte
RECEIVED_AS_FILE_OVER_THE_INTERNET
public static final byte
RECEIVED_AS_STREAM_OVER_THE_INTERNET
public static final byte
RECEIVED_AS_NOTE_SHEETS
public static final byte
RECEIVED_AS_NOTE_SHEETS_IN_A_BOOK_WITH_OTHER_SHEETS
public static final byte
RECEIVED_AS_MUSIC_ON_OTHER_MEDIA
public static final byte
RECEIVED_AS_NON_MUSICAL_MERCHANDISE
private TextEncoding
m_oTextEncoding
private String
m_sPrice
private String
m_sValidUntil
private String
m_sContactUrl
private byte
m_byReceivedAs
private String
m_sNameOfSeller
private String
m_sDescription
private String
m_sPictureMimeType
private byte[]
m_abySellerLogoData
Constructors Summary
public COMRID3V2Frame(String sPrice, String sValidUntil, String sContactUrl, byte byReceivedAs, String sNameOfSeller, String sDescription, String sPictureMimeType, byte[] abySellerLogoData)
Constructor.

param
sPrice a price(s) string (a price string consists of a three letter ISO-4217 currency code, followed by an amount, where "." is used as the decimal separator). Multiple prices may be separated by a "/" characters.
param
sValidUntil the date the prices offer is valid until, in the format YYYYMMDD
param
sContactUrl an URL at which contact can be made with the seller
param
byReceivedAs byte specifying how the track will be delivered when purchased
param
sNameOfSeller the name of the seller
param
sDescription short description of the product
param
sPictureMimeType the mime type of the picture (only "image/jpeg" and "image/png" are allowed by the ID3 specification)
param
abySellerLogoData the image data containing the seller's logo
throws
ID3Exception if sPrice is null or invalid
throws
ID3Exception if sValidUntil is null or invalid
throws
ID3Exception if sContactUrl is null
throws
ID3Exception if sNameOfSeller is null
throws
ID3Exception if sDecription is null


                                                                                                                                                                                       
      
                           
                           
                           
                           
                           
                           
                           
         
    
        m_oTextEncoding = TextEncoding.getDefaultTextEncoding();
        if (sPrice == null)
        {
            throw new ID3Exception("Price required in COMR frame.");
        }
        if ( ! sPrice.matches("(?uis)(\\w{3}\\d*\\.?\\d+/?)+"))
        {
            throw new ID3Exception("Invalid COMR frame price string.");
        }
        m_sPrice = sPrice;
        if (sValidUntil == null)
        {
            throw new ID3Exception("Valid until valud required in COMR frame.");
        }
        if ( ! sValidUntil.matches("(?uis)\\d{8}"))
        {
            throw new ID3Exception("Invalid COMR frame valid until date.");
        }
        m_sValidUntil = sValidUntil;
        if (sContactUrl == null)
        {
            throw new ID3Exception("Contact URL required in COMR frame.");
        }
        m_sContactUrl = sContactUrl;
        m_byReceivedAs = byReceivedAs;
        if (sNameOfSeller == null)
        {
            throw new ID3Exception("Name of seller required in COMR frame.");
        }
        m_sNameOfSeller = sNameOfSeller;
        if (sDescription == null)
        {
            throw new ID3Exception("Description required in COMR frame.");
        }
        m_sDescription = sDescription;
        m_sPictureMimeType = sPictureMimeType;
        if (m_sPictureMimeType == null)
        {
            m_sPictureMimeType = "image/";
        }
        m_abySellerLogoData = abySellerLogoData;
    
public COMRID3V2Frame(InputStream oIS)

        // Parse out the text encoding and text string from the raw data
        try
        {
            ID3DataInputStream oFrameDataID3DIS = new ID3DataInputStream(oIS);
            
            // text encoding
            m_oTextEncoding = TextEncoding.getTextEncoding(oFrameDataID3DIS.readUnsignedByte());
            
            // price (read to null)
            m_sPrice = oFrameDataID3DIS.readStringToNull();
            
            // valid until
            byte[] abyValidUntil = new byte[8];
            oFrameDataID3DIS.readFully(abyValidUntil);
            m_sValidUntil = new String(abyValidUntil);
            
            // contact url (read to null)
            m_sContactUrl = oFrameDataID3DIS.readStringToNull();
            
            // received as
            m_byReceivedAs = (byte)oFrameDataID3DIS.readUnsignedByte();

            // name of seller (read to null)
            m_sNameOfSeller = oFrameDataID3DIS.readStringToNull(m_oTextEncoding);

            // description (read to null)
            m_sDescription = oFrameDataID3DIS.readStringToNull(m_oTextEncoding);
            
            // is there a company logo picture coming?
            if (oFrameDataID3DIS.available() > 0)
            {
                // company logo mime type (read to null)
                m_sPictureMimeType = oFrameDataID3DIS.readStringToNull();
                
                // company logo picture data
                m_abySellerLogoData = new byte[oFrameDataID3DIS.available()];
                oFrameDataID3DIS.readFully(m_abySellerLogoData);
            }
        }
        catch (Exception e)
        {
            throw new InvalidFrameID3Exception(e);
        }
    
Methods Summary
public voidaccept(ID3Visitor oID3Visitor)

        oID3Visitor.visitCOMRID3V2Frame(this);
    
public booleanequals(java.lang.Object oOther)

        if ((oOther == null) || (!(oOther instanceof COMRID3V2Frame)))
        {
            return false;
        }
        
        COMRID3V2Frame oOtherCOMR = (COMRID3V2Frame)oOther;
        
        return (m_oTextEncoding.equals(oOtherCOMR.m_oTextEncoding) &&
                m_sPrice.equals(oOtherCOMR.m_sPrice) &&
                m_sValidUntil.equals(oOtherCOMR.m_sValidUntil) &&
                m_sContactUrl.equals(oOtherCOMR.m_sContactUrl) &&
                (m_byReceivedAs == oOtherCOMR.m_byReceivedAs) &&
                m_sNameOfSeller.equals(oOtherCOMR.m_sNameOfSeller) &&
                m_sDescription.equals(oOtherCOMR.m_sDescription) &&
                m_sPictureMimeType.equals(oOtherCOMR.m_sPictureMimeType) &&
                Arrays.equals(m_abySellerLogoData, oOtherCOMR.m_abySellerLogoData));
    
public java.lang.StringgetContactUrl()
Get contact URL string.

return
the contact URL string

        return m_sContactUrl;
    
public java.lang.StringgetDescription()
Get description of item.

return
the description of the item being sold

        return m_sDescription;
    
protected byte[]getFrameId()

        return "COMR".getBytes();
    
public java.lang.StringgetNameOfSeller()
Get name of seller.

return
the name of the seller

        return m_sNameOfSeller;
    
public java.lang.StringgetPrice()
Get price.

return
price string

        return m_sPrice;
    
public bytegetReceivedAsFormat()
Get received as format.

return
the byte specifying the received as format

        return m_byReceivedAs;
    
public byte[]getSellerLogoData()
Get image data for the seller logo.

return
image data for the seller logo

        return m_abySellerLogoData;
    
public java.lang.StringgetSellerLogoMimeType()
Get mime type of the seller logo image.

return
mime type of the seller logo image

        return m_sPictureMimeType;
    
public TextEncodinggetTextEncoding()
Get the text encoding used for the name of seller and description in this frame.

return
the text encoding to be used for this frame

        return m_oTextEncoding;
    
public java.lang.StringgetValidUntilDate()
Get valid until date.

return
valid until date

        return m_sValidUntil;
    
public voidsetCommercialInformation(java.lang.String sPrice, java.lang.String sValidUntil, java.lang.String sContactUrl, byte byReceivedAs, java.lang.String sNameOfSeller, java.lang.String sDescription, java.lang.String sPictureMimeType, byte[] abySellerLogoData)
Set commercial information.

param
sPrice a price(s) string (a price string consists of a three letter ISO-4217 currency code, followed by an amount, where "." is used as the decimal separator). Multiple prices may be separated by a "/" characters.
param
sValidUntil the date the prices offer is valid until, in the format YYYYMMDD
param
sContactUrl an URL at which contact can be made with the seller
param
byReceivedAs byte specifying how the track will be delivered when purchased
param
sNameOfSeller the name of the seller
param
sDescription short description of the product
param
sPictureMimeType the mime type of the picture (only "image/jpeg" and "image/png" are allowed by the ID3 specification)
param
abySellerLogoData the image data containing the seller's logo
throws
ID3Exception if sPrice is null or invalid
throws
ID3Exception if sValidUntil is null or invalid
throws
ID3Exception if sContactUrl is null
throws
ID3Exception if sNameOfSeller is null
throws
ID3Exception if sDecription is null

        m_oTextEncoding = TextEncoding.getDefaultTextEncoding();
        if (sPrice == null)
        {
            throw new ID3Exception("Price required in COMR frame.");
        }
        if ( ! sPrice.matches("(?uis)(\\w{3}\\d*\\.?\\d+/?)+"))
        {
            throw new ID3Exception("Invalid COMR frame price string.");
        }
        m_sPrice = sPrice;
        if (sValidUntil == null)
        {
            throw new ID3Exception("Valid until date required in COMR frame.");
        }
        if ( ! sValidUntil.matches("(?uis)\\d{8}"))
        {
            throw new ID3Exception("Invalid COMR frame valid until date.");
        }
        m_sValidUntil = sValidUntil;
        if (sContactUrl == null)
        {
            throw new ID3Exception("Contact URL required in COMR frame.");
        }
        m_sContactUrl = sContactUrl;
        m_byReceivedAs = byReceivedAs;
        if (sNameOfSeller == null)
        {
            throw new ID3Exception("Name of seller required in COMR frame.");
        }
        m_sNameOfSeller = sNameOfSeller;
        if (sDescription == null)
        {
            throw new ID3Exception("Description required in COMR frame.");
        }
        m_sDescription = sDescription;
        m_sPictureMimeType = sPictureMimeType;
        if (m_sPictureMimeType == null)
        {
            m_sPictureMimeType = "image/";
        }
        m_abySellerLogoData = abySellerLogoData;
    
public voidsetTextEncoding(TextEncoding oTextEncoding)
Set the text encoding to be used for the name of seller and description in this frame.

param
oTextEncoding the text encoding to be used for this frame

        if (oTextEncoding == null)
        {
            throw new NullPointerException("Text encoding cannot be null.");
        }
        m_oTextEncoding = oTextEncoding;
    
public java.lang.StringtoString()

        return "Commercial Frame: Price=[" + m_sPrice + "], Valid Until=[" + m_sValidUntil + "], Contact URL=[" +
               m_sContactUrl + "], Received As=" + m_byReceivedAs + ", Name Of Seller=[" + m_sNameOfSeller +
               "], Description=[" + m_sDescription + "], Picture Mime Type=[" + m_sPictureMimeType + "]";
    
protected voidwriteBody(ID3DataOutputStream oIDOS)

        // text encoding
        oIDOS.writeUnsignedByte(m_oTextEncoding.getEncodingValue());
        // price string
        oIDOS.write(m_sPrice.getBytes());
        oIDOS.writeUnsignedByte(0);
        // valid until
        oIDOS.write(m_sValidUntil.getBytes());
        // contact url
        oIDOS.write(m_sContactUrl.getBytes());
        oIDOS.writeUnsignedByte(0);
        // received as
        oIDOS.writeUnsignedByte(m_byReceivedAs);
        // name of seller
        if (m_sNameOfSeller != null)
        {
            oIDOS.write(m_sNameOfSeller.getBytes(m_oTextEncoding.getEncodingString()));
        }
        // null terminating optional name of seller
        if (m_oTextEncoding.equals(TextEncoding.ISO_8859_1))
        {
            oIDOS.writeUnsignedByte(0);
        }
        else
        {
            oIDOS.writeUnsignedByte(0);
            oIDOS.writeUnsignedByte(0);
        }
        // description
        if (m_sDescription != null)
        {
            oIDOS.write(m_sDescription.getBytes(m_oTextEncoding.getEncodingString()));
        }
        // null terminating optional description
        if (m_oTextEncoding.equals(TextEncoding.ISO_8859_1))
        {
            oIDOS.writeUnsignedByte(0);
        }
        else
        {
            oIDOS.writeUnsignedByte(0);
            oIDOS.writeUnsignedByte(0);
        }
        // optional company logo image
        if (m_abySellerLogoData != null)
        {
            // image mime type (optional, "image/" assumed if not set)
            if (m_sPictureMimeType != null)
            {
                oIDOS.write(m_sPictureMimeType.getBytes());
            }
            oIDOS.writeUnsignedByte(0); // terminating null
            
            // actual image data
            oIDOS.write(m_abySellerLogoData);
        }