Coverage Report - org.jaudiotagger.audio.asf.io.ContentDescriptionReader
 
Classes in this File Line Coverage Branch Coverage Complexity
ContentDescriptionReader
100%
27/27
87%
14/16
2.6
 
 1  
 /*
 2  
  * Entagged Audio Tag library
 3  
  * Copyright (c) 2004-2005 Christian Laireiter <liree@web.de>
 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.asf.io;
 20  
 
 21  
 import org.jaudiotagger.audio.asf.data.Chunk;
 22  
 import org.jaudiotagger.audio.asf.data.ContentDescription;
 23  
 import org.jaudiotagger.audio.asf.data.GUID;
 24  
 import org.jaudiotagger.audio.asf.util.Utils;
 25  
 
 26  
 import java.io.IOException;
 27  
 import java.io.InputStream;
 28  
 import java.math.BigInteger;
 29  
 
 30  
 /**
 31  
  * Reads and interprets the data of a ASF chunk containing title, author... <br>
 32  
  * 
 33  
  * @author Christian Laireiter
 34  
  * @see org.jaudiotagger.audio.asf.data.ContentDescription
 35  
  */
 36  
 public class ContentDescriptionReader implements ChunkReader {
 37  
 
 38  
     /**
 39  
      * The GUID this reader {@linkplain #getApplyingIds() applies to}
 40  
      */
 41  4
     private final static GUID[] APPLYING = { GUID.GUID_CONTENTDESCRIPTION };
 42  
 
 43  
     /**
 44  
      * Should not be used for now.
 45  
      */
 46  24
     protected ContentDescriptionReader() {
 47  
         // NOTHING toDo
 48  24
     }
 49  
 
 50  
     /**
 51  
      * {@inheritDoc}
 52  
      */
 53  
     public boolean canFail() {
 54  295
         return false;
 55  
     }
 56  
 
 57  
     /**
 58  
      * {@inheritDoc}
 59  
      */
 60  
     public GUID[] getApplyingIds() {
 61  24
         return APPLYING.clone();
 62  
     }
 63  
 
 64  
     /**
 65  
      * Returns the next 5 UINT16 values as an array.<br>
 66  
      * 
 67  
      * @param stream
 68  
      *            stream to read from
 69  
      * @return 5 int values read from stream.
 70  
      * @throws IOException
 71  
      *             on I/O Errors.
 72  
      */
 73  
     private int[] getStringSizes(final InputStream stream) throws IOException {
 74  295
         final int[] result = new int[5];
 75  1770
         for (int i = 0; i < result.length; i++) {
 76  1475
             result[i] = Utils.readUINT16(stream);
 77  
         }
 78  295
         return result;
 79  
     }
 80  
 
 81  
     /**
 82  
      * {@inheritDoc}
 83  
      */
 84  
     public Chunk read(final GUID guid, final InputStream stream,
 85  
             final long chunkStart) throws IOException {
 86  295
         final BigInteger chunkSize = Utils.readBig64(stream);
 87  
         /*
 88  
          * Now comes 16-Bit values representing the length of the Strings which
 89  
          * follows.
 90  
          */
 91  295
         final int[] stringSizes = getStringSizes(stream);
 92  
 
 93  
         /*
 94  
          * Now we know the String length of each occuring String.
 95  
          */
 96  295
         final String[] strings = new String[stringSizes.length];
 97  1770
         for (int i = 0; i < strings.length; i++) {
 98  1475
             if (stringSizes[i] > 0) {
 99  1299
                 strings[i] = Utils
 100  
                         .readFixedSizeUTF16Str(stream, stringSizes[i]);
 101  
             }
 102  
         }
 103  
         /*
 104  
          * Now create the result
 105  
          */
 106  295
         final ContentDescription result = new ContentDescription(chunkStart,
 107  
                 chunkSize);
 108  295
         if (stringSizes[0] > 0) {
 109  295
             result.setTitle(strings[0]);
 110  
         }
 111  295
         if (stringSizes[1] > 0) {
 112  295
             result.setAuthor(strings[1]);
 113  
         }
 114  295
         if (stringSizes[2] > 0) {
 115  281
             result.setCopyright(strings[2]);
 116  
         }
 117  295
         if (stringSizes[3] > 0) {
 118  283
             result.setComment(strings[3]);
 119  
         }
 120  295
         if (stringSizes[4] > 0) {
 121  145
             result.setRating(strings[4]);
 122  
         }
 123  295
         return result;
 124  
     }
 125  
 }