Coverage Report - org.jaudiotagger.tag.datatype.ByteArraySizeTerminated
 
Classes in this File Line Coverage Branch Coverage Complexity
ByteArraySizeTerminated
82%
19/23
50%
6/12
2.143
 
 1  
 /**
 2  
  *  @author : Paul Taylor
 3  
  *  @author : Eric Farng
 4  
  *
 5  
  *  Version @version:$Id: ByteArraySizeTerminated.java 836 2009-11-12 15:44:07Z paultaylor $
 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  876
         super(identifier, frameBody);
 38  876
     }
 39  
 
 40  
     public ByteArraySizeTerminated(ByteArraySizeTerminated object)
 41  
     {
 42  337
         super(object);
 43  337
     }
 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  775
         int len = 0;
 53  
 
 54  775
         if (value != null)
 55  
         {
 56  691
             len = ((byte[]) value).length;
 57  
         }
 58  
 
 59  775
         return len;
 60  
     }
 61  
 
 62  
     public boolean equals(Object obj)
 63  
     {
 64  0
         return obj instanceof ByteArraySizeTerminated && super.equals(obj);
 65  
 
 66  
     }
 67  
 
 68  
     /**
 69  
      * @param arr
 70  
      * @param offset
 71  
      * @throws NullPointerException
 72  
      * @throws IndexOutOfBoundsException
 73  
      */
 74  
     public void readByteArray(byte[] arr, int offset) throws InvalidDataTypeException
 75  
     {
 76  502
         if (arr == null)
 77  
         {
 78  0
             throw new NullPointerException("Byte array is null");
 79  
         }
 80  
 
 81  502
         if (offset < 0)
 82  
         {
 83  0
             throw new IndexOutOfBoundsException("Offset to byte array is out of bounds: offset = " + offset + ", array.length = " + arr.length);
 84  
         }
 85  
 
 86  
         //Empty Byte Array
 87  502
         if (offset >= arr.length)
 88  
         {
 89  52
             value = null;
 90  52
             return;
 91  
         }
 92  
 
 93  450
         int len = arr.length - offset;
 94  450
         value = new byte[len];
 95  450
         System.arraycopy(arr, offset, value, 0, len);
 96  450
     }
 97  
 
 98  
     /**
 99  
      * Because this is usually binary data and could be very long we just return
 100  
      * the number of bytes held
 101  
      *
 102  
      * @return the number of bytes
 103  
      */
 104  
     public String toString()
 105  
     {
 106  0
         return getSize() + " bytes";
 107  
     }
 108  
 
 109  
     /**
 110  
      * Write contents to a byte array
 111  
      *
 112  
      * @return a byte array that that contians the data that should be perisisted to file
 113  
      */
 114  
     public byte[] writeByteArray()
 115  
     {
 116  273
         logger.info("Writing byte array" + this.getIdentifier());
 117  273
         return (byte[]) value;
 118  
     }
 119  
 }