org.jaudiotagger.audio.ogg
Class OggVorbisTagWriter

java.lang.Object
  extended by org.jaudiotagger.audio.ogg.OggVorbisTagWriter

public class OggVorbisTagWriter
extends java.lang.Object

Write Vorbis Tag within an ogg

VorbisComment holds the tag information within an ogg file


Field Summary
static java.util.logging.Logger logger
           
private  OggVorbisTagReader reader
           
private  OggVorbisCommentTagCreator tc
           
 
Constructor Summary
OggVorbisTagWriter()
           
 
Method Summary
private  void calculateChecksumOverPage(java.nio.ByteBuffer page)
          Calculate checkSum over the Page
private  byte[] createSegments(int length, boolean quitStream)
          This method creates a byte array of values whose sum should be the value of length.
private  byte[] createSegmentTable(int newCommentLength, int setupHeaderLength, java.util.List<OggPageHeader.PacketStartAndLength> extraPackets)
          This method creates a new segment table for the second page (header).
private  byte[] createSegmentTable(int setupHeaderLength, java.util.List<OggPageHeader.PacketStartAndLength> extraPackets)
          This method creates a new segment table for the second half of setup header
 void delete(java.io.RandomAccessFile raf, java.io.RandomAccessFile tempRaf)
           
private  boolean isCommentAndSetupHeaderFitsOnASinglePage(int commentLength, int setupHeaderLength, java.util.List<OggPageHeader.PacketStartAndLength> extraPacketList)
           
private  void replacePagesAndRenumberPageSeqs(OggVorbisTagReader.OggVorbisHeaderSizes originalHeaderSizes, int newCommentLength, OggPageHeader secondPageHeader, java.nio.ByteBuffer newComment, java.io.RandomAccessFile raf, java.io.RandomAccessFile rafTemp)
          CommentHeader extends over multiple pages OR Comment Header doesnt but it's got larger causing some extra packets to be shifted onto another page.
private  void replaceSecondPageAndRenumberPageSeqs(OggVorbisTagReader.OggVorbisHeaderSizes originalHeaderSizes, int newCommentLength, int newSecondPageLength, OggPageHeader secondPageHeader, java.nio.ByteBuffer newComment, java.io.RandomAccessFile raf, java.io.RandomAccessFile rafTemp)
          Previously comment and/or setup header was on a number of pages now can just replace this page fitting all on 2nd page, and renumber subsequent sequence pages
private  void replaceSecondPageOnly(OggVorbisTagReader.OggVorbisHeaderSizes vorbisHeaderSizes, int newCommentLength, int newSecondPageLength, OggPageHeader secondPageHeader, java.nio.ByteBuffer newComment, long secondPageHeaderEndPos, java.io.RandomAccessFile raf, java.io.RandomAccessFile rafTemp)
          Usually can use this method, previously comment and setup header all fit on page 2 and they still do, so just replace this page.
private  java.nio.ByteBuffer startCreateBasicSecondPage(OggVorbisTagReader.OggVorbisHeaderSizes vorbisHeaderSizes, int newCommentLength, int newSecondPageLength, OggPageHeader secondPageHeader, java.nio.ByteBuffer newComment)
          Create a second Page, and add comment header to it, but page is incomplete may want to add addition header and need to calculate CRC
 void write(Tag tag, java.io.RandomAccessFile raf, java.io.RandomAccessFile rafTemp)
           
 void writeRemainingPages(int pageSequence, java.io.RandomAccessFile raf, java.io.RandomAccessFile rafTemp)
          Write all the remaining pages as they are except that the page sequence needs to be modified.
 void writeRemainingPagesOld(int pageSequence, java.io.RandomAccessFile raf, java.io.RandomAccessFile rafTemp)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

public static java.util.logging.Logger logger

tc

private OggVorbisCommentTagCreator tc

reader

private OggVorbisTagReader reader
Constructor Detail

OggVorbisTagWriter

public OggVorbisTagWriter()
Method Detail

delete

public void delete(java.io.RandomAccessFile raf,
                   java.io.RandomAccessFile tempRaf)
            throws java.io.IOException,
                   CannotReadException,
                   CannotWriteException
Throws:
java.io.IOException
CannotReadException
CannotWriteException

write

public void write(Tag tag,
                  java.io.RandomAccessFile raf,
                  java.io.RandomAccessFile rafTemp)
           throws CannotReadException,
                  CannotWriteException,
                  java.io.IOException
Throws:
CannotReadException
CannotWriteException
java.io.IOException

calculateChecksumOverPage

private void calculateChecksumOverPage(java.nio.ByteBuffer page)
Calculate checkSum over the Page

Parameters:
page -

startCreateBasicSecondPage

private java.nio.ByteBuffer startCreateBasicSecondPage(OggVorbisTagReader.OggVorbisHeaderSizes vorbisHeaderSizes,
                                                       int newCommentLength,
                                                       int newSecondPageLength,
                                                       OggPageHeader secondPageHeader,
                                                       java.nio.ByteBuffer newComment)
                                                throws java.io.IOException
Create a second Page, and add comment header to it, but page is incomplete may want to add addition header and need to calculate CRC

Parameters:
vorbisHeaderSizes -
newCommentLength -
newSecondPageLength -
secondPageHeader -
newComment -
Returns:
Throws:
java.io.IOException

