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

« back to all changes in this revision

Viewing changes to org/jaudiotagger/audio/flac/FlacTagReader.java

  • Committer: Bazaar Package Importer
  • Author(s): Varun Hiremath, Damien Raude-Morvan, Varun Hiremath
  • Date: 2009-04-01 19:17:56 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20090401191756-bygniim270guy7o1
Tags: 1.0.9-1
[ Damien Raude-Morvan ]
* New upstream release
* debian/watch: Use java.net repository (which contains new releases!)
* debian/control:
  - Build-Depends on default-jdk-builddep
  - Bump Standards-Version to 3.8.1 (no changes needed)
  - Change section to "java"
* debian/rules: use default-java as JAVA_HOME
* debina/orig-tar.{sh|excludes}: strip audio and others binary files from ZIP
* debian/build.xml:
  - compile with "nowarn" to keep build log readable
  - exclude LogFormatter from build (use com.sun classes)
* debian/ant.properties: new source directory is "src" in orig.tar.gz
* Add myself as Uploaders

[ Varun Hiremath ]
* Accept changes made by Damien Raude-Morvan (Closes: #522130)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Entagged Audio Tag library
3
 
 * Copyright (c) 2003-2005 Rapha�l Slinckx <raphael@slinckx.net>
4
 
 * 
5
 
 * This library is free software; you can redistribute it and/or
6
 
 * modify it under the terms of the GNU Lesser General Public
7
 
 * License as published by the Free Software Foundation; either
8
 
 * version 2.1 of the License, or (at your option) any later version.
9
 
 *  
10
 
 * This library is distributed in the hope that it will be useful,
11
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
 
 * Lesser General Public License for more details.
14
 
 * 
15
 
 * You should have received a copy of the GNU Lesser General Public
16
 
 * License along with this library; if not, write to the Free Software
17
 
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
 
 */
19
 
package org.jaudiotagger.audio.flac;
20
 
 
21
 
import org.jaudiotagger.audio.exceptions.*;
22
 
import org.jaudiotagger.audio.flac.metadatablock.MetadataBlockHeader;
23
 
import org.jaudiotagger.audio.flac.metadatablock.BlockType;
24
 
import org.jaudiotagger.audio.flac.metadatablock.MetadataBlockDataStreamInfo;
25
 
import org.jaudiotagger.audio.flac.metadatablock.MetadataBlockDataPicture;
26
 
import org.jaudiotagger.tag.vorbiscomment.VorbisCommentTag;
27
 
import org.jaudiotagger.tag.vorbiscomment.VorbisCommentReader;
28
 
import org.jaudiotagger.tag.InvalidFrameException;
29
 
import org.jaudiotagger.tag.flac.FlacTag;
30
 
 
31
 
import java.io.*;
32
 
import java.util.List;
33
 
import java.util.ArrayList;
34
 
import java.util.logging.Logger;
35
 
 
36
 
/**
37
 
 * Read Flac Tag
38
 
 */
39
 
public class FlacTagReader
40
 
{
41
 
    // Logger Object
42
 
    public static Logger logger = Logger.getLogger("org.jaudiotagger.audio.flac");
43
 
 
44
 
    private VorbisCommentReader vorbisCommentReader = new VorbisCommentReader();
45
 
 
46
 
    
47
 
    public FlacTag read(RandomAccessFile raf) throws CannotReadException, IOException
48
 
    {
49
 
        FlacStream.findStream(raf);
50
 
 
51
 
        //Hold the metadata
52
 
        VorbisCommentTag        tag = null;
53
 
        List<MetadataBlockDataPicture> images = new ArrayList<MetadataBlockDataPicture>();
54
 
 
55
 
        //Seems like we have a valid stream
56
 
        boolean isLastBlock = false;
57
 
        while (!isLastBlock)
58
 
        {
59
 
            //Read the header
60
 
            MetadataBlockHeader mbh = MetadataBlockHeader.readHeader(raf);
61
 
 
62
 
            //Is it one containing some sort of metadata, therefore interested in it?
63
 
            switch (mbh.getBlockType())
64
 
            {
65
 
                //We got a vorbiscomment comment block, parse it
66
 
                case VORBIS_COMMENT :
67
 
                    byte[] commentHeaderRawPacket = new byte[mbh.getDataLength()];
68
 
                    raf.read(commentHeaderRawPacket);
69
 
                    tag = vorbisCommentReader.read(commentHeaderRawPacket,false);                    
70
 
                    break;
71
 
 
72
 
                case PICTURE:
73
 
                    try
74
 
                    {
75
 
                        MetadataBlockDataPicture mbdp = new MetadataBlockDataPicture(mbh,raf);
76
 
                        images.add(mbdp);
77
 
                    }
78
 
                    catch(IOException ioe)
79
 
                    {
80
 
                        logger.warning("Unable to read picture metablock, ignoring:"+ioe.getMessage());
81
 
                    }
82
 
                    catch(InvalidFrameException ive)
83
 
                    {
84
 
                         logger.warning("Unable to read picture metablock, ignoring"+ive.getMessage());
85
 
                    }
86
 
 
87
 
                    break;
88
 
 
89
 
                //This is not a metadata block we are interested in so we skip to next block
90
 
                default :
91
 
                    raf.seek(raf.getFilePointer() + mbh.getDataLength());
92
 
                    break;
93
 
            }
94
 
 
95
 
            isLastBlock = mbh.isLastBlock();
96
 
            mbh = null;
97
 
        }
98
 
 
99
 
        //Note there may not be either a tag or any images, no problem this is valid however to make it easier we
100
 
        //just initialize Flac with an empty VorbisTag
101
 
        if(tag==null)
102
 
        {
103
 
            tag = new VorbisCommentTag();
104
 
        }
105
 
        FlacTag flacTag = new FlacTag(tag,images);
106
 
        return flacTag;
107
 
    }
108
 
}
109