|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.tffenterprises.music.io.TaggedFile
public class TaggedFile
This class represents a music file with ID3 tags. Using this class, one can read and write ID3v1 and ID3v2 tags. It is also possible to not worry about what kind of ID3 tags the file has; it will use ID3v2 tags by default, but will use ID3v1 tags if they are the only ones present. The user can give TaggedFile an instance of an ID3 subclass for writing, and TaggedFile will write it at its proper place or create an of a known ID3 subclass if the supplied one is unknown. TaggedFile does not abstract the physical relationship of the file with the tags. When the user requests a tag object from TaggedFile, the result will be whatever's on the disk. A class that abstracts that relationship could easily be built by encapsulating a TaggedFile instance.
Field Summary | |
---|---|
private boolean |
checkedID3v1
Internal flag: has the file been checked for an ID3v1 tag ? |
private boolean |
checkedID3v2
Internal flag: has the file been checked for an ID3v2 tag ? |
private java.io.RandomAccessFile |
raFile
The underlying file, handled via the RandomAccessFile class. |
static java.lang.String |
ReadOnly
The read-only mode. |
static java.lang.String |
ReadWrite
The read-write mode. |
private boolean |
tagID3v1present
Is there an ID3v1 tag in the file ? |
private boolean |
tagID3v2present
Is there an ID3v2 tag in the file ? |
Constructor Summary | |
---|---|
TaggedFile(java.io.File theFile,
java.lang.String openmode)
Constructor, from a File object and an openmode, either TaggedFile.ReadOnly or TaggedFile.ReadWrite. |
|
TaggedFile(java.lang.String pathname,
java.lang.String openmode)
Constructor, from a pathname and an openmode, either TaggedFile.ReadOnly or TaggedFile.ReadWrite. |
Method Summary | |
---|---|
private void |
adjustFileLength(byte[] tagBytes)
Adjust the length of the file in order to exactly fit the byte array, which represents an ID3v2 tag. |
void |
close()
Closes the underlying file stream and releases any system resources associated with it. |
private void |
findMpegAudioStart()
Positions the file at the beginning of the first frame of MP3 data, past the ID3v2 tag if there is one. |
ID3v1 |
getID3v1()
Obtain the ID3v1 tag associated with this file. |
ID3v2 |
getID3v2()
Return the ID3v2 tag associated with this file. |
byte[] |
getID3v2Bytes()
Return a byte array containing the encoded ID3v2 tag associated with this file. |
java.io.RandomAccessFile |
getRAFile()
Returns the underlying RandomAccessFile object. |
ID3Tag |
getTag()
Obtain an ID3 tag associated with this file. |
boolean |
hasID3v1()
Returns a boolean indicating whether the TaggedFile has an ID3v1 tag. |
boolean |
hasID3v2()
Returns a boolean indicating whether the TaggedFile has an ID3v2 tag. |
boolean |
hasTag()
Returns a boolean indicating whether the TaggedFile has a tag. |
long |
length()
Returns the length of the underlying file. |
void |
removeID3v1()
Remove the ID3v1 tag, if any, from the file. |
void |
writeID3v1(ID3v1 tag)
Write an ID3v1 object to the file. |
void |
writeID3v2(ID3v2 tag)
Write the an ID3v2 object to the file. |
void |
writeID3v2(ID3v2 tag,
int newLengthInFile)
Write an ID3v2 object to the file. |
void |
writeID3v2Bytes(byte[] tagBytes)
Write a byte array to file, assuming it contains ID3v2 information. |
void |
writeTag(ID3Tag tag)
Write a given ID3 tag to the file. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static java.lang.String ReadOnly
public static java.lang.String ReadWrite
private java.io.RandomAccessFile raFile
private boolean checkedID3v1
private boolean tagID3v1present
private boolean checkedID3v2
private boolean tagID3v2present
Constructor Detail |
---|
public TaggedFile(java.io.File theFile, java.lang.String openmode) throws java.lang.SecurityException, java.io.IOException
theFile
- a File object to open.openmode
- the opening mode to use, either
TaggedFile.ReadOnly
or TaggedFile.ReadWrite
.
java.lang.SecurityException
- if the program cannot open the file in
the mode that was requested.
java.io.IOException
- if some other I/O error occurs.public TaggedFile(java.lang.String pathname, java.lang.String openmode) throws java.lang.SecurityException, java.io.IOException
pathname
- the pathname of a file to open.openmode
- the opening mode to use, either
TaggedFile.ReadOnly
or TaggedFile.ReadWrite
.
java.lang.SecurityException
- if the program cannot open the file in
the mode that was requested.
java.io.IOException
- if some other I/O error occurs.Method Detail |
---|
public java.io.RandomAccessFile getRAFile()
public void close()
public long length() throws java.io.IOException
java.io.IOException
- if an I/O error occurs.public boolean hasID3v1() throws java.io.IOException
java.io.IOException
- if an I/O error occurs.public boolean hasID3v2() throws java.io.IOException
java.io.IOException
- if an I/O error occurs.public boolean hasTag() throws java.io.IOException
java.io.IOException
- if an I/O error occurs.public void writeID3v1(ID3v1 tag) throws java.io.IOException
tag
- the tag to write.
java.io.IOException
- if an I/O error occurs.public void removeID3v1() throws java.io.IOException
java.io.IOException
- if an I/O error occurs.public void writeID3v2(ID3v2 tag) throws java.io.IOException
tag
- the tag to write
java.io.IOException
- if an I/O error occurs.public void writeID3v2(ID3v2 tag, int newLengthInFile) throws java.io.IOException
newLengthInFile
is a target tag length, in
bytes.
If the target is greater than the old tag length, the file will
be lengthened. If the old tag length is greater than
newLengthInFile
, the old value will be used. If the
tag cannot be made to fit in newLengthInFile
bytes,
the operation will fail. If newLengthInFile
is
non-positive, the tag is written using the minimum possible size.
tag
- the tag to writenewLengthInFile
- a target length in bytes for the tag
java.io.IOException
- if an I/O error occurs.public void writeID3v2Bytes(byte[] tagBytes) throws java.io.IOException
tagBytes
- a byte array containing ID3v2 information.
java.io.IOException
- if an I/O error occurs.private void adjustFileLength(byte[] tagBytes) throws java.io.IOException
tagBytes
- a byte array containing ID3v2 information.
java.io.IOException
- if an I/O error occurs.public void writeTag(ID3Tag tag) throws java.io.IOException
tag
- the ID3 tag to write to the file.
java.io.IOException
- if an I/O error occurs.public ID3v1 getID3v1() throws java.io.IOException
java.io.IOException
- if an I/O error occurs.public byte[] getID3v2Bytes() throws java.io.IOException
java.io.IOException
- if an I/O error occurs.public ID3v2 getID3v2() throws java.io.IOException
java.io.IOException
- if an I/O error occurs.public ID3Tag getTag() throws java.io.IOException
java.io.IOException
- if an I/O error occurs.private void findMpegAudioStart() throws java.io.IOException
java.io.IOException
- if an I/O error occurs.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |