| 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 | |
@SuppressWarnings({"ManualArrayToCollectionCopy"}) |
| 18 | 0 | public class ChunkRemover implements ChunkModifier { |
| 19 | |
|
| 20 | |
|
| 21 | |
|
| 22 | |
|
| 23 | |
private final Set<GUID> toRemove; |
| 24 | |
|
| 25 | |
|
| 26 | |
|
| 27 | |
|
| 28 | |
|
| 29 | |
|
| 30 | |
|
| 31 | 0 | public ChunkRemover(final GUID... guids) { |
| 32 | 0 | this.toRemove = new HashSet<GUID>(); |
| 33 | 0 | for (final GUID current : guids) { |
| 34 | 0 | this.toRemove.add(current); |
| 35 | |
} |
| 36 | 0 | } |
| 37 | |
|
| 38 | |
|
| 39 | |
|
| 40 | |
|
| 41 | |
public boolean isApplicable(final GUID guid) { |
| 42 | 0 | return this.toRemove.contains(guid); |
| 43 | |
} |
| 44 | |
|
| 45 | |
|
| 46 | |
|
| 47 | |
|
| 48 | |
public ModificationResult modify(final GUID guid, final InputStream source, |
| 49 | |
final OutputStream destination) throws IOException { |
| 50 | |
ModificationResult result; |
| 51 | 0 | if (guid == null) { |
| 52 | |
|
| 53 | |
|
| 54 | 0 | result = new ModificationResult(0, 0); |
| 55 | |
} else { |
| 56 | 0 | assert isApplicable(guid); |
| 57 | |
|
| 58 | |
|
| 59 | 0 | final long chunkLen = Utils.readUINT64(source); |
| 60 | 0 | source.skip(chunkLen - 24); |
| 61 | 0 | result = new ModificationResult(-1, -1 * chunkLen, guid); |
| 62 | |
} |
| 63 | 0 | return result; |
| 64 | |
} |
| 65 | |
|
| 66 | |
} |