String getUnicodeStringIfOriginalMatches(AbstractUnicodeExtraField f, byte[] orig) { if (f != null) { java.util.zip.CRC32 crc32 = new java.util.zip.CRC32(); crc32.update(orig); long origCRC32 = crc32.getValue(); if (origCRC32 == f.getNameCRC32()) { try { return(ZipEncodingHelper .UTF8_ZIP_ENCODING.decode(f.getUnicodeName())); } catch (java.io.IOException) { // UTF-8 unsupported? should be impossible the // Unicode*ExtraField must contain some bad bytes // TODO log this anywhere? return(default(String)); } } } return(default(String)); }
protected void init(String text, byte[] bytes, int off, int len) { java.util.zip.CRC32 crc32 = new java.util.zip.CRC32(); crc32.update(bytes, off, len); nameCRC32 = crc32.getValue(); try { unicodeName = text.getBytes("UTF-8"); } catch (java.io.UnsupportedEncodingException e) { throw new java.lang.RuntimeException("FATAL: UTF-8 encoding not supported.", e); } }
static void Main() { java.util.zip.CRC32 crc = new java.util.zip.CRC32(); java.util.zip.Adler32 a32 = new java.util.zip.Adler32(); java.lang.SystemJ.outJ.println(crc.getValue() + "\t" + a32.getValue()); crc.update("Bastie".getBytes()); a32.update("Bastie".getBytes()); java.lang.SystemJ.outJ.println(crc.getValue() + "\t" + a32.getValue()); crc = new java.util.zip.CRC32(); a32 = new java.util.zip.Adler32(); java.lang.SystemJ.outJ.println(crc.getValue() + "\t" + a32.getValue()); crc.update("Bas".getBytes()); a32.update("Bas".getBytes()); java.lang.SystemJ.outJ.println(crc.getValue() + "\t" + a32.getValue()); crc.update("tie".getBytes()); a32.update("tie".getBytes()); java.lang.SystemJ.outJ.println(crc.getValue() + "\t" + a32.getValue()); }
static void Main() { java.util.zip.CRC32 crc = new java.util.zip.CRC32(); java.util.zip.Adler32 a32 = new java.util.zip.Adler32(); java.lang.SystemJ.outJ.println(crc.getValue()+"\t"+a32.getValue()); crc.update("Bastie".getBytes()); a32.update("Bastie".getBytes()); java.lang.SystemJ.outJ.println(crc.getValue()+"\t"+a32.getValue()); crc = new java.util.zip.CRC32(); a32 = new java.util.zip.Adler32(); java.lang.SystemJ.outJ.println(crc.getValue()+"\t"+a32.getValue()); crc.update("Bas".getBytes()); a32.update("Bas".getBytes()); java.lang.SystemJ.outJ.println(crc.getValue()+"\t"+a32.getValue()); crc.update("tie".getBytes()); a32.update("tie".getBytes()); java.lang.SystemJ.outJ.println(crc.getValue()+"\t"+a32.getValue()); }