FileDocCategorySizeDatePackage
AsfHeaderReader.javaAPI DocJaudiotagger 2.0.49095Wed Mar 30 16:11:50 BST 2011org.jaudiotagger.audio.asf.io

AsfHeaderReader

public class AsfHeaderReader extends ChunkContainerReader
This class reads an ASF header out of an input stream an creates an {@link org.jaudiotagger.audio.asf.data.AsfHeader} object if successful.
For now only ASF ver 1.0 is supported, because ver 2.0 seems not to be used anywhere.
ASF headers contains other chunks. As of this other readers of current package are called from within.
author
Christian Laireiter

Fields Summary
private static final org.jaudiotagger.audio.asf.data.GUID[]
APPLYING
The GUID this reader {@linkplain #getApplyingIds() applies to}
private static final AsfHeaderReader
FULL_READER
ASF reader configured to extract all information.
private static final AsfHeaderReader
INFO_READER
ASF reader configured to just extract information about audio streams.
If the ASF file only contains one audio stream it works fine.
private static final AsfHeaderReader
TAG_READER
ASF reader configured to just extract metadata information.
Constructors Summary
public AsfHeaderReader(List toRegister, boolean readChunkOnce)
Creates an instance of this reader.

param
toRegister The chunk readers to utilize.
param
readChunkOnce if true, each chunk type (identified by chunk GUID) will handled only once, if a reader is available, other chunks will be discarded.

        super(toRegister, readChunkOnce);
    
Methods Summary
public booleancanFail()
{@inheritDoc}

        return false;
    
protected org.jaudiotagger.audio.asf.data.AsfHeadercreateContainer(long streamPosition, java.math.BigInteger chunkLength, java.io.InputStream stream)
{@inheritDoc}

        final long chunkCount = Utils.readUINT32(stream);
        /*
         * 2 reserved bytes. first should be equal to 0x01 and second 0x02. ASF
         * specification suggests to not read the content if second byte is not
         * 0x02.
         */
        if (stream.read() != 1) {
            throw new IOException("No ASF"); //$NON-NLS-1$
        }
        if (stream.read() != 2) {
            throw new IOException("No ASF"); //$NON-NLS-1$
        }
        /*
         * Creating the resulting object
         */
        return new AsfHeader(streamPosition, chunkLength, chunkCount);
    
private static java.io.InputStreamcreateStream(java.io.RandomAccessFile raf)
Creates a Stream that will read from the specified {@link RandomAccessFile};

param
raf data source to read from.
return
a stream which accesses the source.


     
        final List<Class<? extends ChunkReader>> readers = new ArrayList<Class<? extends ChunkReader>>();
        readers.add(FileHeaderReader.class);
        readers.add(StreamChunkReader.class);
        INFO_READER = new AsfHeaderReader(readers, true);
        readers.clear();
        readers.add(ContentDescriptionReader.class);
        readers.add(ContentBrandingReader.class);
        readers.add(LanguageListReader.class);
        readers.add(MetadataReader.class);
        /*
         * Create the header extension object readers with just content
         * description reader, extended content description reader, language
         * list reader and both metadata object readers.
         */
        final AsfExtHeaderReader extReader = new AsfExtHeaderReader(readers,
                true);
        final AsfExtHeaderReader extReader2 = new AsfExtHeaderReader(readers,
                true);
        TAG_READER = new AsfHeaderReader(readers, true);
        TAG_READER.setExtendedHeaderReader(extReader);
        readers.add(FileHeaderReader.class);
        readers.add(StreamChunkReader.class);
        readers.add(EncodingChunkReader.class);
        readers.add(EncryptionChunkReader.class);
        readers.add(StreamBitratePropertiesReader.class);
        FULL_READER = new AsfHeaderReader(readers, false);
        FULL_READER.setExtendedHeaderReader(extReader2);
    
        return new FullRequestInputStream(new BufferedInputStream(
                new RandomAccessFileInputstream(raf)));
    
public org.jaudiotagger.audio.asf.data.GUID[]getApplyingIds()
{@inheritDoc}

        return APPLYING.clone();
    
public static org.jaudiotagger.audio.asf.data.AsfHeaderreadHeader(java.io.File file)
This method extracts the full ASF-Header from the given file.
If no header could be extracted null is returned.

param
file the ASF file to read.
return
AsfHeader-Wrapper, or null if no supported ASF header was found.
throws
IOException on I/O Errors.

        final InputStream stream = new FileInputStream(file);
        final AsfHeader result = FULL_READER.read(Utils.readGUID(stream),
                stream, 0);
        stream.close();
        return result;
    
public static org.jaudiotagger.audio.asf.data.AsfHeaderreadHeader(java.io.RandomAccessFile file)
This method tries to extract a full ASF-header out of the given stream.
If no header could be extracted null is returned.

param
file File which contains the ASF header.
return
AsfHeader-Wrapper, or null if no supported ASF header was found.
throws
IOException Read errors

        final InputStream stream = createStream(file);
        return FULL_READER.read(Utils.readGUID(stream), stream, 0);
    
public static org.jaudiotagger.audio.asf.data.AsfHeaderreadInfoHeader(java.io.RandomAccessFile file)
This method tries to extract an ASF-header out of the given stream, which only contains information about the audio stream.
If no header could be extracted null is returned.

param
file File which contains the ASF header.
return
AsfHeader-Wrapper, or null if no supported ASF header was found.
throws
IOException Read errors

        final InputStream stream = createStream(file);
        return INFO_READER.read(Utils.readGUID(stream), stream, 0);
    
public static org.jaudiotagger.audio.asf.data.AsfHeaderreadTagHeader(java.io.RandomAccessFile file)
This method tries to extract an ASF-header out of the given stream, which only contains metadata.
If no header could be extracted null is returned.

param
file File which contains the ASF header.
return
AsfHeader-Wrapper, or null if no supported ASF header was found.
throws
IOException Read errors

        final InputStream stream = createStream(file);
        return TAG_READER.read(Utils.readGUID(stream), stream, 0);
    
public voidsetExtendedHeaderReader(AsfExtHeaderReader extReader)
Sets the {@link AsfExtHeaderReader}, which is to be used, when an header extension object is found.

param
extReader header extension object reader.

        for (final GUID curr : extReader.getApplyingIds()) {
            this.readerMap.put(curr, extReader);
        }