FileDocCategorySizeDatePackage
ID3Compression.javaAPI DocJaudiotagger 2.0.42507Wed Mar 30 16:12:06 BST 2011org.jaudiotagger.tag.id3

ID3Compression

public class ID3Compression extends Object
compresses frame data

Is currently required for V23Frames and V24Frames

Fields Summary
public static Logger
logger
Constructors Summary
Methods Summary
protected static java.nio.ByteBufferuncompress(java.lang.String identifier, java.lang.String filename, java.nio.ByteBuffer byteBuffer, int decompressedFrameSize, int realFrameSize)
Decompress realFrameSize bytes to decompressedFrameSize bytes and return as ByteBuffer

param
byteBuffer
param
decompressedFrameSize
param
realFrameSize
return
throws
org.jaudiotagger.tag.InvalidFrameException


                            
                 
    
        logger.config(filename + ":About to decompress " + realFrameSize + " bytes, expect result to be:" + decompressedFrameSize + " bytes");
        // Decompress the bytes into this buffer, size initialized from header field
        byte[] result = new byte[decompressedFrameSize];
        byte[] input = new byte[realFrameSize];

        //Store position ( just after frame header and any extra bits)
        //Read frame data into array, and then put buffer back to where it was
        int position = byteBuffer.position();
        byteBuffer.get(input, 0, realFrameSize);
        byteBuffer.position(position);

        Inflater decompresser = new Inflater();
        decompresser.setInput(input);
        try
        {
            int inflatedTo = decompresser.inflate(result);
            logger.config(filename + ":Decompressed to " + inflatedTo + " bytes");
        }
        catch (DataFormatException dfe)
        {
            logger.log(Level.CONFIG,"Unable to decompress this frame:"+identifier,dfe);

            //Update position of main buffer, so no attempt is made to reread these bytes
            byteBuffer.position(byteBuffer.position() + realFrameSize);
            throw new InvalidFrameException(ErrorMessage.ID3_UNABLE_TO_DECOMPRESS_FRAME.getMsg(identifier,filename,dfe.getMessage()));
        }
        decompresser.end();
        return ByteBuffer.wrap(result);