Пример #1
0
         /*
         * Reads up to {@code nbytes} of decompressed data and stores it in
         * {@code buffer} starting at {@code off}.
         *
         * @param buffer
         *            the buffer to write data to.
         * @param off
         *            offset in buffer to start writing.
         * @param nbytes
         *            number of bytes to read.
         * @return Number of uncompressed bytes read
         * @throws IOException
         *             if an IOException occurs.
         */
    
        public override int read(byte[] buffer, int off, int nbytes) {//throws IOException {
            /* archive.1E=Stream is closed */
            if (closed) {
                throw new java.io.IOException("Stream is closed"); //$NON-NLS-1$
            }

            if (null == buffer) {
                throw new java.lang.NullPointerException();
            }

            if (off < 0 || nbytes < 0 || off + nbytes > buffer.Length) {
                throw new java.lang.IndexOutOfBoundsException();
            }

            if (nbytes == 0) {
                return 0;
            }

            if (eof) {
                return -1;
            }

            // avoid int overflow, check null buffer
            if (off > buffer.Length || nbytes < 0 || off < 0
                    || buffer.Length - off < nbytes) {
                throw new java.lang.ArrayIndexOutOfBoundsException();
            }

            do {
                if (inf.needsInput()) {
                    fill();
                }
                // Invariant: if reading returns -1 or throws, eof must be true.
                // It may also be true if the next read() should return -1.
                try {
                    int result = inf.inflate(buffer, off, nbytes);
                    eof = inf.finished();
                    if (result > 0) {
                        return result;
                    } else if (eof) {
                        return -1;
                    } else if (inf.needsDictionary()) {
                        eof = true;
                        return -1;
                    } else if (len == -1) {
                        eof = true;
                        throw new java.io.EOFException();
                        // If result == 0, fill() and try again
                    }
                } catch (DataFormatException e) {
                    eof = true;
                    if (len == -1) {
                        throw new java.io.EOFException();
                    }
                    throw (java.io.IOException) (new java.io.IOException().initCause(e));
                }
            } while (true);
        }
Пример #2
0
        private void write()  //throws IOException, ZipException {
        {
            int inflated = 0;

            try {
                while ((inflated = inf.inflate(buf)) > 0)
                {
                    outJ.write(buf, 0, inflated);
                }
            } catch (DataFormatException e) {
                throw new ZipException();
            }
        }