本文整理汇总了Java中org.jaudiotagger.tag.id3.ID3v1Tag.getSize方法的典型用法代码示例。如果您正苦于以下问题:Java ID3v1Tag.getSize方法的具体用法?Java ID3v1Tag.getSize怎么用?Java ID3v1Tag.getSize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jaudiotagger.tag.id3.ID3v1Tag
的用法示例。
在下文中一共展示了ID3v1Tag.getSize方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getHash
import org.jaudiotagger.tag.id3.ID3v1Tag; //导入方法依赖的package包/类
/**
* Calculates hash with algorithm "MD5", "SHA-1" or SHA-256".
* Hash is calculated EXCLUDING meta-data, like id3v1 or id3v2
*
* @return byte[] hash value in byte
* @throws IOException
* @throws InvalidAudioFrameException
* @throws NoSuchAlgorithmException
*/
public byte[] getHash(String algorithm, int bufferSize) throws InvalidAudioFrameException, IOException, NoSuchAlgorithmException {
File mp3File = getFile();
long startByte = getMP3StartByte(mp3File);
int id3v1TagSize = 0;
if (hasID3v1Tag()) {
ID3v1Tag id1tag = getID3v1Tag();
id3v1TagSize = id1tag.getSize();
}
InputStream inStream = new FileInputStream(mp3File);
byte[] buffer = new byte[bufferSize];
MessageDigest digest = MessageDigest.getInstance(algorithm);
inStream.skip(startByte);
int read;
long totalSize = mp3File.length() - startByte - id3v1TagSize;
int pointer = buffer.length;
while (pointer <= totalSize) {
read = inStream.read(buffer);
digest.update(buffer, 0, read);
pointer += buffer.length;
}
read = inStream.read(buffer, 0, (int) totalSize - pointer + buffer.length);
digest.update(buffer, 0, read);
byte[] hash = digest.digest();
return hash;
}
示例2: getHash
import org.jaudiotagger.tag.id3.ID3v1Tag; //导入方法依赖的package包/类
public byte[] getHash(String algorithm, int bufferSize) throws InvalidAudioFrameException, IOException, NoSuchAlgorithmException {
File mp3File = getFile();
long startByte = getMP3StartByte(mp3File);
int id3v1TagSize = 0;
if (hasID3v1Tag()) {
ID3v1Tag id1tag = getID3v1Tag();
id3v1TagSize = id1tag.getSize();
}
File file = new File(mp3File.getAbsolutePath());
// android.os.Build.VERSION.SDK_INT
//InputStream inStream = Files.newInputStream(Paths.get(mp3File.getAbsolutePath()));
InputStream inStream = new FileInputStream(file);
byte[] buffer = new byte[bufferSize];
MessageDigest digest = MessageDigest.getInstance(algorithm);
inStream.skip(startByte);
int read;
long totalSize = mp3File.length() - startByte - id3v1TagSize;
int pointer = buffer.length;
while (pointer <= totalSize) {
read = inStream.read(buffer);
digest.update(buffer, 0, read);
pointer += buffer.length;
}
read = inStream.read(buffer, 0, (int) totalSize - pointer + buffer.length);
digest.update(buffer, 0, read);
return digest.digest();
}