Package java.util.zip

Examples of java.util.zip.ZipException


        deflate();
    }
    if ((e.flag & 8) == 0) {
        // verify size, compressed size, and crc-32 settings
        if (e.size != def.getTotalIn()) {
      throw new ZipException(
          "invalid entry size (expected " + e.size +
          " but got " + def.getTotalIn() + " bytes)");
        }
        if (e.csize != def.getTotalOut()) {
      throw new ZipException(
          "invalid entry compressed size (expected " +
          e.csize + " but got " + def.getTotalOut() +
          " bytes)");
        }
        if (e.crc != crc.getValue()) {
      throw new ZipException(
          "invalid entry CRC-32 (expected 0x" +
          Long.toHexString(e.crc) + " but got 0x" +
          Long.toHexString(crc.getValue()) + ")");
        }
    } else {
        e.size = def.getTotalIn();
        e.csize = def.getTotalOut();
        e.crc = crc.getValue();
        writeEXT(e);
    }
    def.reset();
    written += e.csize;
    break;
      case STORED:
    // we already know that both e.size and e.csize are the same
    if (e.size != written - locoff) {
        throw new ZipException(
      "invalid entry size (expected " + e.size +
      " but got " + (written - locoff) + " bytes)");
    }
    if (e.crc != crc.getValue()) {
        throw new ZipException(
       "invalid entry crc-32 (expected 0x" +
       Long.toHexString(e.crc) + " but got 0x" +
       Long.toHexString(crc.getValue()) + ")");
    }
    break;
View Full Code Here


  } else if (len == 0) {
      return;
  }

  if (entry == null) {
      throw new ZipException("no current ZIP entry");
  }
  switch (entry.method) {
  case DEFLATED:
      super.write(b, off, len);
      break;
  case STORED:
      written += len;
      if (written - locoff > entry.size) {
    throw new ZipException(
        "attempt to write past end of STORED entry");
      }
      out.write(b, off, len);
      break;
  default:
View Full Code Here

  }
  if (entry != null) {
      closeEntry();
  }
  if (entries.size() < 1) {
      throw new ZipException("ZIP file must have at least one entry");
  }
  // write central directory
  long off = written;
  Iterator e = entries.iterator();
  while (e.hasNext()) {
View Full Code Here

      if (len > remaining) {
    len = (int)remaining;
      }
      len = in.read(b, off, len);
      if (len == -1) {
    throw new ZipException("unexpected EOF");
      }
      crc.update(b, off, len);
      remaining -= len;
      return len;
  default:
View Full Code Here

      return null;
  }
  // get the entry name and create the ZipEntry first
  int len = get16(tmpbuf, LOCNAM);
  if (len == 0) {
      throw new ZipException("missing entry name");
  }
        int blen = b.length;
        if (len > blen) {
            do
                blen = blen * 2;
            while (len > blen);
            b = new byte[blen];
        }
  readFully(b, 0, len);
  ZipEntry e = createZipEntry(getUTF8String(b, 0, len));
  // now get the remaining fields for the entry
  e.version = get16(tmpbuf, LOCVER);
  e.flag = get16(tmpbuf, LOCFLG);
  if ((e.flag & 1) == 1) {
      throw new ZipException("encrypted ZIP entry not supported");
  }
  e.method = get16(tmpbuf, LOCHOW);
  e.time = get32(tmpbuf, LOCTIM);
  if ((e.flag & 8) == 8) {
      /* EXT descriptor present */
      if (e.method != DEFLATED) {
    throw new ZipException(
      "only DEFLATED entries can have EXT descriptor");
      }
  } else {
      e.crc = get32(tmpbuf, LOCCRC);
      e.csize = get32(tmpbuf, LOCSIZ);
View Full Code Here

                e.csize = get32(tmpbuf, EXTSIZ);
                e.size = get32(tmpbuf, EXTLEN);
            }
  }
  if (e.size != inf.getTotalOut()) {
      throw new ZipException(
    "invalid entry size (expected " + e.size + " but got " +
    inf.getTotalOut() + " bytes)");
  }
  if (e.csize != inf.getTotalIn()) {
      throw new ZipException(
    "invalid entry compressed size (expected " + e.csize +
    " but got " + inf.getTotalIn() + " bytes)");
  }
  if (e.crc != crc.getValue()) {
      throw new ZipException(
    "invalid entry CRC (expected 0x" + Long.toHexString(e.crc) +
    " but got 0x" + Long.toHexString(crc.getValue()) + ")");
  }
    }
View Full Code Here

    }
      }
      return n;
  } catch (DataFormatException e) {
      String s = e.getMessage();
      throw new ZipException(s != null ? s : "Invalid ZLIB data format");
  }
    }
View Full Code Here

        int start = 0;
        while (start <= data.length-4) {
            ZipShort headerId = new ZipShort(data, start);
            int length = (new ZipShort(data, start+2)).getValue();
            if (start+4+length > data.length) {
                throw new ZipException("data starting at "+start+" is in unknown format");
            }
            try {
                ZipExtraField ze = createExtraField(headerId);
                ze.parseFromLocalFileData(data, start+4, length);
                v.addElement(ze);
            } catch (InstantiationException ie) {
                throw new ZipException(ie.getMessage());
            } catch (IllegalAccessException iae) {
                throw new ZipException(iae.getMessage());
            }
            start += (length+4);
        }
        if (start != data.length) { // array not exhausted
            throw new ZipException("data starting at "+start+" is in unknown format");
        }
       
        ZipExtraField[] result = new ZipExtraField[v.size()];
        v.copyInto(result);
        return result;
View Full Code Here

            def.reset();

            written += entry.getCompressedSize();
        } else {
            if (entry.getCrc() != realCrc) {
                throw new ZipException("bad CRC checksum for entry "
                                       +entry.getName()+ ": "
                                       + Long.toHexString(entry.getCrc())
                                       + " instead of "
                                       + Long.toHexString(realCrc));
            }

            if (entry.getSize() != written - dataStart) {
                throw new ZipException("bad size for entry "
                                       +entry.getName()+ ": "
                                       + entry.getSize()
                                       + " instead of "
                                       + (written - dataStart));
            }
View Full Code Here

            entry.setTime(System.currentTimeMillis());
        }

        if (entry.getMethod() == STORED) {
            if (entry.getSize() == -1) {
                throw new ZipException("uncompressed size is required for STORED method");
            }
            if (entry.getCrc() == -1) {
                throw new ZipException("crc checksum is required for STORED method");
            }
            entry.setComprSize(entry.getSize());
        } else {
            def.setLevel(level);
        }       
View Full Code Here

TOP

Related Classes of java.util.zip.ZipException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.