void showClass ( String className ) { PrintWriter pw = log . getWriter ( WriterKind . NOTICE ) ; pw . println ( "javac: show class: " + className ) ; URL url = getClass ( ) . getResource ( ' ' + className . replace ( ' ' , ' ' ) + ".class" ) ; if ( url != null ) { pw . println ( " " + url ) ; } try ( InputStream in = getClass ( ) . getResourceAsStream ( ' ' + className . replace ( ' ' , ' ' ) + ".class" ) ) { final String algorithm = "MD5" ; byte [ ] digest ; MessageDigest md = MessageDigest . getInstance ( algorithm ) ; try ( DigestInputStream din = new DigestInputStream ( in , md ) ) { byte [ ] buf = new byte [ 8192 ] ; int n ; do { n = din . read ( buf ) ; } while ( n > 0 ) ; digest = md . digest ( ) ; } StringBuilder sb = new StringBuilder ( ) ; for ( byte b : digest ) sb . append ( String . format ( "%02x" , ) ) ; pw . println ( " " + algorithm + " checksum: " + sb ) ; } catch ( NoSuchAlgorithmException | IOException e ) { pw . println ( " cannot compute digest: " + e ) ; } }
Display the location and checksum of a class .