Examples of MetadataBlockHeader


Examples of org.jaudiotagger.audio.flac.metadatablock.MetadataBlockHeader

            FlacStreamReader flacStream = new FlacStreamReader(randomAccessFile);
            flacStream.findStream();
            boolean isLastBlock = false;
            String checksum = null;
            while (!isLastBlock) {
                MetadataBlockHeader mbh = MetadataBlockHeader.readHeader(randomAccessFile);
                if (mbh.getBlockType() == BlockType.STREAMINFO) {
                    ByteBuffer rawdata = ByteBuffer.allocate(mbh.getDataLength());
                    int bytesRead = randomAccessFile.getChannel().read(rawdata);
                    if (bytesRead < mbh.getDataLength()) {
                        throw new IOException("Unable to read required number of databytes read:" + bytesRead + ":required:" + mbh.getDataLength());
                    }
                    rawdata.rewind();
                    StringBuilder sb = new StringBuilder();
                    for (int i = 18; i < 34; i++) {
                        byte dataByte = rawdata.get(i);
                        sb.append(String.format("%02x", dataByte));
                    }
                    checksum = sb.toString();
                } else {
                    randomAccessFile.seek(randomAccessFile.getFilePointer() + mbh.getDataLength());
                }
                isLastBlock = mbh.isLastBlock();
            }
            checksum = checksum + String.format("-%08x", randomAccessFile.length() - randomAccessFile.getFilePointer());
            randomAccessFile.close();
            return checksum;
        } catch (CannotReadException e) {
View Full Code Here

Examples of org.jaudiotagger.audio.flac.metadatablock.MetadataBlockHeader

        //Search for StreamInfo Block, but even after we found it we still have to continue through all
        //the metadata blocks so that we can find the start of the audio frames which we need to calculate
        //the bitrate
        while (!isLastBlock) {
            MetadataBlockHeader mbh = MetadataBlockHeader.readHeader(raf);
            if (mbh.getBlockType() == BlockType.STREAMINFO) {
                mbdsi = new MetadataBlockDataStreamInfo(mbh, raf);
                if (!mbdsi.isValid()) {
                    throw new CannotReadException("FLAC StreamInfo not valid");
                }
            } else {
                raf.seek(raf.getFilePointer() + mbh.getDataLength());
            }

            isLastBlock = mbh.isLastBlock();
            mbh = null; //Free memory
        }

        if (mbdsi == null) {
            throw new CannotReadException("Unable to find Flac StreamInfo");
View Full Code Here

Examples of org.jaudiotagger.audio.flac.metadatablock.MetadataBlockHeader

        boolean isLastBlock = false;

        int count = 0;
        while (!isLastBlock) {
            MetadataBlockHeader mbh = MetadataBlockHeader.readHeader(raf);
//            //logger.info("Found block:" + mbh.getBlockType());
            raf.seek(raf.getFilePointer() + mbh.getDataLength());
            isLastBlock = mbh.isLastBlock();
            mbh = null; //Free memory
            count++;
        }
        raf.close();
        return count;
View Full Code Here

Examples of org.jaudiotagger.audio.flac.metadatablock.MetadataBlockHeader

        }

//        //logger.info("Convert flac tag:taglength:" + tagLength);
        ByteBuffer buf = ByteBuffer.allocate(tagLength + paddingSize);

        MetadataBlockHeader vorbisHeader;
        //If there are other metadata blocks
        if (flacTag.getVorbisCommentTag() != null) {
            if ((paddingSize > 0) || (flacTag.getImages().size() > 0)) {
                vorbisHeader = new MetadataBlockHeader(false, BlockType.VORBIS_COMMENT, vorbiscomment.capacity());
            } else {
                vorbisHeader = new MetadataBlockHeader(true, BlockType.VORBIS_COMMENT, vorbiscomment.capacity());
            }
            buf.put(vorbisHeader.getBytes());
            buf.put(vorbiscomment);
        }

        //Images
        ListIterator<MetadataBlockDataPicture> li = flacTag.getImages().listIterator();
        while (li.hasNext()) {
            MetadataBlockDataPicture imageField = li.next();
            MetadataBlockHeader imageHeader;

            if (paddingSize > 0 || li.hasNext()) {
                imageHeader = new MetadataBlockHeader(false, BlockType.PICTURE, imageField.getLength());
            } else {
                imageHeader = new MetadataBlockHeader(true, BlockType.PICTURE, imageField.getLength());
            }
            buf.put(imageHeader.getBytes());
            buf.put(imageField.getBytes());
        }

        //Padding
//        //logger.info("Convert flac tag at" + buf.position());
        if (paddingSize > 0) {
            int paddingDataSize = paddingSize - MetadataBlockHeader.HEADER_LENGTH;
            MetadataBlockHeader paddingHeader = new MetadataBlockHeader(true, BlockType.PADDING, paddingDataSize);
            MetadataBlockDataPadding padding = new MetadataBlockDataPadding(paddingDataSize);
            buf.put(paddingHeader.getBytes());
            buf.put(padding.getBytes());
        }
        buf.rewind();
        return buf;
    }
View Full Code Here

Examples of org.jaudiotagger.audio.flac.metadatablock.MetadataBlockHeader

        //Seems like we have a valid stream
        boolean isLastBlock = false;
        while (!isLastBlock) {
            //Read the header
            MetadataBlockHeader mbh = MetadataBlockHeader.readHeader(raf);

            //Is it one containing some sort of metadata, therefore interested in it?
            switch (mbh.getBlockType()) {
                //We got a vorbiscomment comment block, parse it
                case VORBIS_COMMENT:
                    byte[] commentHeaderRawPacket = new byte[mbh.getDataLength()];
                    raf.read(commentHeaderRawPacket);
                    tag = vorbisCommentReader.read(commentHeaderRawPacket, false);
                    break;

                case PICTURE:
                    try {
                        MetadataBlockDataPicture mbdp = new MetadataBlockDataPicture(mbh, raf);
                        images.add(mbdp);
                    } catch (IOException ioe) {
                        //logger.warning("Unable to read picture metablock, ignoring:" + ioe.getMessage());
                    } catch (InvalidFrameException ive) {
                        //logger.warning("Unable to read picture metablock, ignoring" + ive.getMessage());
                    }

                    break;

                //This is not a metadata block we are interested in so we skip to next block
                default:
                    raf.seek(raf.getFilePointer() + mbh.getDataLength());
                    break;
            }

            isLastBlock = mbh.isLastBlock();
            mbh = null;
        }

        //Note there may not be either a tag or any images, no problem this is valid however to make it easier we
        //just initialize Flac with an empty VorbisTag
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.