Coverage Report - org.jaudiotagger.audio.asf.io.ChunkRemover
 
Classes in this File Line Coverage Branch Coverage Complexity
ChunkRemover
94%
15/16
50%
4/8
0
 
 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  
 import java.util.HashSet;
 10  
 import java.util.Set;
 11  
 
 12  
 /**
 13  
  * This {@link ChunkModifier} implementation is meant to remove selected chunks.<br>
 14  
  * 
 15  
  * @author Christian Laireiter
 16  
  */
 17  3
 public class ChunkRemover implements ChunkModifier
 18  
 {
 19  
 
 20  
     /**
 21  
      * Stores the GUIDs, which are about to be removed by this modifier.<br>
 22  
      */
 23  
     private final Set<GUID> toRemove;
 24  
 
 25  
     /**
 26  
      * Creates an instance, for removing selected chunks.<br>
 27  
      * @param guids the GUIDs which are about to be removed by this modifier.
 28  
      */
 29  
     public ChunkRemover(GUID... guids)
 30  28
     {
 31  28
         this.toRemove = new HashSet<GUID>();
 32  56
         for (GUID current : guids)
 33  
         {
 34  28
             this.toRemove.add(current);
 35  
         }
 36  28
     }
 37  
 
 38  
     /**
 39  
      * {@inheritDoc}
 40  
      */
 41  
     public boolean isApplicable(GUID guid)
 42  
     {
 43  54
         return this.toRemove.contains(guid);
 44  
     }
 45  
 
 46  
     /**
 47  
      * {@inheritDoc}
 48  
      */
 49  
     public ModificationResult modify(GUID guid, InputStream source, OutputStream destination) throws IOException
 50  
     {
 51  12
         ModificationResult result = null;
 52  12
         if (guid != null)
 53  
         {
 54  12
             assert isApplicable(guid);
 55  
             // skip the chunk length minus 24 bytes for the already read length and the guid.
 56  12
             final long chunkLen = Utils.readUINT64(source);
 57  12
             source.skip(chunkLen - 24);
 58  12
             result = new ModificationResult(-1, -1 * chunkLen, guid);
 59  12
         }
 60  
         else
 61  
         {
 62  
             // Now a chunk should be added, however, this implementation is for removal.
 63  0
             result = new ModificationResult(0, 0);
 64  
         }
 65  12
         return result;
 66  
     }
 67  
 
 68  
 }