| 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 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | 3 | public class ChunkRemover implements ChunkModifier |
| 18 | |
{ |
| 19 | |
|
| 20 | |
|
| 21 | |
|
| 22 | |
|
| 23 | |
private final Set<GUID> toRemove; |
| 24 | |
|
| 25 | |
|
| 26 | |
|
| 27 | |
|
| 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 | |
|
| 40 | |
|
| 41 | |
public boolean isApplicable(GUID guid) |
| 42 | |
{ |
| 43 | 54 | return this.toRemove.contains(guid); |
| 44 | |
} |
| 45 | |
|
| 46 | |
|
| 47 | |
|
| 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 | |
|
| 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 | |
|
| 63 | 0 | result = new ModificationResult(0, 0); |
| 64 | |
} |
| 65 | 12 | return result; |
| 66 | |
} |
| 67 | |
|
| 68 | |
} |