Coverage Report - org.jaudiotagger.tag.mp4.field.Mp4TagRawBinaryField
 
Classes in this File Line Coverage Branch Coverage Complexity
Mp4TagRawBinaryField
57%
15/26
50%
2/4
1.455
 
 1  
 package org.jaudiotagger.tag.mp4.field;
 2  
 
 3  
 import org.jaudiotagger.audio.generic.Utils;
 4  
 import org.jaudiotagger.audio.mp4.atom.Mp4BoxHeader;
 5  
 import org.jaudiotagger.tag.TagField;
 6  
 import org.jaudiotagger.tag.mp4.Mp4TagField;
 7  
 
 8  
 import java.io.ByteArrayOutputStream;
 9  
 import java.io.IOException;
 10  
 import java.io.UnsupportedEncodingException;
 11  
 import java.nio.ByteBuffer;
 12  
 
 13  
 /**
 14  
  * Represents raw binary data
 15  
  * <p/>
 16  
  * <p>We use this when we find an atom under the ilst atom that we do not recognise , that does not
 17  
  * follow standard conventions in order to save the data without modification so it can be safetly
 18  
  * written back to file
 19  
  */
 20  
 public class Mp4TagRawBinaryField extends Mp4TagField
 21  
 {
 22  
     protected int dataSize;
 23  
     protected byte[] dataBytes;
 24  
 
 25  
 
 26  
     /**
 27  
      * Construct binary field from rawdata of audio file
 28  
      *
 29  
      * @param header
 30  
      * @param raw
 31  
      * @throws java.io.UnsupportedEncodingException
 32  
      *
 33  
      */
 34  
     public Mp4TagRawBinaryField(Mp4BoxHeader header, ByteBuffer raw) throws UnsupportedEncodingException
 35  
     {
 36  8
         super(header.getId());
 37  8
         dataSize = header.getDataLength();
 38  8
         build(raw);
 39  8
     }
 40  
 
 41  
     public Mp4FieldType getFieldType()
 42  
     {
 43  0
         return Mp4FieldType.IMPLICIT;
 44  
     }
 45  
 
 46  
     /**
 47  
      * Used when creating raw content
 48  
      *
 49  
      * @return
 50  
      * @throws java.io.UnsupportedEncodingException
 51  
      *
 52  
      */
 53  
     protected byte[] getDataBytes() throws UnsupportedEncodingException
 54  
     {
 55  0
         return dataBytes;
 56  
     }
 57  
 
 58  
 
 59  
     /**
 60  
      * Build from data
 61  
      * <p/>
 62  
      * <p>After returning buffers position will be after the end of this atom
 63  
      *
 64  
      * @param raw
 65  
      */
 66  
     protected void build(ByteBuffer raw)
 67  
     {
 68  
         //Read the raw data into byte array
 69  8
         this.dataBytes = new byte[dataSize];
 70  1456
         for (int i = 0; i < dataBytes.length; i++)
 71  
         {
 72  1448
             this.dataBytes[i] = raw.get();
 73  
         }
 74  8
     }
 75  
 
 76  
     public boolean isBinary()
 77  
     {
 78  0
         return true;
 79  
     }
 80  
 
 81  
     public boolean isEmpty()
 82  
     {
 83  0
         return this.dataBytes.length == 0;
 84  
     }
 85  
 
 86  
     public int getDataSize()
 87  
     {
 88  0
         return dataSize;
 89  
 
 90  
     }
 91  
 
 92  
     public byte[] getData()
 93  
     {
 94  0
         return this.dataBytes;
 95  
     }
 96  
 
 97  
     public void setData(byte[] d)
 98  
     {
 99  0
         this.dataBytes = d;
 100  0
     }
 101  
 
 102  
     public void copyContent(TagField field)
 103  
     {
 104  0
         throw new UnsupportedOperationException("not done");
 105  
     }
 106  
 
 107  
     public byte[] getRawContent() throws UnsupportedEncodingException
 108  
     {
 109  4
         logger.fine("Getting Raw data for:" + getId());
 110  
         try
 111  
         {
 112  4
             ByteArrayOutputStream outerbaos = new ByteArrayOutputStream();
 113  4
             outerbaos.write(Utils.getSizeBEInt32(Mp4BoxHeader.HEADER_LENGTH + dataSize));
 114  4
             outerbaos.write(Utils.getDefaultBytes(getId(), "ISO-8859-1"));
 115  4
             outerbaos.write(dataBytes);
 116  4
             System.out.println("SIZE" + outerbaos.size());
 117  4
             return outerbaos.toByteArray();
 118  
         }
 119  0
         catch (IOException ioe)
 120  
         {
 121  
             //This should never happen as were not actually writing to/from a file
 122  0
             throw new RuntimeException(ioe);
 123  
         }
 124  
     }
 125  
 
 126  
 }