2014-02-11 45 views
0

我想使用字幕API。它需要視頻文件的第一個和最後一個64kb的md5散列。 我知道如何做md5部分只是想知道我將如何實現獲得128kb的數據。如何讀取Java中第一個和最後一個64kb的視頻文件?

在Python中給出了一個API的例子,但遺憾的是我不理解它。

#this hash function receives the name of the file and returns the hash code 
def get_hash(name): 
    readsize = 64 * 1024 
    with open(name, 'rb') as f: 
     size = os.path.getsize(name) 
     data = f.read(readsize) 
     f.seek(-readsize, os.SEEK_END) 
     data += f.read(readsize) 
    return hashlib.md5(data).hexdigest() 

http://thesubdb.com/api/

任何幫助,將不勝感激。

+0

你想知道如何在Java中讀取數據的64KB? – crush

+0

[優雅的方式來讀取文件到Java中的byte \ [\]數組]的可能重複(http://stackoverflow.com/questions/6058003/elegant-way-to-read-file-into-byte-array-in -java) – crush

+0

是的。 該文件的第一個64kb和最後一個64kb。結合。 –

回答

0

嘗試這樣的事情

FileInputStream in = new FileInputStream("d:/1.avi"); 
    byte[] a = new byte[64 * 1024]; 
    in.read(a); //head 
    long p = in.getChannel().size() - 64 * 1024; 
    in.getChannel().position(p); 
    in.read(a); //tail 
相關問題