~ubuntu-branches/ubuntu/utopic/libjaudiotagger-java/utopic-proposed

« back to all changes in this revision

Viewing changes to src/org/jaudiotagger/tag/id3/ID3v22Frame.java

  • Committer: Bazaar Package Importer
  • Author(s): Damien Raude-Morvan
  • Date: 2009-12-30 21:58:38 UTC
  • mfrom: (3.1.3 sid)
  • Revision ID: james.westby@ubuntu.com-20091230215838-113vy313ak2ap51i
Tags: 2.0.0-1
* New upstream release
* Update my email address
* Bump debhelper version to >= 7
* Bump Standards-Version to 3.8.3 (no changes needed)
* Depends on java5-runtime-headless as we build java5 bytecode
* Maven POMs:
  - Add a Build-Depends-Indep dependency on maven-repo-helper
  - Use mh_installpoms and mh_installjar to install the POM and the jar to the
    Maven repository

Show diffs side-by-side

added added

removed removed

Lines of Context:
37
37
 *
38
38
 * @author : Paul Taylor
39
39
 * @author : Eric Farng
40
 
 * @version $Id: ID3v22Frame.java,v 1.30 2008/07/21 10:45:48 paultaylor Exp $
 
40
 * @version $Id: ID3v22Frame.java,v 1.34 2009/11/12 15:42:57 paultaylor Exp $
41
41
 */
42
42
public class ID3v22Frame extends AbstractID3v2Frame
43
43
{
44
 
    Pattern validFrameIdentifier = Pattern.compile("[A-Z][0-9A-Z]{2}");
 
44
    private static Pattern validFrameIdentifier = Pattern.compile("[A-Z][0-9A-Z]{2}");
45
45
 
46
46
    protected static final int FRAME_ID_SIZE = 3;
47
47
    protected static final int FRAME_SIZE_SIZE = 3;
67
67
     * <p/>
68
68
     * An empty body of the correct type will be automatically created. This constructor should be used when wish to
69
69
     * create a new frame from scratch using user values
 
70
     * @param identifier
70
71
     */
71
72
    @SuppressWarnings("unchecked")
72
73
    public ID3v22Frame(String identifier)
133
134
     * Copy Constructor
134
135
     * <p/>
135
136
     * Creates a new v22 frame based on another v22 frame
 
137
     * @param frame
136
138
     */
137
139
    public ID3v22Frame(ID3v22Frame frame)
138
140
    {
147
149
        {
148
150
            logger.info("V2:Orig id is:" + frame.getIdentifier() + ":New id is:" + identifier);
149
151
            this.frameBody = (AbstractID3v2FrameBody) ID3Tags.copyObject(frame.getBody());
150
 
            return;
151
152
        }
152
153
        // Is it a known v3 frame which needs forcing to v2 frame e.g. APIC - PIC
153
 
        else if (ID3Tags.isID3v23FrameIdentifier(frame.getIdentifier()) == true)
 
154
        else if (ID3Tags.isID3v23FrameIdentifier(frame.getIdentifier()))
154
155
        {
155
156
            identifier = ID3Tags.forceFrameID23To22(frame.getIdentifier());
156
157
            if (identifier != null)
157
158
            {
158
159
                logger.info("V2:Force:Orig id is:" + frame.getIdentifier() + ":New id is:" + identifier);
159
160
                this.frameBody = this.readBody(identifier, (AbstractID3v2FrameBody) frame.getBody());
160
 
                return;
161
161
            }
162
162
            // No mechanism exists to convert it to a v22 frame
163
163
            else
181
181
                this.frameBody = new FrameBodyDeprecated((FrameBodyDeprecated) frame.getBody());
182
182
                identifier = frame.getIdentifier();
183
183
                logger.info("DEPRECATED:Orig id is:" + frame.getIdentifier() + ":New id is:" + identifier);
184
 
                return;
185
184
            }
186
185
        }
187
186
        // Unknown Frame e.g NCON
190
189
            this.frameBody = new FrameBodyUnsupported((FrameBodyUnsupported) frame.getBody());
191
190
            identifier = frame.getIdentifier();
192
191
            logger.info("v2:UNKNOWN:Orig id is:" + frame.getIdentifier() + ":New id is:" + identifier);
193
 
            return;
194
192
        }
195
193
    }
196
194
 
198
196
     * Creates a new ID3v22 Frame from another frame of a different tag version
199
197
     *
200
198
     * @param frame to construct the new frame from
 
199
     * @throws org.jaudiotagger.tag.InvalidFrameException
201
200
     */
202
201
    public ID3v22Frame(AbstractID3v2Frame frame) throws InvalidFrameException
203
202
    {
204
203
        logger.info("Creating frame from a frame of a different version");
205
 
        if ((frame instanceof ID3v22Frame == true) && (frame instanceof ID3v23Frame == false))
 
204
        if (frame instanceof ID3v22Frame)
206
205
        {
207
206
            throw new UnsupportedOperationException("Copy Constructor not called. Please type cast the argument");
208
207
        }
226
225
     * Creates a new ID3v22Frame datatype by reading from byteBuffer.
227
226
     *
228
227
     * @param byteBuffer to read from
 
228
     * @param loggingFilename
 
229
     * @throws org.jaudiotagger.tag.InvalidFrameException
229
230
     */
230
231
    public ID3v22Frame(ByteBuffer byteBuffer, String loggingFilename) throws InvalidFrameException
231
232
    {
238
239
     *
239
240
     * @param byteBuffer to read from
240
241
     * @deprecated use {@link #ID3v22Frame(ByteBuffer,String)} instead
 
242
     * @throws org.jaudiotagger.tag.InvalidFrameException
241
243
     */
242
244
    public ID3v22Frame(ByteBuffer byteBuffer) throws InvalidFrameException
243
245
    {
276
278
        logger.info("Read Frame from file identifier is:" + identifier);
277
279
 
278
280
        // Is this a valid identifier?
279
 
        if (isValidID3v2FrameIdentifier(identifier) == false)
 
281
        if (!isValidID3v2FrameIdentifier(identifier))
280
282
        {
281
283
            logger.info("Invalid identifier:" + identifier);
282
284
            byteBuffer.position(byteBuffer.position() - (FRAME_ID_SIZE - 1));
313
315
                {
314
316
                    // Is it a valid v22 identifier so should be able to find a
315
317
                    // frame body for it.
316
 
                    if (ID3Tags.isID3v22FrameIdentifier(identifier) == true)
 
318
                    if (ID3Tags.isID3v22FrameIdentifier(identifier))
317
319
                    {
318
320
                        id = identifier;
319
321
                    }
344
346
 
345
347
    /**
346
348
     * Read Frame Size, which has to be decoded
 
349
     * @param buffer
 
350
     * @return
347
351
     */
348
352
    private int decodeSize(byte[] buffer)
349
353
    {
396
400
    /**
397
401
     * Write Frame Size (can now be accurately calculated, have to convert 4 byte int
398
402
     * to 3 byte format.
 
403
     * @param headerBuffer
 
404
     * @param size
399
405
     */
400
406
    private void encodeSize(ByteBuffer headerBuffer, int size)
401
407
    {
414
420
     */
415
421
    public boolean isValidID3v2FrameIdentifier(String identifier)
416
422
    {
417
 
        Matcher m = validFrameIdentifier.matcher(identifier);
 
423
        Matcher m = ID3v22Frame.validFrameIdentifier.matcher(identifier);
418
424
        return m.matches();
419
425
    }
420
426