FileDocCategorySizeDatePackage
MetadataBlockHeader.javaAPI DocJaudiotagger 2.0.44408Fri Oct 28 12:41:04 BST 2011org.jaudiotagger.audio.flac.metadatablock

MetadataBlockHeader

public class MetadataBlockHeader extends Object
Metadata Block Header

Fields Summary
public static final int
BLOCK_TYPE_LENGTH
public static final int
BLOCK_LENGTH
public static final int
HEADER_LENGTH
private boolean
isLastBlock
private int
dataLength
private byte[]
bytes
private BlockType
blockType
Constructors Summary
public MetadataBlockHeader(ByteBuffer rawdata)
Construct header by reading bytes

param
rawdata

        isLastBlock = ((rawdata.get(0) & 0x80) >>> 7) == 1;

        int type = rawdata.get(0) & 0x7F;
        if (type < BlockType.values().length)
        {
            blockType = BlockType.values()[type];
        }


        dataLength = (u(rawdata.get(1)) << 16) + (u(rawdata.get(2)) << 8) + (u(rawdata.get(3)));

        bytes = new byte[HEADER_LENGTH];
        for (int i = 0; i < HEADER_LENGTH; i++)
        {
            bytes[i] = rawdata.get(i);
        }
        
public MetadataBlockHeader(boolean isLastBlock, BlockType blockType, int dataLength)
Construct a new header in order to write metadatablock to file

param
isLastBlock
param
blockType
param
dataLength

        ByteBuffer rawdata = ByteBuffer.allocate(HEADER_LENGTH);
        this.blockType = blockType;
        this.isLastBlock = isLastBlock;
        this.dataLength = dataLength;

        byte type;
        if (isLastBlock)
        {
            type = (byte) (0x80 | blockType.getId());
        }
        else
        {
            type = (byte) blockType.getId();
        }
        rawdata.put(type);

        //Size is 3Byte BigEndian int
        rawdata.put((byte) ((dataLength & 0xFF0000) >>> 16));
        rawdata.put((byte) ((dataLength & 0xFF00) >>> 8));
        rawdata.put((byte) (dataLength & 0xFF));

        bytes = new byte[HEADER_LENGTH];
        for (int i = 0; i < HEADER_LENGTH; i++)
        {
            bytes[i] = rawdata.get(i);
        }
    
Methods Summary
public BlockTypegetBlockType()

        return blockType;
    
public byte[]getBytes()

        return bytes;
    
public byte[]getBytesWithoutIsLastBlockFlag()

        bytes[0] = (byte) (bytes[0] & 0x7F);
        return bytes;
    
public intgetDataLength()

        return dataLength;
    
public booleanisLastBlock()

        return isLastBlock;
    
public static org.jaudiotagger.audio.flac.metadatablock.MetadataBlockHeaderreadHeader(java.io.RandomAccessFile raf)
Create header by reading from file

param
raf
return
throws
IOException


                    
          
    
        ByteBuffer rawdata = ByteBuffer.allocate(HEADER_LENGTH);
        int bytesRead = raf.getChannel().read(rawdata);
        if (bytesRead < HEADER_LENGTH)
        {
            throw new IOException("Unable to read required number of databytes read:" + bytesRead + ":required:" + HEADER_LENGTH);
        }
        rawdata.rewind();
        return new MetadataBlockHeader(rawdata);
    
public java.lang.StringtoString()

        return "BlockType:"+blockType + " DataLength:"+dataLength + " isLastBlock:"+isLastBlock;
    
private intu(int i)

        return i & 0xFF;