-1

I was trying to write a code for a Subtitle finder in Java using SubDB api. Since I don't know python much, I don't understand what they are doing to calculate the hash value for a string. The hash is composed by taking the first and the last 64kb of the video file, putting all together and generating a md5 of the resulting data. name is the filename.

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()

Can anyone help me with the implementation of above code in Java?

thefourtheye
  • 233,700
  • 52
  • 457
  • 497
  • 2
    [No](http://i1.kym-cdn.com/photos/images/newsfeed/000/232/114/e39.png), unless you write some code and face a specific problem. – thefourtheye Feb 21 '14 at 12:24
  • I am not able to understand the code. I think I had mentioned that. Since I am not much familiar with reading a file, I think it was a relevant help needed. – Abhishek Sahu Feb 21 '14 at 12:27
  • 2
    @thefourtheye that pic scared the life outta me :P – Games Brainiac Feb 21 '14 at 12:31
  • Well why didn't you just ask someone to explain the code to you? Or learn a bit of python? In fact, you can pretty much understand what it is doing with ZERO knowledge of python ... if you can assume that the code is correct. – Stephen C Feb 22 '14 at 02:51

1 Answers1

1

Can anyone help me with the implementation of above code in Java?

Hints:

  1. the code to read the first and last N bytes of a file can easily be implemented using a FileInputStream, its skip(long) method and calling its read(byte[], int, int) method twice. Use File.size() to get the file size.

  2. generating an MD5 checksum in Java is covered by numerous questions; e.g. How can I generate an MD5 hash?

Community
  • 1
  • 1
Stephen C
  • 698,415
  • 94
  • 811
  • 1,216