📄 id3v1controler.java
字号:
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;
/**
* Description of the Class
*
* @author kilo
* @created 2003年12月22日
*/
public final class ID3v1Controler
extends ID3Interface {
/**
* Constructor for the ID3v1Controler object
*
* @param filename Description of the Parameter
* @exception FileNotFoundException Description of the Exception
* @exception IOException Description of the Exception
* @exception BadID3Exception 损坏的ID3标签异常
*/
public ID3v1Controler( Object filename )
throws FileNotFoundException,
IOException, BadID3Exception {
cAFile = null;
if ( filename instanceof String ) {
cFile = new File( (String)filename );
cAFile = new RandomAccessFile( (String)filename, "r" );
}
else if ( filename instanceof File ) {
cFile = (File)filename;
cAFile = new RandomAccessFile( (File)filename, "r" );
}
if ( cAFile == null )
throw new BadID3Exception( "No ID3v1 flag" );
}
/**
* Description of the Method
*
* @param fileName Description of the Parameter
* @return Description of the Return Value
* @exception BadID3Exception 损坏的ID3标签异常
* @exception FileNotFoundException Description of the Exception
* @exception IOException Description of the Exception
*/
public static boolean ID3Check( Object fileName )
throws BadID3Exception, FileNotFoundException, IOException {
byte[] bflag;
String flag;
bflag = new byte[3];
RandomAccessFile theFile = null;
if ( fileName instanceof String )
theFile = new RandomAccessFile( (String)fileName, "r" );
else if ( fileName instanceof File )
theFile = new RandomAccessFile( (File)fileName, "r" );
if ( theFile != null ) {
try {
theFile.seek( theFile.length() - 128 );
theFile.read( bflag );
} finally {
theFile.close();
}
flag = new String( bflag );
if ( !"TAG".equals( flag ) )
return false;
return true;
}
return false;
}
/**
* Gets the frame attribute of the ID3v1Controler object
*
* @param frameID Description of the Parameter
* @return The frame value
* @exception IOException Description of the Exception
* @exception BadID3Exception Description of the Exception
*/
protected String getFrame( String frameID )
throws IOException, BadID3Exception {
byte[] bContext;
String sContext;
boolean findID = false;
bContext = new byte[30];
if ( "Title".equals( frameID ) ) {
bContext = new byte[30];
cAFile.seek( cAFile.length() - 125 );
cAFile.read( bContext );
findID = true;
}
else if ( "Artist".equals( frameID ) ) {
bContext = new byte[30];
cAFile.seek( cAFile.length() - 95 );
cAFile.read( bContext );
findID = true;
}
else if ( "Album".equals( frameID ) ) {
bContext = new byte[30];
cAFile.seek( cAFile.length() - 65 );
cAFile.read( bContext );
findID = true;
}
else if ( "Year".equals( frameID ) ) {
bContext = new byte[4];
cAFile.seek( cAFile.length() - 35 );
cAFile.read( bContext );
findID = true;
}
else if ( "Comment".equals( frameID ) ) {
bContext = new byte[30];
cAFile.seek( cAFile.length() - 31 );
cAFile.read( bContext, (int)cAFile.length() - 31, 30 );
findID = true;
}
else if ( "Genre".equals( frameID ) ) {
cAFile.read( bContext, (int)cAFile.length() - 1, 1 );
findID = true;
}
if ( findID )
sContext = new String( bContext ).trim();
else
sContext = "";
return sContext;
}
/**
* Description of the Method
*
* @param frameID Description of the Parameter
* @return Description of the Return Value
*/
protected String encodeFrame( String frameID ) {
String newID;
if ( "Title".equals( frameID ) )
newID = "Title";
else if ( "Artist".equals( frameID ) )
newID = "Artist";
else if ( "Album".equals( frameID ) )
newID = "Album";
else if ( "Year".equals( frameID ) )
newID = "Year";
else
newID = "";
return newID;
}
/**
* Sets the frame attribute of the ID3v1Controler object
*
* @param frameID The new frame value
* @param sContext The new frame value
* @return Description of the Return Value
*/
protected boolean setFrame( String frameID, String sContext ) {
return false;
}
/**
* Description of the Method
*
* @param filename Description of the Parameter
* @exception BadID3Exception 损坏的ID3标签异常
* @exception FileNotFoundException Description of the Exception
* @exception IOException Description of the Exception
*/
protected void initFiles( Object filename )
throws BadID3Exception,
FileNotFoundException, IOException {
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -