2014-02-11 37 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 
相关问题