Coverage Report - org.jaudiotagger.tag.mp4.field.Mp4TagBinaryField
 
Classes in this File Line Coverage Branch Coverage Complexity
Mp4TagBinaryField
29%
8/27
0%
0/6
1.167
 
 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.tag.mp4.field;
 20  
 
 21  
 import org.jaudiotagger.audio.mp4.atom.Mp4BoxHeader;
 22  
 import org.jaudiotagger.tag.TagField;
 23  
 import org.jaudiotagger.tag.mp4.Mp4TagField;
 24  
 import org.jaudiotagger.tag.mp4.atom.Mp4DataBox;
 25  
 
 26  
 import java.io.UnsupportedEncodingException;
 27  
 import java.nio.ByteBuffer;
 28  
 
 29  
 /**
 30  
  * Represents binary data
 31  
  * <p/>
 32  
  * <p>Subclassed by cover art field,
 33  
  * TODO unaware of any other binary fields at the moment
 34  
  */
 35  
 public class Mp4TagBinaryField extends Mp4TagField
 36  
 {
 37  
     protected int dataSize;
 38  
     protected byte[] dataBytes;
 39  307
     protected boolean isBinary = false;
 40  
 
 41  
     /**
 42  
      * Construct an empty Binary Field
 43  
      *
 44  
      * @param id
 45  
      */
 46  
     public Mp4TagBinaryField(String id)
 47  
     {
 48  0
         super(id);
 49  0
     }
 50  
 
 51  
     /**
 52  
      * Construct new binary field with binarydata provided
 53  
      *
 54  
      * @param id
 55  
      * @param data
 56  
      * @throws UnsupportedEncodingException
 57  
      */
 58  
     public Mp4TagBinaryField(String id, byte[] data)
 59  
     {
 60  32
         super(id);
 61  32
         this.dataBytes = data;
 62  32
     }
 63  
 
 64  
     /**
 65  
      * Construct binary field from rawdata of audio file
 66  
      *
 67  
      * @param id
 68  
      * @param raw
 69  
      * @throws UnsupportedEncodingException
 70  
      */
 71  
     public Mp4TagBinaryField(String id, ByteBuffer raw) throws UnsupportedEncodingException
 72  
     {
 73  275
         super(id, raw);
 74  275
     }
 75  
 
 76  
     public Mp4FieldType getFieldType()
 77  
     {
 78  
         //TODO dont know what value this should be do we actually have any binary fields other
 79  
         //than cover art
 80  0
         return Mp4FieldType.IMPLICIT;
 81  
     }
 82  
 
 83  
     /**
 84  
      * Used when creating raw content
 85  
      *
 86  
      * @return
 87  
      * @throws UnsupportedEncodingException
 88  
      */
 89  
     protected byte[] getDataBytes() throws UnsupportedEncodingException
 90  
     {
 91  124
         return dataBytes;
 92  
     }
 93  
 
 94  
     protected void build(ByteBuffer raw)
 95  
     {
 96  0
         Mp4BoxHeader header = new Mp4BoxHeader(raw);
 97  0
         dataSize = header.getDataLength();
 98  
 
 99  
         //Skip the version and length fields
 100  0
         raw.position(raw.position() + Mp4DataBox.PRE_DATA_LENGTH);
 101  
 
 102  
         //Read the raw data into byte array
 103  0
         this.dataBytes = new byte[dataSize - Mp4DataBox.PRE_DATA_LENGTH];
 104  0
         for (int i = 0; i < dataBytes.length; i++)
 105  
         {
 106  0
             this.dataBytes[i] = raw.get();
 107  
         }
 108  
 
 109  
         //After returning buffers position will be after the end of this atom
 110  0
     }
 111  
 
 112  
     public boolean isBinary()
 113  
     {
 114  0
         return isBinary;
 115  
     }
 116  
 
 117  
     public boolean isEmpty()
 118  
     {
 119  0
         return this.dataBytes.length == 0;
 120  
     }
 121  
 
 122  
     public int getDataSize()
 123  
     {
 124  0
         return dataSize;
 125  
 
 126  
     }
 127  
 
 128  
     public byte[] getData()
 129  
     {
 130  352
         return this.dataBytes;
 131  
     }
 132  
 
 133  
     public void setData(byte[] d)
 134  
     {
 135  0
         this.dataBytes = d;
 136  0
     }
 137  
 
 138  
     public void copyContent(TagField field)
 139  
     {
 140  0
         if (field instanceof Mp4TagBinaryField)
 141  
         {
 142  0
             this.dataBytes = ((Mp4TagBinaryField) field).getData();
 143  0
             this.isBinary = field.isBinary();
 144  
         }
 145  0
     }
 146  
 }