Coverage Report - org.jaudiotagger.tag.datatype.ByteArraySizeTerminated
 
Classes in this File Line Coverage Branch Coverage Complexity
ByteArraySizeTerminated
76%
19/25
60%
6/10
2.286
 
 1  
 /**
 2  
  *  @author : Paul Taylor
 3  
  *  @author : Eric Farng
 4  
  *
 5  
  *  Version @version:$Id: ByteArraySizeTerminated.java,v 1.8 2008/07/21 10:45:41 paultaylor Exp $
 6  
  *
 7  
  *  MusicTag Copyright (C)2003,2004
 8  
  *
 9  
  *  This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser
 10  
  *  General Public  License as published by the Free Software Foundation; either version 2.1 of the License,
 11  
  *  or (at your option) any later version.
 12  
  *
 13  
  *  This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
 14  
  *  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 15  
  *  See the GNU Lesser General Public License for more details.
 16  
  *
 17  
  *  You should have received a copy of the GNU Lesser General Public License along with this library; if not,
 18  
  *  you can get a copy from http://www.opensource.org/licenses/lgpl-license.php or write to the Free Software
 19  
  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 20  
  *
 21  
  * Description:
 22  
  *
 23  
  */
 24  
 package org.jaudiotagger.tag.datatype;
 25  
 
 26  
 import org.jaudiotagger.tag.InvalidDataTypeException;
 27  
 import org.jaudiotagger.tag.id3.AbstractTagFrameBody;
 28  
 
 29  
 /**
 30  
  * Represents a stream of bytes, continuing until the end of the buffer. Usually used for binary data or where
 31  
  * we havent yet mapped the data to a better fitting type.
 32  
  */
 33  
 public class ByteArraySizeTerminated extends AbstractDataType
 34  
 {
 35  
     public ByteArraySizeTerminated(String identifier, AbstractTagFrameBody frameBody)
 36  
     {
 37  240
         super(identifier, frameBody);
 38  240
     }
 39  
 
 40  
     public ByteArraySizeTerminated(ByteArraySizeTerminated object)
 41  
     {
 42  86
         super(object);
 43  86
     }
 44  
 
 45  
     /**
 46  
      * Return the size in byte of this datatype
 47  
      *
 48  
      * @return the size in bytes
 49  
      */
 50  
     public int getSize()
 51  
     {
 52  224
         int len = 0;
 53  
 
 54  224
         if (value != null)
 55  
         {
 56  203
             len = ((byte[]) value).length;
 57  
         }
 58  
 
 59  224
         return len;
 60  
     }
 61  
 
 62  
     public boolean equals(Object obj)
 63  
     {
 64  0
         if (obj instanceof ByteArraySizeTerminated == false)
 65  
         {
 66  0
             return false;
 67  
         }
 68  
 
 69  0
         return super.equals(obj);
 70  
     }
 71  
 
 72  
     /**
 73  
      * @param arr
 74  
      * @param offset
 75  
      * @throws NullPointerException
 76  
      * @throws IndexOutOfBoundsException
 77  
      */
 78  
     public void readByteArray(byte[] arr, int offset) throws InvalidDataTypeException
 79  
     {
 80  154
         if (arr == null)
 81  
         {
 82  0
             throw new NullPointerException("Byte array is null");
 83  
         }
 84  
 
 85  154
         if (offset < 0)
 86  
         {
 87  0
             throw new IndexOutOfBoundsException("Offset to byte array is out of bounds: offset = " + offset + ", array.length = " + arr.length);
 88  
         }
 89  
 
 90  
         //Empty Byte Array
 91  154
         if (offset >= arr.length)
 92  
         {
 93  13
             value = null;
 94  13
             return;
 95  
         }
 96  
 
 97  141
         int len = arr.length - offset;
 98  141
         value = new byte[len];
 99  141
         System.arraycopy(arr, offset, value, 0, len);
 100  141
     }
 101  
 
 102  
     /**
 103  
      * Because this is usually binary data and could be very long we just return
 104  
      * the number of bytes held
 105  
      *
 106  
      * @return the number of bytes
 107  
      */
 108  
     public String toString()
 109  
     {
 110  0
         return getSize() + " bytes";
 111  
     }
 112  
 
 113  
     /**
 114  
      * Write contents to a byte array
 115  
      *
 116  
      * @return a byte array that that contians the data that should be perisisted to file
 117  
      */
 118  
     public byte[] writeByteArray()
 119  
     {
 120  70
         logger.info("Writing byte array" + this.getIdentifier());
 121  70
         return (byte[]) value;
 122  
     }
 123  
 }