replaceSecondPageOnly

private void replaceSecondPageOnly(OggVorbisTagReader.OggVorbisHeaderSizes vorbisHeaderSizes,
                                   int newCommentLength,
                                   int newSecondPageLength,
                                   OggPageHeader secondPageHeader,
                                   java.nio.ByteBuffer newComment,
                                   long secondPageHeaderEndPos,
                                   java.io.RandomAccessFile raf,
                                   java.io.RandomAccessFile rafTemp)
                            throws java.io.IOException
Usually can use this method, previously comment and setup header all fit on page 2 and they still do, so just replace this page. And copy further pages as is.

Parameters:
vorbisHeaderSizes -
newCommentLength -
newSecondPageLength -
secondPageHeader -
newComment -
secondPageHeaderEndPos -
raf -
rafTemp -
Throws:
java.io.IOException

replaceSecondPageAndRenumberPageSeqs

private void replaceSecondPageAndRenumberPageSeqs(OggVorbisTagReader.OggVorbisHeaderSizes originalHeaderSizes,
                                                  int newCommentLength,
                                                  int newSecondPageLength,
                                                  OggPageHeader secondPageHeader,
                                                  java.nio.ByteBuffer newComment,
                                                  java.io.RandomAccessFile raf,
                                                  java.io.RandomAccessFile rafTemp)
                                           throws java.io.IOException,
                                                  CannotReadException,
                                                  CannotWriteException
Previously comment and/or setup header was on a number of pages now can just replace this page fitting all on 2nd page, and renumber subsequent sequence pages

Parameters:
originalHeaderSizes -
newCommentLength -
newSecondPageLength -
secondPageHeader -
newComment -
raf -
rafTemp -
Throws:
java.io.IOException
CannotReadException
CannotWriteException

replacePagesAndRenumberPageSeqs

private void replacePagesAndRenumberPageSeqs(OggVorbisTagReader.OggVorbisHeaderSizes originalHeaderSizes,
                                             int newCommentLength,
                                             OggPageHeader secondPageHeader,
                                             java.nio.ByteBuffer newComment,
                                             java.io.RandomAccessFile raf,
                                             java.io.RandomAccessFile rafTemp)
                                      throws java.io.IOException,
                                             CannotReadException,
                                             CannotWriteException
CommentHeader extends over multiple pages OR Comment Header doesnt but it's got larger causing some extra packets to be shifted onto another page.

Parameters:
originalHeaderSizes -
newCommentLength -
secondPageHeader -
newComment -
raf -
rafTemp -
Throws:
java.io.IOException
CannotReadException
CannotWriteException

writeRemainingPages

public void writeRemainingPages(int pageSequence,
                                java.io.RandomAccessFile raf,
                                java.io.RandomAccessFile rafTemp)
                         throws java.io.IOException,
                                CannotReadException,
                                CannotWriteException
Write all the remaining pages as they are except that the page sequence needs to be modified.

Parameters:
pageSequence -
raf -
rafTemp -
Throws:
java.io.IOException
CannotReadException
CannotWriteException

writeRemainingPagesOld

public void writeRemainingPagesOld(int pageSequence,
                                   java.io.RandomAccessFile raf,
                                   java.io.RandomAccessFile rafTemp)
                            throws java.io.IOException,
                                   CannotReadException,
                                   CannotWriteException
Throws:
java.io.IOException
CannotReadException
CannotWriteException

createSegmentTable

private byte[] createSegmentTable(int newCommentLength,
                                  int setupHeaderLength,
                                  java.util.List<OggPageHeader.PacketStartAndLength> extraPackets)
This method creates a new segment table for the second page (header).

Parameters:
newCommentLength - The length of the Vorbis Comment
setupHeaderLength - The length of Setup Header, zero if comment String extends over multiple pages and this is not the last page.
extraPackets - If there are packets immediately after setup header in same page, they need including in the segment table
Returns:
new segment table.

createSegmentTable

private byte[] createSegmentTable(int setupHeaderLength,
                                  java.util.List<OggPageHeader.PacketStartAndLength> extraPackets)
This method creates a new segment table for the second half of setup header

Parameters:
setupHeaderLength - The length of Setup Header, zero if comment String extends over multiple pages and this is not the last page.
extraPackets - If there are packets immediately after setup header in same page, they need including in the segment table
Returns:
new segment table.

createSegments

private byte[] createSegments(int length,
                              boolean quitStream)
This method creates a byte array of values whose sum should be the value of length.

Parameters:
length - Size of the page which should be represented as 255 byte packets.
quitStream - If true and a length is a multiple of 255 we need another segment table entry with the value of 0. Else it's the last stream of the table which is already ended.
Returns:
Array of packet sizes. However only the last packet will differ from 255.


isCommentAndSetupHeaderFitsOnASinglePage

private boolean isCommentAndSetupHeaderFitsOnASinglePage(int commentLength,
                                                         int setupHeaderLength,
                                                         java.util.List<OggPageHeader.PacketStartAndLength> extraPacketList)
Parameters:
commentLength -
setupHeaderLength -
extraPacketList -
Returns:
true if there is enough room to fit the comment and the setup headers on one page taking into account the maximum no of segments allowed per page and zero lacing values.