1 27 package org.jruby.util; 28 29 import java.lang.reflect.Field ; 30 31 import java.util.zip.Adler32 ; 32 import java.util.zip.Checksum ; 33 34 39 public class Adler32Ext implements Checksum { 40 private int adler; 41 private final Adler32 intern; 42 43 private static final Field intern_adler; 44 45 static { 46 try { 47 intern_adler = Adler32 .class.getDeclaredField("adler"); 48 intern_adler.setAccessible(true); 49 } catch(final NoSuchFieldException nsfe) { 50 throw new RuntimeException ("This class have stopped working, it should be updated and FIXED now."); 51 } 52 } 53 54 57 public Adler32Ext() { 58 this(1); 59 } 60 61 66 public Adler32Ext(final int adler) { 67 super(); 68 this.adler=adler; 69 this.intern = new Adler32 (); 70 setAdlerRef(this.adler); 71 } 72 73 78 public void setAdler(final int adler) { 79 this.adler = adler; 80 setAdlerRef(this.adler); 81 } 82 83 86 public void update(final int b) { 87 this.intern.update(b); 88 } 89 90 93 public void update(final byte[] b, final int off, final int len) { 94 this.intern.update(b,off,len); 95 } 96 97 100 public void update(final byte[] b) { 101 this.intern.update(b); 102 } 103 104 107 public void reset() { 108 this.intern.reset(); 109 this.adler = 1; 110 } 111 112 115 public long getValue() { 116 return this.intern.getValue(); 117 } 118 119 124 private void setAdlerRef(final int val) { 125 try { 126 intern_adler.setInt(intern,val); 127 } catch(final IllegalAccessException e) { 128 throw new IllegalStateException (e.toString()); 129 } 130 } 131 } 132 | Popular Tags |