/** * The actual data to put into local file data - without Header-ID * or length specifier. * @return get the data */ public byte[] getLocalFileDataData() { // CRC will be added later byte[] data = new byte[getLocalFileDataLength().getValue() - WORD]; java.lang.SystemJ.arraycopy(ZipShort.getBytes(getMode()), 0, data, 0, 2); byte[] linkArray = getLinkedFile().getBytes(); // Uses default charset - see class Javadoc // CheckStyle:MagicNumber OFF java.lang.SystemJ.arraycopy(ZipLong.getBytes(linkArray.Length), 0, data, 2, WORD); java.lang.SystemJ.arraycopy(ZipShort.getBytes(getUserId()), 0, data, 6, 2); java.lang.SystemJ.arraycopy(ZipShort.getBytes(getGroupId()), 0, data, 8, 2); java.lang.SystemJ.arraycopy(linkArray, 0, data, 10, linkArray.Length); // CheckStyle:MagicNumber ON crc.reset(); crc.update(data); long checksum = crc.getValue(); byte[] result = new byte[data.Length + WORD]; java.lang.SystemJ.arraycopy(ZipLong.getBytes(checksum), 0, result, 0, WORD); java.lang.SystemJ.arraycopy(data, 0, result, WORD, data.Length); return(result); }
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)); }
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()); }
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); } }
/** * Writes all necessary data for this entry. * @throws IOException on error */ public override void closeArchiveEntry() //throws IOException { if (finished) { throw new java.io.IOException("Stream has already been finished"); } if (entry == null) { throw new java.io.IOException("No current entry to close"); } long realCrc = crc.getValue(); crc.reset(); if (entry.getMethod() == DEFLATED) { def.finish(); while (!def.finished()) { deflate(); } entry.setSize(ZipUtil.adjustToLong(def.getTotalIn())); entry.setCompressedSize(ZipUtil.adjustToLong(def.getTotalOut())); entry.setCrc(realCrc); def.reset(); written += entry.getCompressedSize(); } else if (raf == null) { if (entry.getCrc() != realCrc) { throw new java.util.zip.ZipException("bad CRC checksum for entry " + entry.getName() + ": " + java.lang.Long.toHexString(entry.getCrc()) + " instead of " + java.lang.Long.toHexString(realCrc)); } if (entry.getSize() != written - dataStart) { throw new java.util.zip.ZipException("bad size for entry " + entry.getName() + ": " + entry.getSize() + " instead of " + (written - dataStart)); } } else /* method is STORED and we used RandomAccessFile */ { long size = written - dataStart; entry.setSize(size); entry.setCompressedSize(size); entry.setCrc(realCrc); } // If random access output, write the local file header containing // the correct CRC and compressed/uncompressed sizes if (raf != null) { long save = raf.getFilePointer(); raf.seek(localDataStart); writeOut(ZipLong.getBytes(entry.getCrc())); writeOut(ZipLong.getBytes(entry.getCompressedSize())); writeOut(ZipLong.getBytes(entry.getSize())); raf.seek(save); } writeDataDescriptor(entry); entry = null; }