2
* Entagged Audio Tag library
3
* Copyright (c) 2003-2005 Rapha�l Slinckx <raphael@slinckx.net>
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.
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.
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
19
package org.jaudiotagger.audio.flac;
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;
32
import java.util.List;
33
import java.util.ArrayList;
34
import java.util.logging.Logger;
39
public class FlacTagReader
42
public static Logger logger = Logger.getLogger("org.jaudiotagger.audio.flac");
44
private VorbisCommentReader vorbisCommentReader = new VorbisCommentReader();
47
public FlacTag read(RandomAccessFile raf) throws CannotReadException, IOException
49
FlacStream.findStream(raf);
52
VorbisCommentTag tag = null;
53
List<MetadataBlockDataPicture> images = new ArrayList<MetadataBlockDataPicture>();
55
//Seems like we have a valid stream
56
boolean isLastBlock = false;
60
MetadataBlockHeader mbh = MetadataBlockHeader.readHeader(raf);
62
//Is it one containing some sort of metadata, therefore interested in it?
63
switch (mbh.getBlockType())
65
//We got a vorbiscomment comment block, parse it
67
byte[] commentHeaderRawPacket = new byte[mbh.getDataLength()];
68
raf.read(commentHeaderRawPacket);
69
tag = vorbisCommentReader.read(commentHeaderRawPacket,false);
75
MetadataBlockDataPicture mbdp = new MetadataBlockDataPicture(mbh,raf);
78
catch(IOException ioe)
80
logger.warning("Unable to read picture metablock, ignoring:"+ioe.getMessage());
82
catch(InvalidFrameException ive)
84
logger.warning("Unable to read picture metablock, ignoring"+ive.getMessage());
89
//This is not a metadata block we are interested in so we skip to next block
91
raf.seek(raf.getFilePointer() + mbh.getDataLength());
95
isLastBlock = mbh.isLastBlock();
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
103
tag = new VorbisCommentTag();
105
FlacTag flacTag = new FlacTag(tag,images);