Ejemplo n.º 1
0
        /**
         * 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);
        }
Ejemplo n.º 2
0
        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));
        }
Ejemplo n.º 3
0
 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());
 }
Ejemplo n.º 4
0
 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());
 }
Ejemplo n.º 5
0
        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);
            }
        }
Ejemplo n.º 6
0
 /**
  * Writes bytes to ZIP entry.
  * @param b the byte array to write
  * @param offset the start position to write from
  * @param length the number of bytes to write
  * @throws IOException on error
  */
 public override void write(byte[] b, int offset, int length) //throws IOException
 {
     ZipUtil.checkRequestedFeatures(entry);
     if (entry.getMethod() == DEFLATED)
     {
         if (length > 0)
         {
             if (!def.finished())
             {
                 if (length <= DEFLATER_BLOCK_SIZE)
                 {
                     def.setInput(b, offset, length);
                     deflateUntilInputIsNeeded();
                 }
                 else
                 {
                     int fullblocks = length / DEFLATER_BLOCK_SIZE;
                     for (int i = 0; i < fullblocks; i++)
                     {
                         def.setInput(b, offset + i * DEFLATER_BLOCK_SIZE,
                                      DEFLATER_BLOCK_SIZE);
                         deflateUntilInputIsNeeded();
                     }
                     int done = fullblocks * DEFLATER_BLOCK_SIZE;
                     if (done < length)
                     {
                         def.setInput(b, offset + done, length - done);
                         deflateUntilInputIsNeeded();
                     }
                 }
             }
         }
     }
     else
     {
         writeOut(b, offset, length);
         written += length;
     }
     crc.update(b, offset, length);
     count(length);
 }
Ejemplo n.º 7
0
        public override int read(byte[] buffer, int start, int length) //throws IOException
        {
            if (closed)
            {
                throw new java.io.IOException("The stream is closed");
            }
            if (inf.finished() || current == null)
            {
                return(-1);
            }

            // avoid int overflow, check null buffer
            if (start <= buffer.Length && length >= 0 && start >= 0 &&
                buffer.Length - start >= length)
            {
                ZipUtil.checkRequestedFeatures(current);
                if (!supportsDataDescriptorFor(current))
                {
                    throw new UnsupportedZipFeatureException(Feature.DATA_DESCRIPTOR, current);
                }

                if (current.getMethod() == ZipArchiveOutputStream.STORED)
                {
                    if (hasDataDescriptor)
                    {
                        if (lastStoredEntry == null)
                        {
                            readStoredEntry();
                        }
                        return(lastStoredEntry.read(buffer, start, length));
                    }

                    int csize = (int)current.getSize();
                    if (readBytesOfEntry >= csize)
                    {
                        return(-1);
                    }
                    if (offsetInBuffer >= lengthOfLastRead)
                    {
                        offsetInBuffer = 0;
                        if ((lengthOfLastRead = inJ.read(buf)) == -1)
                        {
                            return(-1);
                        }
                        count(lengthOfLastRead);
                        bytesReadFromStream += lengthOfLastRead;
                    }
                    int toRead = length > lengthOfLastRead
                        ? lengthOfLastRead - offsetInBuffer
                        : length;
                    if ((csize - readBytesOfEntry) < toRead)
                    {
                        toRead = csize - readBytesOfEntry;
                    }
                    java.lang.SystemJ.arraycopy(buf, offsetInBuffer, buffer, start, toRead);
                    offsetInBuffer   += toRead;
                    readBytesOfEntry += toRead;
                    crc.update(buffer, start, toRead);
                    return(toRead);
                }

                if (inf.needsInput())
                {
                    fill();
                    if (lengthOfLastRead > 0)
                    {
                        bytesReadFromStream += lengthOfLastRead;
                    }
                }
                int read = 0;
                try {
                    read = inf.inflate(buffer, start, length);
                } catch (java.util.zip.DataFormatException e) {
                    throw new java.util.zip.ZipException(e.getMessage());
                }
                if (read == 0)
                {
                    if (inf.finished())
                    {
                        return(-1);
                    }
                    else if (lengthOfLastRead == -1)
                    {
                        throw new java.io.IOException("Truncated ZIP file");
                    }
                }
                crc.update(buffer, start, read);
                return(read);
            }
            throw new java.lang.ArrayIndexOutOfBoundsException();
        }