Coverage Report - org.jaudiotagger.audio.ogg.OggVorbisCommentTagCreator
 
Classes in this File Line Coverage Branch Coverage Complexity
OggVorbisCommentTagCreator
100%
12/12
N/A
1
 
 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.ogg;
 20  
 
 21  
 import org.jaudiotagger.audio.ogg.util.VorbisHeader;
 22  
 import org.jaudiotagger.audio.ogg.util.VorbisPacketType;
 23  
 import org.jaudiotagger.tag.Tag;
 24  
 import org.jaudiotagger.tag.vorbiscomment.VorbisCommentCreator;
 25  
 
 26  
 import java.io.UnsupportedEncodingException;
 27  
 import java.nio.ByteBuffer;
 28  
 import java.util.logging.Logger;
 29  
 
 30  
 /**
 31  
  * Creates an OggVorbis Comment Tag from a VorbisComment for use within an OggVorbis Container
 32  
  * <p/>
 33  
  * When a Vorbis Comment is used within OggVorbis it additionally has a vorbis header and a framing
 34  
  * bit.
 35  
  */
 36  42
 public class OggVorbisCommentTagCreator
 37  
 {
 38  
     // Logger Object
 39  42
     public static Logger logger = Logger.getLogger("org.jaudiotagger.audio.ogg");
 40  
 
 41  
     public static final int FIELD_FRAMING_BIT_LENGTH = 1;
 42  
     public static final byte FRAMING_BIT_VALID_VALUE = (byte) 0x01;
 43  42
     private VorbisCommentCreator creator = new VorbisCommentCreator();
 44  
 
 45  
     //Creates the ByteBuffer for the ogg tag
 46  
     public ByteBuffer convert(Tag tag) throws UnsupportedEncodingException
 47  
     {
 48  22
         ByteBuffer ogg = creator.convert(tag);
 49  22
         int tagLength = ogg.capacity() + VorbisHeader.FIELD_PACKET_TYPE_LENGTH + VorbisHeader.FIELD_CAPTURE_PATTERN_LENGTH + OggVorbisCommentTagCreator.FIELD_FRAMING_BIT_LENGTH;
 50  
 
 51  22
         ByteBuffer buf = ByteBuffer.allocate(tagLength);
 52  
 
 53  
         //[packet type=comment0x03]['vorbis']
 54  22
         buf.put((byte) VorbisPacketType.COMMENT_HEADER.getType());
 55  22
         buf.put(VorbisHeader.CAPTURE_PATTERN_AS_BYTES);
 56  
 
 57  
         //The actual tag
 58  22
         buf.put(ogg);
 59  
 
 60  
         //Framing bit = 1
 61  22
         buf.put(FRAMING_BIT_VALID_VALUE);
 62  
 
 63  22
         buf.rewind();
 64  22
         return buf;
 65  
     }
 66  
 }