use of org.jaudiotagger.tag.vorbiscomment.VorbisCommentTag in project MusicDNA by harjot-oberai.
the class FlacTagReader method read.
public FlacTag read(RandomAccessFile raf) throws CannotReadException, IOException {
FlacStreamReader flacStream = new FlacStreamReader(raf);
flacStream.findStream();
//Hold the metadata
VorbisCommentTag tag = null;
List<MetadataBlockDataPicture> images = new ArrayList<MetadataBlockDataPicture>();
//Seems like we have a valid stream
boolean isLastBlock = false;
while (!isLastBlock) {
if (logger.isLoggable(Level.CONFIG)) {
logger.config("Looking for MetaBlockHeader at:" + raf.getFilePointer());
}
//Read the header
MetadataBlockHeader mbh = MetadataBlockHeader.readHeader(raf);
if (mbh == null) {
break;
}
if (logger.isLoggable(Level.CONFIG)) {
logger.config("Reading MetadataBlockHeader:" + mbh.toString() + " ending at " + raf.getFilePointer());
}
//JAUDIOTAGGER-466:CBlocktype can be null
if (mbh.getBlockType() != null) {
switch(mbh.getBlockType()) {
//We got a vorbiscomment comment block, parse it
case VORBIS_COMMENT:
byte[] commentHeaderRawPacket = new byte[mbh.getDataLength()];
raf.read(commentHeaderRawPacket);
tag = vorbisCommentReader.read(commentHeaderRawPacket, false);
break;
case PICTURE:
try {
MetadataBlockDataPicture mbdp = new MetadataBlockDataPicture(mbh, raf);
images.add(mbdp);
} catch (IOException ioe) {
logger.warning("Unable to read picture metablock, ignoring:" + ioe.getMessage());
} catch (InvalidFrameException ive) {
logger.warning("Unable to read picture metablock, ignoring" + ive.getMessage());
}
break;
//This is not a metadata block we are interested in so we skip to next block
default:
if (logger.isLoggable(Level.CONFIG)) {
logger.config("Ignoring MetadataBlock:" + mbh.getBlockType());
}
raf.seek(raf.getFilePointer() + mbh.getDataLength());
break;
}
}
isLastBlock = mbh.isLastBlock();
mbh = null;
}
//just initialize Flac with an empty VorbisTag
if (tag == null) {
tag = VorbisCommentTag.createNewTag();
}
FlacTag flacTag = new FlacTag(tag, images);
return flacTag;
}
use of org.jaudiotagger.tag.vorbiscomment.VorbisCommentTag in project MusicDNA by harjot-oberai.
the class OggVorbisTagReader method read.
/**
* Read the Logical VorbisComment Tag from the file
*
* <p>Read the CommenyTag, within an OggVorbis file the VorbisCommentTag is mandatory
*
* @param raf
* @return
* @throws CannotReadException
* @throws IOException
*/
public Tag read(RandomAccessFile raf) throws CannotReadException, IOException {
logger.config("Starting to read ogg vorbis tag from file:");
byte[] rawVorbisCommentData = readRawPacketData(raf);
//Begin tag reading
VorbisCommentTag tag = vorbisCommentReader.read(rawVorbisCommentData, true);
logger.fine("CompletedReadCommentTag");
return tag;
}
use of org.jaudiotagger.tag.vorbiscomment.VorbisCommentTag in project MusicDNA by harjot-oberai.
the class OggVorbisTagWriter method delete.
public void delete(RandomAccessFile raf, RandomAccessFile tempRaf) throws IOException, CannotReadException, CannotWriteException {
try {
reader.read(raf);
} catch (CannotReadException e) {
write(VorbisCommentTag.createNewTag(), raf, tempRaf);
return;
}
VorbisCommentTag emptyTag = VorbisCommentTag.createNewTag();
//Go back to start of file
raf.seek(0);
write(emptyTag, raf, tempRaf);
}
Aggregations