当前位置: 首页>>代码示例>>Java>>正文


Java ID3v1Tag.getSize方法代码示例

本文整理汇总了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;
}
 
开发者ID:GlennioTech,项目名称:MetadataEditor,代码行数:48,代码来源:MP3File.java

示例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();
}
 
开发者ID:Old-Geek,项目名称:Musique,代码行数:41,代码来源:MP3File.java


注:本文中的org.jaudiotagger.tag.id3.ID3v1Tag.getSize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。