com.smaxe.uv.fformat
Class Flv

java.lang.Object
  extended by com.smaxe.uv.fformat.Flv

public final class Flv
extends java.lang.Object

Flv - FLV file format parser.

Format:
[Header][PreviousTagSize0 (U32)][Tag1][PreviousTagSize1 (U32)][Tag2].... , where PreviousTagSize* is size of previous tag, including its header. For FLV version 1, this value is 11 plus the DataSize of the previous tag.

Author:
Andrei Sochirca

Nested Class Summary
static class Flv.Header
          Header - FLV file header.
static interface Flv.ITagProcessor
          ITagProcessor - tag processor.
static class Flv.ScriptData
          ScriptData - script data.
static class Flv.Tag
          Tag - FLV file tag.
static class Flv.TagProcessorAdapter
          TagProcessorAdapter - Flv.ITagProcessor adapter.
 
Method Summary
static void checkHeader(byte[] header)
          Checks the header of the FLV file correctness.
static Flv.Header readHeader(java.io.InputStream is)
          Reads the FLV file header from the is and points to the first file tag.
static Flv.ScriptData[] readScriptData(java.io.InputStream is, int length)
          Reads script data from the is.
static int readTag(java.io.InputStream is, Flv.ITagProcessor processor)
          Reads the tag from the is
static void writeHeader(java.io.OutputStream os, Flv.Header header)
          Writes the FLV file header to the os.
static void writeScriptData(java.io.OutputStream os, Flv.ScriptData[] scriptData)
          Writes script data to the os.
static void writeTag(java.io.OutputStream os, int type, long timestamp, byte[] buf, int offset, int length)
          Writes tag to the os.
static void writeTagHeader(java.io.OutputStream os, int type, long timestamp, int dataSize)
          Writes tag header to the os.
static void writeTagTrailer(java.io.OutputStream os, int dataSize)
          Writes tag trailer to the os.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

checkHeader

public static void checkHeader(byte[] header)
Checks the header of the FLV file correctness.

Parameters:
header - header bytes

readHeader

public static Flv.Header readHeader(java.io.InputStream is)
                             throws java.io.IOException
Reads the FLV file header from the is and points to the first file tag.

Parameters:
is -
Returns:
flv file header
Throws:
java.io.IOException - if an I/O exception occurred

writeHeader

public static void writeHeader(java.io.OutputStream os,
                               Flv.Header header)
                        throws java.io.IOException
Writes the FLV file header to the os.

Parameters:
os -
header - flv file header
Throws:
java.io.IOException - if an I/O exception occurred

readTag

public static int readTag(java.io.InputStream is,
                          Flv.ITagProcessor processor)
                   throws java.io.IOException
Reads the tag from the is

Parameters:
is -
processor - tag processor
Returns:
tag type, -1 if tag is not read
Throws:
java.io.IOException - if an I/O exception occurred

writeTag

public static void writeTag(java.io.OutputStream os,
                            int type,
                            long timestamp,
                            byte[] buf,
                            int offset,
                            int length)
                     throws java.io.IOException
Writes tag to the os.

Parameters:
os -
type - tag type
timestamp - tag timestamp
buf - data buffer
offset - data buffer offset
length - data buffer length
Throws:
java.io.IOException - if an I/O exception occurred

writeTagHeader

public static void writeTagHeader(java.io.OutputStream os,
                                  int type,
                                  long timestamp,
                                  int dataSize)
                           throws java.io.IOException
Writes tag header to the os.

Parameters:
os -
type - tag type
timestamp - tag timestamp
dataSize - data size
Throws:
java.io.IOException - if an I/O exception occurred

writeTagTrailer

public static void writeTagTrailer(java.io.OutputStream os,
                                   int dataSize)
                            throws java.io.IOException
Writes tag trailer to the os.

Parameters:
os -
dataSize - data size
Throws:
java.io.IOException - if an I/O exception occurred

readScriptData

public static Flv.ScriptData[] readScriptData(java.io.InputStream is,
                                              int length)
                                       throws java.io.IOException
Reads script data from the is.

Parameters:
is -
length - data length
Returns:
script data
Throws:
java.io.IOException - if an I/O exception occurred

writeScriptData

public static void writeScriptData(java.io.OutputStream os,
                                   Flv.ScriptData[] scriptData)
                            throws java.io.IOException
Writes script data to the os.

Parameters:
os -
scriptData - script data
Throws:
java.io.IOException - if an I/O exception occurred