Coverage Report - org.jaudiotagger.audio.asf.io.LanguageListReader
 
Classes in this File Line Coverage Branch Coverage Complexity
LanguageListReader
100%
14/14
50%
6/12
1.667
 
 1  
 package org.jaudiotagger.audio.asf.io;
 2  
 
 3  
 import org.jaudiotagger.audio.asf.data.Chunk;
 4  
 import org.jaudiotagger.audio.asf.data.GUID;
 5  
 import org.jaudiotagger.audio.asf.data.LanguageList;
 6  
 import org.jaudiotagger.audio.asf.util.Utils;
 7  
 
 8  
 import java.io.IOException;
 9  
 import java.io.InputStream;
 10  
 import java.math.BigInteger;
 11  
 
 12  
 /**
 13  
  * Reads and interprets the &quot;Language List Object&quot; of ASF files.<br>
 14  
  * 
 15  
  * @author Christian Laireiter
 16  
  */
 17  28
 public class LanguageListReader implements ChunkReader {
 18  
 
 19  
     /**
 20  
      * The GUID this reader {@linkplain #getApplyingIds() applies to}
 21  
      */
 22  4
     private final static GUID[] APPLYING = { GUID.GUID_LANGUAGE_LIST };
 23  
 
 24  
     /**
 25  
      * {@inheritDoc}
 26  
      */
 27  
     public boolean canFail() {
 28  4
         return false;
 29  
     }
 30  
 
 31  
     /**
 32  
      * {@inheritDoc}
 33  
      */
 34  
     public GUID[] getApplyingIds() {
 35  24
         return APPLYING.clone();
 36  
     }
 37  
 
 38  
     /**
 39  
      * {@inheritDoc}
 40  
      */
 41  
     public Chunk read(final GUID guid, final InputStream stream,
 42  
             final long streamPosition) throws IOException {
 43  4
         assert GUID.GUID_LANGUAGE_LIST.equals(guid);
 44  4
         final BigInteger chunkLen = Utils.readBig64(stream);
 45  
 
 46  4
         final int readUINT16 = Utils.readUINT16(stream);
 47  
 
 48  4
         final LanguageList result = new LanguageList(streamPosition, chunkLen);
 49  8
         for (int i = 0; i < readUINT16; i++) {
 50  4
             final int langIdLen = (stream.read() & 0xFF);
 51  4
             final String langId = Utils
 52  
                     .readFixedSizeUTF16Str(stream, langIdLen);
 53  
             // langIdLen = 2 bytes for each char and optionally one zero
 54  
             // termination character
 55  4
             assert langId.length() == langIdLen / 2 - 1
 56  
                     || langId.length() == langIdLen / 2;
 57  4
             result.addLanguage(langId);
 58  
         }
 59  
 
 60  4
         return result;
 61  
     }
 62  
 
 63  
 }