Coverage Report - org.jaudiotagger.audio.asf.io.WriteableChunkModifer
 
Classes in this File Line Coverage Branch Coverage Complexity
WriteableChunkModifer
95%
18/19
58%
7/12
2.333
 
 1  
 package org.jaudiotagger.audio.asf.io;
 2  
 
 3  
 import org.jaudiotagger.audio.asf.data.GUID;
 4  
 import org.jaudiotagger.audio.asf.util.Utils;
 5  
 
 6  
 import java.io.IOException;
 7  
 import java.io.InputStream;
 8  
 import java.io.OutputStream;
 9  
 
 10  
 /**
 11  
  * A chunk modifier which works with information provided by {@link WriteableChunk} objects.<br>
 12  
  * 
 13  
  * @author Christian Laireiter
 14  
  */
 15  5
 public class WriteableChunkModifer implements ChunkModifier
 16  
 {
 17  
 
 18  
     /**
 19  
      * The chunk to write.
 20  
      */
 21  
     private WriteableChunk writableChunk;
 22  
 
 23  
     /**
 24  
      * Creates an instance.<br>
 25  
      * 
 26  
      * @param chunk chunk to write
 27  
      */
 28  
     public WriteableChunkModifer(WriteableChunk chunk)
 29  30
     {
 30  30
         this.writableChunk = chunk;
 31  30
     }
 32  
 
 33  
     /**
 34  
      * {@inheritDoc}
 35  
      */
 36  
     public boolean isApplicable(GUID guid)
 37  
     {
 38  122
         return guid.equals(this.writableChunk.getGuid());
 39  
     }
 40  
 
 41  
     /**
 42  
      * {@inheritDoc}
 43  
      */
 44  
     public ModificationResult modify(GUID guid, InputStream chunk, OutputStream destination) throws IOException
 45  
     {
 46  30
         int chunkDiff = 0;
 47  30
         long newSize = 0;
 48  30
         long oldSize = 0;
 49  30
         if (!this.writableChunk.isEmpty())
 50  
         {
 51  30
             newSize = this.writableChunk.writeInto(destination);
 52  30
             if (guid == null)
 53  
             {
 54  15
                 chunkDiff++;
 55  
             }
 56  
 
 57  
         }
 58  30
         if (guid != null)
 59  
         {
 60  15
             assert isApplicable(guid);
 61  15
             if (this.writableChunk.isEmpty())
 62  
             {
 63  0
                 chunkDiff--;
 64  
             }
 65  15
             oldSize = Utils.readUINT64(chunk);
 66  15
             chunk.skip(oldSize - 24);
 67  
         }
 68  30
         return new ModificationResult(chunkDiff, (newSize - oldSize), guid);
 69  
     }
 70  
 
 71  
 }