FileDocCategorySizeDatePackage
FlacStreamReader.javaAPI DocJaudiotagger 2.0.42928Thu Apr 28 12:41:36 BST 2011org.jaudiotagger.audio.flac

FlacStreamReader

public class FlacStreamReader extends Object
Flac Stream

Reader files and identifies if this is in fact a flac stream

Fields Summary
public static Logger
logger
public static final int
FLAC_STREAM_IDENTIFIER_LENGTH
public static final String
FLAC_STREAM_IDENTIFIER
private RandomAccessFile
raf
private int
startOfFlacInFile
Constructors Summary
public FlacStreamReader(RandomAccessFile raf)
Create instance for holding stream info

param
raf


                 
      
    
        this.raf = raf;

    
Methods Summary
public voidfindStream()
Reads the stream block to ensure it is a flac file

throws
IOException
throws
CannotReadException

        //Begins tag parsing
        if (raf.length() == 0)
        {
            //Empty File
            throw new CannotReadException("Error: File empty");
        }
        raf.seek(0);

        //FLAC Stream at start
        if (isFlacHeader())
        {
            startOfFlacInFile = 0;
            return;
        }

        //Ok maybe there is an ID3v24tag first
        if (isId3v2Tag())
        {
            startOfFlacInFile = (int) (raf.getFilePointer() - FLAC_STREAM_IDENTIFIER_LENGTH);
            return;
        }
        throw new CannotReadException(ErrorMessage.FLAC_NO_FLAC_HEADER_FOUND.getMsg());
    
public intgetStartOfFlacInFile()
Usually flac header is at start of file, but unofficially and ID3 tag is allowed at the start of the file.

return
the start of the Flac within file

        return startOfFlacInFile;
    
private booleanisFlacHeader()

        //FLAC Stream at start
        byte[] b = new byte[FLAC_STREAM_IDENTIFIER_LENGTH];
        raf.read(b);
        String flac = new String(b);
        return flac.equals(FLAC_STREAM_IDENTIFIER);
    
private booleanisId3v2Tag()

        raf.seek(0);
        if(AbstractID3v2Tag.isId3Tag(raf))
        {
            logger.warning(ErrorMessage.FLAC_CONTAINS_ID3TAG.getMsg(raf.getFilePointer()));
            //FLAC Stream immediately after end of id3 tag
            if (isFlacHeader())
            {
                return true;
            }
        }
        return false;