FileDocCategorySizeDatePackage
WriteableChunkModifer.javaAPI DocJaudiotagger 2.0.42386Wed Mar 30 16:11:50 BST 2011org.jaudiotagger.audio.asf.io

WriteableChunkModifer

public class WriteableChunkModifer extends Object implements ChunkModifier
A chunk modifier which works with information provided by {@link WriteableChunk} objects.
author
Christian Laireiter

Fields Summary
private final WriteableChunk
writableChunk
The chunk to write.
Constructors Summary
public WriteableChunkModifer(WriteableChunk chunk)
Creates an instance.

param
chunk chunk to write

        this.writableChunk = chunk;
    
Methods Summary
public booleanisApplicable(org.jaudiotagger.audio.asf.data.GUID guid)
{@inheritDoc}

        return guid.equals(this.writableChunk.getGuid());
    
public ModificationResultmodify(org.jaudiotagger.audio.asf.data.GUID guid, java.io.InputStream chunk, java.io.OutputStream destination)
{@inheritDoc}

 // NOPMD by Christian Laireiter on 5/9/09 5:03 PM
        int chunkDiff = 0;
        long newSize = 0;
        long oldSize = 0;
        /*
         * Replace the outputstream with the counting one, only if assert's are
         * evaluated.
         */
        assert (destination = new CountingOutputstream(destination)) != null;
        if (!this.writableChunk.isEmpty()) {
            newSize = this.writableChunk.writeInto(destination);
            assert newSize == this.writableChunk.getCurrentAsfChunkSize();
            /*
             * If assert's are evaluated, we have replaced destination by a
             * CountingOutpustream and can now verify if
             * getCurrentAsfChunkSize() really works correctly.
             */
            assert ((CountingOutputstream) destination).getCount() == newSize;
            if (guid == null) {
                chunkDiff++;
            }

        }
        if (guid != null) {
            assert isApplicable(guid);
            if (this.writableChunk.isEmpty()) {
                chunkDiff--;
            }
            oldSize = Utils.readUINT64(chunk);
            chunk.skip(oldSize - 24);
        }
        return new ModificationResult(chunkDiff, (newSize - oldSize), guid);