Exemplo n.º 1
0
        /**
         * Parses the supported flags from the given archive data.
         * @param data local file header or a central directory entry.
         * @param offset offset at which the general purpose bit starts
         */
        public static GeneralPurposeBit parse(byte[] data, int offset)
        {
            int generalPurposeFlag = ZipShort.getValue(data, offset);
            GeneralPurposeBit b    = new GeneralPurposeBit();

            b.useDataDescriptor((generalPurposeFlag & DATA_DESCRIPTOR_FLAG) != 0);
            b.useUTF8ForNames((generalPurposeFlag & UFT8_NAMES_FLAG) != 0);
            b.useStrongEncryption((generalPurposeFlag & STRONG_ENCRYPTION_FLAG)
                                  != 0);
            b.useEncryption((generalPurposeFlag & ENCRYPTION_FLAG) != 0);
            return(b);
        }
Exemplo n.º 2
0
        private void writeVersionNeededToExtractAndGeneralPurposeBits(int zipMethod,
                                                                      bool utfFallback)
        //throws IOException
        {
            // CheckStyle:MagicNumber OFF
            int versionNeededToExtract = 10;
            GeneralPurposeBit b        = new GeneralPurposeBit();

            b.useUTF8ForNames(useUTF8Flag || utfFallback);
            if (zipMethod == DEFLATED && raf == null)
            {
                // requires version 2 as we are going to store length info
                // in the data descriptor
                versionNeededToExtract = 20;
                b.useDataDescriptor(true);
            }
            // CheckStyle:MagicNumber ON

            // version needed to extract
            writeOut(ZipShort.getBytes(versionNeededToExtract));
            // general purpose bit flag
            writeOut(b.encode());
        }