Java has functionality for calculating SHA-1 and MD5 checksums but not for displaying them as the 40-char hex strings I’m used to. I want to update my photo reorganizer so it doesn’t create duplicate files so I figured this would be a handy thing to write. I wrote one for MD5 a while ago (the only code you really need to write is the byte-array-to-hex-string converter) but I guess I lost it. Anyway, here it is.
Rather than paste a huge useless block of code here, I put it on github: https://github.com/evandhoffman/Java-SHA-1-Hasher.
Output appears to match that of the command-line utility:
[evan@EvanMBP bin]$ java -jar SHA1.jar ~/text.txt
[evan@EvanMBP bin]$ shasum ~/text.txt
It’s not as fast as shasum (as I expected) but that may partially be due to reading data in 1k chunks.
I wrote a little utility to reorganize my digital camera pics based on the EXIF date-taken data stored in the pic. It’s pretty simple, I hacked it together in about an hour,
but I thought it might be worth sharing for anyone else looking to do something similar. My camera organizes stuff as it sees fit sometimes, I am particular about my directory structure. This is probably a job best left to perl, but I don’t feel like getting Perl running on my Windows box where all the pics are. Now I can finally burn all my images to DVD.
- Drew Noakes’s Metadata Extractor – this is
a required library used to do the actual reading of the exif data.
- FileOrganizer.java – Abstract base class that moves
files from a source to a target directory based on criteria specified in the subclass.
- JpegFileOrganizer.java – Subclass that
accepts jpeg files and generates the correct path based on the EXIF data stored
in the image’s header. So if picture pic00001.jpg was taken on August 20, 2004, and the supplied
target directory is “/pics”, the directory to which the image would be moved would be
main() method is in JpegFileOrganizer, its arguments are [sourceDir] [targetDir].