org.jaudiotagger.audio.generic
Class AudioFileWriter

java.lang.Object
  extended by org.jaudiotagger.audio.generic.AudioFileWriter
Direct Known Subclasses:
AsfFileWriter, FlacFileWriter, MP3FileWriter, Mp4FileWriter, OggFileWriter, WavFileWriter

public abstract class AudioFileWriter
extends java.lang.Object

This abstract class is the skeleton for tag writers.

It handles the creation/closing of the randomaccessfile objects and then call the subclass method writeTag or deleteTag. These two method have to be implemented in the subclass.

Since:
v0.02
Version:
$Id: AudioFileWriter.java,v 1.21 2009/05/05 15:59:14 paultaylor Exp $
Author:
Raphael Slinckx

Field Summary
static java.util.logging.Logger logger
           
private static int MINIMUM_FILESIZE
           
private  AudioFileModificationListener modificationListener
          If not null, this listener is used to notify the listener about modification events.
private static java.lang.String TEMP_FILENAME_SUFFIX
           
private static java.lang.String WRITE_MODE
           
 
Constructor Summary
AudioFileWriter()
           
 
Method Summary
 void delete(AudioFile af)
          Delete the tag (if any) present in the given file
 void delete(java.io.RandomAccessFile raf, java.io.RandomAccessFile tempRaf)
          Delete the tag (if any) present in the given randomaccessfile, and do not close it at the end.
protected abstract  void deleteTag(java.io.RandomAccessFile raf, java.io.RandomAccessFile tempRaf)
          Same as above, but delete tag in the file.
private  void precheckWrite(AudioFile af)
          Prechecks before normal write

If the tag is actually empty, remove the tag if the file is not writable, throw exception If the file is too small to be a valid file, throw exception

 void setAudioFileModificationListener(AudioFileModificationListener listener)
          This method sets the AudioFileModificationListener.
There is only one listener allowed, if you want more instances to be supported, use the ModificationHandler to broadcast those events.
 void write(AudioFile af)
          Write the tag (if not empty) present in the AudioFile in the associated File
protected abstract  void writeTag(Tag tag, java.io.RandomAccessFile raf, java.io.RandomAccessFile rafTemp)
          This is called when a tag has to be written in a file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TEMP_FILENAME_SUFFIX

private static final java.lang.String TEMP_FILENAME_SUFFIX
See Also:
Constant Field Values

WRITE_MODE

private static final java.lang.String WRITE_MODE
See Also:
Constant Field Values

MINIMUM_FILESIZE

private static final int MINIMUM_FILESIZE
See Also:
Constant Field Values

logger

public static java.util.logging.Logger logger

modificationListener

private AudioFileModificationListener modificationListener
If not null, this listener is used to notify the listener about modification events.

Constructor Detail

AudioFileWriter

public AudioFileWriter()
Method Detail

delete

public void delete(AudioFile af)
            throws CannotReadException,
                   CannotWriteException
Delete the tag (if any) present in the given file

Parameters:
af - The file to process
Throws:
CannotWriteException - if anything went wrong
CannotReadException

delete

public void delete(java.io.RandomAccessFile raf,
                   java.io.RandomAccessFile tempRaf)
            throws CannotReadException,
                   CannotWriteException,
                   java.io.IOException
Delete the tag (if any) present in the given randomaccessfile, and do not close it at the end.

Parameters:
raf - The source file, already opened in r-write mode
tempRaf - The temporary file opened in r-write mode
Throws:
CannotWriteException - if anything went wrong
CannotReadException
java.io.IOException

deleteTag

protected abstract void deleteTag(java.io.RandomAccessFile raf,
                                  java.io.RandomAccessFile tempRaf)
                           throws CannotReadException,
                                  CannotWriteException,
                                  java.io.IOException
Same as above, but delete tag in the file.

Parameters:
raf -
tempRaf -
Throws:
java.io.IOException - is thrown when the RandomAccessFile operations throw it (you should never throw them manually)
CannotWriteException - when an error occured during the deletion of the tag
CannotReadException

setAudioFileModificationListener

public void setAudioFileModificationListener(AudioFileModificationListener listener)
This method sets the AudioFileModificationListener.
There is only one listener allowed, if you want more instances to be supported, use the ModificationHandler to broadcast those events.

Parameters:
listener - The listener. null allowed to deregister.

precheckWrite

private void precheckWrite(AudioFile af)
                    throws CannotWriteException
Prechecks before normal write

Parameters:
af -
Throws:
CannotWriteException

write

public void write(AudioFile af)
           throws CannotWriteException
Write the tag (if not empty) present in the AudioFile in the associated File

Parameters:
af - The file we want to process
Throws:
CannotWriteException - if anything went wrong

writeTag

protected abstract void writeTag(Tag tag,
                                 java.io.RandomAccessFile raf,
                                 java.io.RandomAccessFile rafTemp)
                          throws CannotReadException,
                                 CannotWriteException,
                                 java.io.IOException
This is called when a tag has to be written in a file. Three parameters are provided, the tag to write (not empty) Two randomaccessfiles, the first points to the file where we want to write the given tag, and the second is an empty temporary file that can be used if e.g. the file has to be bigger than the original.

If something has been written in the temporary file, when this method returns, the original file is deleted, and the temporary file is renamed the the original name

If nothing has been written to it, it is simply deleted.

This method can assume the raf, rafTemp are pointing to the first byte of the file. The subclass must not close these two files when the method returns.

Parameters:
tag -
raf -
rafTemp -
Throws:
java.io.IOException - is thrown when the RandomAccessFile operations throw it (you should never throw them manually)
CannotWriteException - when an error occured during the generation of the tag
CannotReadException