protected static java.nio.ByteBuffer | uncompress(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
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);
|