FileDocCategorySizeDatePackage
ENCRID3V2Frame.javaAPI Docjid3 0.467979Thu Oct 27 03:10:18 BST 2005org.blinkenlights.jid3.v2

ENCRID3V2Frame

public class ENCRID3V2Frame extends ID3V2Frame
author
paul Frame containing encryption information.

Fields Summary
private String
m_sOwnerIdentifier
private byte
m_byMethodSymbol
private byte[]
m_abyEncryptionData
Constructors Summary
public ENCRID3V2Frame(String sOwnerIdentifier, byte byMethodSymbol, byte[] abyEncryptionData)
Constructor.

param
sOwnerIdentifier an URL or email address where decryption details can be found
param
byMethodSymbol a symbol which can be used to identify this encryption method in this file (methods below 0x80 are reserved)
param
abyEncryptionData any optional required data for this encryption method
throws
ID3Exception if sOwnerIdentifier is null

    
                                                            
          
         
    
        // owner identifier
        if (sOwnerIdentifier == null)
        {
            throw new ID3Exception("ENCR frame requires owner identifier string.");
        }
        m_sOwnerIdentifier = sOwnerIdentifier;
        
        // method symbol
        if ((byMethodSymbol & 0xff) < 0x80)
        {
            throw new ID3Exception("Encryption method symbols below 0x80 are reserved.");
        }
        m_byMethodSymbol = byMethodSymbol;
        
        // encryption data
        m_abyEncryptionData = abyEncryptionData;
        if (m_abyEncryptionData == null)
        {
            m_abyEncryptionData = new byte[0];
        }
    
public ENCRID3V2Frame(InputStream oIS)

        try
        {
            ID3DataInputStream oFrameDataID3DIS = new ID3DataInputStream(oIS);
            
            // owner identifier (read to null)
            ByteArrayOutputStream oOwnerIdentifierBAOS = new ByteArrayOutputStream();
            int iOwnerIdentifierByte;
            do
            {
                iOwnerIdentifierByte = oFrameDataID3DIS.readUnsignedByte();
                if (iOwnerIdentifierByte != 0)
                {
                    oOwnerIdentifierBAOS.write(iOwnerIdentifierByte);
                }
            }
            while (iOwnerIdentifierByte != 0);
            if (oOwnerIdentifierBAOS.size() > 0)
            {
                byte[] abyOwnerIdentifier = oOwnerIdentifierBAOS.toByteArray();
                m_sOwnerIdentifier = new String(abyOwnerIdentifier);
            }
            else
            {
                m_sOwnerIdentifier = "";
            }
            
            // method symbol
            m_byMethodSymbol = (byte)oFrameDataID3DIS.readUnsignedByte();
            
            // encryption data
            m_abyEncryptionData = new byte[oFrameDataID3DIS.available()];
            oFrameDataID3DIS.readFully(m_abyEncryptionData);
        }
        catch (Exception e)
        {
            throw new InvalidFrameID3Exception(e);
        }
    
Methods Summary
public voidaccept(ID3Visitor oID3Visitor)

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

        if ((oOther == null) || (!(oOther instanceof ENCRID3V2Frame)))
        {
            return false;
        }
        
        ENCRID3V2Frame oOtherENCR = (ENCRID3V2Frame)oOther;
        
        return (m_sOwnerIdentifier.equals(oOtherENCR.m_sOwnerIdentifier) &&
                (m_byMethodSymbol == oOtherENCR.m_byMethodSymbol) &&
                Arrays.equals(m_abyEncryptionData, oOtherENCR.m_abyEncryptionData));
    
public byte[]getEncryptionData()
Get additional encryption data for this method.

return
additional encryption data, or null if none was provided

        return m_abyEncryptionData;
    
public bytegetEncryptionMethodSymbol()
Get the symbol used for this encryption method in this file.

return
the unique encryption method symbol

        return m_byMethodSymbol;
    
protected byte[]getFrameId()

        return "ENCR".getBytes();
    
public java.lang.StringgetOwnerIdentifier()
Get the owner identifier for this encryption method.

return
the owner identifier, which should be an URL or email address

        return m_sOwnerIdentifier;
    
public voidsetEncryptionDetails(java.lang.String sOwnerIdentifier, byte byMethodSymbol, byte[] abyEncryptionData)
Set details for this encryption frame.

param
sOwnerIdentifier an URL or email address where decryption details can be found
param
byMethodSymbol a symbol which can be used to identify this encryption method in this file
param
abyEncryptionData any optional required data for this encryption method
throws
ID3Exception if sOwnerIdentifier is null
throws
ID3Exception if this frame is in a tag with another ENCR frame which would have the method symbol

        String sOrigOwnerIdentifier = m_sOwnerIdentifier;
        byte byOrigMethodSymbol = m_byMethodSymbol;
        byte[] abyOrigEncryptionData = m_abyEncryptionData;
        
        if (sOwnerIdentifier == null)
        {
            throw new ID3Exception("ENCR frame requires owner identifier string.");
        }
        if ((byMethodSymbol & 0xff) < 0x80)
        {
            throw new ID3Exception("Encryption method symbols below 0x80 are reserved.");
        }

        // owner identifier
        m_sOwnerIdentifier = sOwnerIdentifier;
        
        // method symbol
        m_byMethodSymbol = byMethodSymbol;
        
        // encryption data
        m_abyEncryptionData = abyEncryptionData;
        
        // try this update, and reverse it if it generates and error
        try
        {
            notifyID3Observers();
        }
        catch (ID3Exception e)
        {
            m_sOwnerIdentifier = sOrigOwnerIdentifier;
            m_byMethodSymbol = byOrigMethodSymbol;
            m_abyEncryptionData = abyOrigEncryptionData;
            
            throw e;
        }
    
public java.lang.StringtoString()

        return "Encryption Method Registration: Owner identifier=[" + m_sOwnerIdentifier +
               "], Method Symbol=[" + m_byMethodSymbol + "]";
    
protected voidwriteBody(ID3DataOutputStream oIDOS)

        // owner identifier (and terminating null)
        oIDOS.write(m_sOwnerIdentifier.getBytes());
        oIDOS.writeUnsignedByte(0);
        // method symbol
        oIDOS.writeUnsignedByte(m_byMethodSymbol);
        // encryption data
        if (m_abyEncryptionData != null)
        {
            oIDOS.write(m_abyEncryptionData);
        }