Cannot extract Zip file with Winzip after zipping with java.util.zip

Hi all,
I write a class for zip and unzip the text files together which can be zip and unzip successfully with Java platform. However, I cannot extract the zip file with Winzip or even WinRAR after zipping with Java platform.
Please help to comment, thanks~
Below is the code:
=====================================================================
package myapp.util;
import java.io.* ;
import java.util.TreeMap ;
import java.util.zip.* ;
import myapp.exception.UserException ;
public class CompressionUtil {
  public CompressionUtil() {
    super() ;
  public void createZip(String zipName, String fileName)
      throws ZipException, FileNotFoundException, IOException, UserException {
    FileOutputStream fos = null ;
    BufferedOutputStream bos = null ;
    ZipOutputStream zos = null ;
    File file = null ;
    try {
      file = new File(zipName) ; //new zip file
      if (file.isDirectory()) //check if it is a directory
     throw new UserException("Invalid zip file ["+zipName+"]") ;
      if (file.exists() && !file.canWrite()) //check if it is readonly
     throw new UserException("Zip file is ReadOnly ["+zipName+"]") ;
      if (file.exists()) //overwrite the existing file
     file.delete();
      file.createNewFile();
      //instantiate the ZipOutputStream
      fos = new FileOutputStream(file) ;
      bos = new BufferedOutputStream(fos) ;
      zos = new ZipOutputStream(bos) ;
      this.writeZipFileEntry(zos, fileName); //call to write the file into the zip
      zos.finish() ;
    catch (ZipException ze) {
      throw ze ;
    catch (FileNotFoundException fnfe) {
      throw fnfe ;
    catch (IOException ioe) {
      throw ioe ;
    catch (UserException ue) {
      throw ue ;
    finally {
      //close all the stream and file
      if (fos != null)
     fos.close() ;
      if (bos != null)
     bos.close();
      if (zos != null)
     zos.close();
      if (file != null)
     file = null ;
    }//end of try-catch-finally
  private void writeZipFileEntry(ZipOutputStream zos, String fileName)
      throws ZipException, FileNotFoundException, IOException, UserException {
    BufferedInputStream bis = null ;
    File file = null ;
    ZipEntry zentry = null ;
    byte[] bArray = null ;
    try {
      file = new File(fileName) ; //instantiate the file
      if (!file.exists()) //check if the file is not exist
     throw new UserException("No such file ["+fileName+"]") ;
      if (file.isDirectory()) //check if the file is a directory
     throw new UserException("Invalid file ["+fileName+"]") ;
      //instantiate the BufferedInputStream
      bis = new BufferedInputStream(new FileInputStream(file)) ;
      //Get the content of the file and put into the byte[]
      int size = (int) file.length();
      if (size == -1)
     throw new UserException("Cannot determine the file size [" +fileName + "]");
      bArray = new byte[(int) size];
      int rb = 0;
      int chunk = 0;
      while (((int) size - rb) > 0) {
     chunk = bis.read(bArray, rb, (int) size - rb);
     if (chunk == -1)
       break;
     rb += chunk;
      }//end of while (((int)size - rb) > 0)
      //instantiate the CRC32
      CRC32 crc = new CRC32() ;
      crc.update(bArray, 0, size);
      //instantiate the ZipEntry
      zentry = new ZipEntry(fileName) ;
      zentry.setMethod(ZipEntry.STORED) ;
      zentry.setSize(size);
      zentry.setCrc(crc.getValue());
      //write all the info to the ZipOutputStream
      zos.putNextEntry(zentry);
      zos.write(bArray, 0, size);
      zos.closeEntry();
    catch (ZipException ze) {
      throw ze ;
    catch (FileNotFoundException fnfe) {
      throw fnfe ;
    catch (IOException ioe) {
      throw ioe ;
    catch (UserException ue) {
      throw ue ;
    finally {
      //close all the stream and file
      if (bis != null)
     bis.close();
      if (file != null)
     file = null ;
    }//end of try-catch-finally
}

Tried~
The problem is still here~ >___<
Anyway, thanks for information sharing~
The message is:
Cannot open file: it does not appear to be a valid archive.
If you downloaded this file, try downloading the file again.
The problem may be here:
if (fos != null)
fos.close() ;
if (bos != null)
bos.close();
if (zos != null)
zos.close();
if (file != null)
file = null ;
The fos is closed before bos so the last buffer is not
saved.
zos.close() is enough.

Similar Messages

  • Extracting file from a TAR file with java.util.zip.* classes

    Is there a way to extract files from a .TAR file using the java.util.zip.* classes?
    I tried in some ways but I get the following error:
    java.util.zip.ZipException: error in opening zip file
    at java.util.zip.ZipFile.<init>(ZipFile.java127)
    at java.util.zip.ZipFile.<init>(ZipFile.java92)
    Thank you
    Giuseppe

    download the tar.jar from the above link and use the sample program below
    import com.ice.tar.*;
    import java.util.zip.GZIPInputStream;
    import java.io.*;
    public class untarFiles
         public static void main(String args[]){
              try{
              untar("c:/split/20040826172459.tar.gz",new File("c:/split/"));
              }catch(Exception e){
                   e.printStackTrace();
                   System.out.println(e.getMessage());
         private static void untar(String tarFileName, File dest)throws IOException{
              //assuming the file you pass in is not a dir
              dest.mkdir();     
              //create tar input stream from a .tar.gz file
              TarInputStream tin = new TarInputStream( new GZIPInputStream( new FileInputStream(new File(tarFileName))));
              //get the first entry in the archive
              TarEntry tarEntry = tin.getNextEntry();
              while (tarEntry != null){//create a file with the same name as the tarEntry  
                   File destPath = new File(
                   dest.toString() + File.separatorChar + tarEntry.getName());
                   if(tarEntry.isDirectory()){   
                        destPath.mkdir();
                   }else {          
                        FileOutputStream fout = new FileOutputStream(destPath);
                        tin.copyEntryContents(fout);
                        fout.close();
                   tarEntry = tin.getNextEntry();
              tin.close();
    }

  • Error in deploying p6.ear on WebLogic: java.util.zip.ZipException: invalid entry CRC

    Hello,
    We're trying to install Primavera EPPM 8.3 and test it on our server but having troubles in deploying p6 application.
    We have successfully installed the following prerequisites:
    - WebLogic 11g
    - JDK1.7.0_45 and setting JAVA_HOME path=C:\Program Files\Java\jdk1.7.0_45 in enviornmental variables
    - Downloading wsdl4j-1.6.2.jar for web services
    - Running the setup.exe file (located in PEPPM path\Disk1\install\setup.exe
    - Successfully finished the setup and running the Configuration Wizard.
    - Successfully created the database using Microsoft SQL Server 2008 database
    - Successfully creating a new WebLogic domain.
    - We didn't install BI publisher nor any content repository ( would this affect running the primavera application? )
    - In the configuration wizard summary we can see everything is marked successfully except the "Start Web Logic" step it showed an error and a message indicating that we should start it manually ( however, the domain is successfully created ).
    Next, we run the startWebLogic.cmd file in our new created domain, then we run startNodeManager.cmd from WebLogic common/bin directory.
    We can access the WebLogic administration panel successfully but no "p6" application in the deployments.
    So, we click "install" then open the p6 directory and deploy it without errors.
    But when when starting the P6 server and then try to start p6 application, it failed with the following error message:
    java.util.zip.ZipException: invalid entry CRC (expected 0xa0a67af0 but got 0xef73b950)
    Can you please help us to solve this? Please note that every other deployment is running correctly except p6.

    The cause of errors was a dying Westen Digital drive, specially the 48G partition reserved only for $ORACLE_BASE (/dev/sdb3 mounted on /opt/oracle).
    A simple quick scan of unmounted partition (badblocks -v /dev/sdb3) reported more than thousand new bad blocks (compared to the last scan six months ago). Although I strongly believe, specially in the case of WDC drives, that the best utility to "repair" bad blocks is the one that opens a window and prints the message: "Go to the nearest shop and buy a new drive", I was very curious to prove my suspicion just on this drive. After zero-filling the partition with dd, then formatting it (mke2fs -cc) and mounting again, the 11g installation and database creation (on the same partition) successfully completed, performing fast and smoothly. To make sure it was not a casual event, I repeated the installation once again with full success. The database itself is working fine (by now). Well, the whole procedure took me more than four hours, but I'm pretty satisfied. I learned once again - stay away from Western Digital. As Oracle cannot rely on dying drive, my friend is going tomorrow to spend a 150+ euro on two 250G Seagate Barracudas and replace both WDC drives, even though the first drive seems to be healthy.
    In general there is no difference between loading correct data from good disk into bad memory and loading the incorrect data from dying disk into good memory. In both cases the pattern is damaged. For everyone who runs into the problem similar to this, and the cause cannot be easily determined, the rule of thumb must be:
    1. test memory and, if it shows any error, check sockets and test memory modules individually
    2. check disks for bad blocks regardless of the result of memory testing
    Therefore I consider your answer being generally correct.
    Regards
    NJ

  • Problem in clustering in Weblogic 5.1 (java.util.zip.ZipException)

    Hi All,
    We are using WLS 5.1 clustering. 2 WLS are running in 2 different unix box in same subnet. But we are getting the following exception ( Though all the Beans have been deployed successfully).
    java.util.zip.ZipException: error in opening zip file
    at java.util.zip.ZipFile.open(Native Method)
    at java.util.zip.ZipFile.open(Compiled Code)
    at java.util.zip.ZipFile.<init>(Compiled Code)
    at java.util.zip.ZipFile.<init>(Compiled Code)
    at weblogic.boot.ServerClassLoader.deploy(ServerClassLoader.java:132)
    at weblogic.cluster.AnnotatedServiceOffer.expandClassPath(Compiled Code)
    at weblogic.cluster.AnnotatedServiceOffer.readObject(Compiled Code)
    at weblogic.common.internal.WLObjectInputStreamBase.readPublicSerializable(Compiled Code)
    Fri Jan 25 16:57:22 MST 2002:<E> <MulticastSocket> Multicast socket receive error: java.lang.RuntimeException: I/O error opening JAR file from file:/opt/wlogic/weblogic/obscluster/server113/tmp_deployments/ejbjar-4247.jar
    (cluster name we have changed to obscluster )
    This Exception is coming in both the servers The difference is that the server whose ip ends with 112 is trying to open the file from server113 dir and the server whose ip ends with 113 is trying to open the file from server112 dir.
    In web I have found that if the directory structure of 2 servers doesn't match then this porblem can arise. But for both of my servers the directory structure is same , at least until /opt/wlogic/weblogic/obscluster/ and then the directory server113 or server112 is created by Weblogic automatically when I have started the Server.
    Any help regarding this will be very helpful.
    Thanks & Regards
    Srijeeb.

    Hi everyone,
    I think I have got the solution. Using sp11. added sp11 related jar in PRE_CLASSPATH . Problem Solved....
    Thanks
    Srijeeb

  • What cause this error: java.util.zip.ZipException: invalid literal/lengths?

    Hi all,
    Our application produces this error in the logs: (our JDEV is 11.1.1.4.0, WLS 10.3)
    org.apache.myfaces.trinidadinternal.renderkit.core.CoreResponseStateManager _restoreSerializedView
    SEVERE:
    java.util.zip.ZipException: invalid literal/lengths set
    at java.util.zip.InflaterInputStream.read(InflaterInputStream.java:147)
    at java.util.zip.GZIPInputStream.read(GZIPInputStream.java:92)
    at java.io.ObjectInputStream$PeekInputStream.read(ObjectInputStream.java:2266)
    at java.io.ObjectInputStream$PeekInputStream.readFully(ObjectInputStream.java:2279)
    at java.io.ObjectInputStream$BlockDataInputStream.readShort(ObjectInputStream.java:2750)
    at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:780)
    at java.io.ObjectInputStream.<init>(ObjectInputStream.java:280)
    I have googled this error for hours and search the forum here, but no luck. Can someone please shed some light on this error? Thanks in advance!
    Shawn

    Hi Shawn,
    Please refer the below thing i found. Hope this may help you in moving forward in resolving. I hope this issue has occured when you are deploying your application WAR.
    ======================================================================================
    Method: read()
    Class: at java.util.zip.InflaterInputStream.read(InflaterInputStream.java:147)
    The above class comes in your exception hierarchy above.
    Reads uncompressed data into an array of bytes. This method will block until some input can be decompressed.
    Throws:
    ZipException - if a ZIP format error has occurred
    ====================================
    This also points that your WAR file is corrupt.
    Class: GZIPInputStream
    IOException - if an I/O error has occurred or the compressed input data is corrupt
    Thanks,

  • Cannot use winzip to unzip the zip file zipped by java.util.zip

    Hi all,
    I use the followcode to create a zip file, and i downlaod it and try to use winzip to unzip this file but fail. The path is correct and i got the zip file. but it just cannot unzip.
    pls help
    thanks alot.
    Kin
              int count = 0;
              count = ContentDocuments.size();
              for (int i = 0; i < bb; i++)     {
                   System.out.println(filenames[i] + "");
              // Create a buffer for reading the files
              byte[] buf = new byte[10*1024*1024];
              try {      
                   String outFilename = MyDir + "zipfile/" + getContentID2()+".zip";
                   System.out.println("outFilename = " + outFilename);
                   ZipOutputStream out = new ZipOutputStream(new FileOutputStream(outFilename));
                   for (int i=0; i<filenames.length; i++) {           
                        FileInputStream in = new FileInputStream(filenames);
                        out.putNextEntry(new ZipEntry(filenames[i]));
                        int len;
                        while ((len = in.read(buf)) != -1) {               
                             out.write(buf, 0, len);
                        out.closeEntry();
                        in.close();
                   out.close();
              } catch (IOException e)     {
                   System.err.println("zipprocess " + e.getMessage());

    I've written a replacement zip file creator class. Not much tested but it seems to work, however I've yet to try it with the version of WINZIP that rejected my previous attempts. Oh, and the stored dates are garbage.
    * ZipOutputFile.java
    * Created on 25 March 2004, 13:08
    package zip;
    import java.io.IOException;
    import java.nio.ByteBuffer;
    * <p>Creates a ZIP archive in a file which WINZIP should be able to read.</p>
    * <p>Unfortunately zip archives generated by the standard Java class
    * {@link java.util.zip.ZipOutputStream}, while adhering to PKZIPs format specification,
    * don't appear to be readable by some versions of WinZip and similar utilities. This is
    * probably because they use
    * a format specified for writing to a non-seakable stream, where the length and CRC of
    * a file is writen to a special block following the data. Since the length of the binary
    * date is unknown this makes an archive quite complicated to read, and it looks like
    * WinZip hasn't bothered.</p>
    * <p>All data is Deflated. Close completes the archive, flush terminates the current entry.</p>
    * @see java.util.zip.ZipOutputStream
    * @author  Malcolm McMahon
    public class ZipOutputFile extends java.io.OutputStream {
        byte[] oneByte = new byte[1];
        java.io.RandomAccessFile archive;
        public final static short DEFLATE_METHOD = 8;
        public final static short VERSION_CODE = 20;
        public final static short MIN_VERSION = 10;
        public final static int  ENTRY_HEADER_MAGIC = 0x04034b50;
        public final static int  CATALOG_HEADER_MAGIC = 0x02014b50;
        public final static int  CATALOG_END_MAGIC = 0x06054b50;
        private final static short DISC_NUMBER = 0;
        ByteBuffer entryHeader = ByteBuffer.wrap(new byte[30]);
        ByteBuffer entryLater = ByteBuffer.wrap(new byte[12]);
        java.util.zip.CRC32 crcAcc = new java.util.zip.CRC32();
        java.util.zip.Deflater def = new java.util.zip.Deflater(java.util.zip.Deflater.DEFLATED, true);
        int totalCompressed;
        long MSEPOCH;
        byte [] deflateBuf = new byte[2048];
        public static final long SECONDS_TO_DAYS = 60 * 60 * 24;
         * Entry stores info about each file stored
        private class Entry {
            long offset;        // position of header in file
            byte[] name;
            long crc;
            int compressedSize;
            int uncompressedSize;
            java.util.Date date;
             * Contructor also writes initial header.
             * @param fileName Name under which data is stored.
             * @param date  Date to label the file with
             * @TODO get the date stored properly
            public Entry(String fileName, java.util.Date date) throws IOException {
                name = fileName.getBytes();
                this.date = date == null ? new java.util.Date() : date;
                entryHeader.position(10);
                putDate(entryHeader);
                entryHeader.putShort(26, (short)name.length);
                offset = archive.getFilePointer();
                archive.write(entryHeader.array());
                archive.write(name);
                catalog.add(this);
                crcAcc.reset();
                totalCompressed = 0;
                def.reset();
             * Finish writing entry data. Save the lenghts & crc for catalog
             * and go back and fill them in in the entry header.
            public void close() throws IOException {
                def.finish();
                while(!def.finished())
                    deflate();
                entryLater.position(0);
                crc = crcAcc.getValue();
                compressedSize = totalCompressed;
                uncompressedSize = def.getTotalIn();
                entryLater.putInt((int)crc);
                entryLater.putInt(compressedSize);
                entryLater.putInt(uncompressedSize);
                long eof = archive.getFilePointer();
                archive.seek(offset + 14);
                archive.write(entryLater.array());
                archive.seek(eof);
             * Write the catalog data relevant to this entry. Buffer is
             * preloaded with fixed data.
             * @param buf Buffer to organise fixed lenght part of header
            public void writeCatalog(ByteBuffer buf) throws IOException {
                buf.position(12);
                putDate(buf);
                buf.putInt((int)crc);
                buf.putInt(compressedSize);
                buf.putInt(uncompressedSize);
                buf.putShort((short)name.length);
                buf.putShort((short)0);  // extra field length
                buf.putShort((short)0);  // file comment length
                buf.putShort(DISC_NUMBER);  // disk number
                buf.putShort((short)0); // internal attributes
                buf.putInt(0);      // external file attributes
                buf.putInt((int)offset); // file position
                archive.write(buf.array());
                archive.write(name);
             * This writes the entries date in MSDOS format.
             * @param buf Where to write it
             * @TODO Get this generating sane dates
            public void putDate(ByteBuffer buf) {
                long msTime = (date.getTime() - MSEPOCH) / 1000;
                buf.putShort((short)(msTime % SECONDS_TO_DAYS));
                buf.putShort((short)(msTime / SECONDS_TO_DAYS));
        private Entry entryInProgress = null; // entry currently being written
        private java.util.ArrayList catalog = new java.util.ArrayList(12);  // all entries
         * Start a new output file.
         * @param name The name to store as
         * @param date Date - null indicates current time
        public java.io.OutputStream openEntry(String name, java.util.Date date) throws IOException{
            if(entryInProgress != null)
                entryInProgress.close();
            entryInProgress = new Entry(name, date);
            return this;
         * Creates a new instance of ZipOutputFile
         * @param fd The file to write to
        public ZipOutputFile(java.io.File fd) throws IOException {
            this(new java.io.RandomAccessFile(fd, "rw"));
         * Create new instance of ZipOutputFile from RandomAccessFile
         * @param archive RandomAccessFile
        public ZipOutputFile(java.io.RandomAccessFile archive) {
            this.archive = archive;
            entryHeader.order(java.nio.ByteOrder.LITTLE_ENDIAN);  // create fixed fields of header
            entryLater.order(java.nio.ByteOrder.LITTLE_ENDIAN);
            entryHeader.putInt(ENTRY_HEADER_MAGIC);
            entryHeader.putShort(MIN_VERSION);
            entryHeader.putShort((short)0);  // general purpose flag
            entryHeader.putShort(DEFLATE_METHOD);
            java.util.Calendar cal = java.util.Calendar.getInstance();
            cal.clear();
            cal.set(java.util.Calendar.YEAR, 1950);
            cal.set(java.util.Calendar.DAY_OF_MONTH, 1);
    //        def.setStrategy(Deflater.HUFFMAN_ONLY);
            MSEPOCH = cal.getTimeInMillis();
         * Writes the master catalogue and postamble and closes the archive file.
        public void close() throws IOException{
            if(entryInProgress != null)
                entryInProgress.close();
            ByteBuffer catEntry = ByteBuffer.wrap(new byte[46]);
            catEntry.order(java.nio.ByteOrder.LITTLE_ENDIAN);
            catEntry.putInt(CATALOG_HEADER_MAGIC);
            catEntry.putShort(VERSION_CODE);
            catEntry.putShort(MIN_VERSION);
            catEntry.putShort((short)0);
            catEntry.putShort(DEFLATE_METHOD);
            long catStart = archive.getFilePointer();
            for(java.util.Iterator it = catalog.iterator(); it.hasNext();) {
                ((Entry)it.next()).writeCatalog(catEntry);
            catEntry.position(0);
            catEntry.putInt(CATALOG_END_MAGIC);
            catEntry.putShort(DISC_NUMBER);
            catEntry.putShort(DISC_NUMBER);
            catEntry.putShort((short)catalog.size());
            catEntry.putShort((short)catalog.size());
            catEntry.putInt((int)(archive.getFilePointer() - catStart));
            catEntry.putInt((int)catStart);
            catEntry.putShort((short)0);
            archive.write(catEntry.array(), 0, catEntry.position());
            archive.setLength(archive.getFilePointer());  // truncate if old file
            archive.close();
            def.end();
         * Closes entry in progress.
        public void flush() throws IOException{
            if(entryInProgress == null)
                throw new IllegalStateException("Must call openEntry before writing");
            entryInProgress.close();
            entryInProgress = null;
         * Standard write routine. Defined by {@link java.io.OutputStream}.
         * Can only be used once openEntry has defined the file.
         * @param b  Bytes to write
        public void write(byte[] b) throws IOException{
            if(entryInProgress == null)
                throw new IllegalStateException("Must call openEntry before writing");
            crcAcc.update(b);
            def.setInput(b);
            while(!def.needsInput())
                deflate();
         * Standard write routine. Defined by {@link java.io.OutputStream}.
         * Can only be used once openEntry has defined the file.
         * @param b  Bytes to write
        public void write(int b) throws IOException{
            oneByte[0] = (byte)b;
            crcAcc.update(b);
            write(oneByte, 0, 1);
         *  Standard write routine. Defined by {@link java.io.OutputStream}.
         * Can only be used once openEntry has defined the file.
         * @param b  Bytes to write
         * @param off Start offset
         * @param len Byte count
        public void write(byte[] b, int off, int len) throws IOException{
            if(entryInProgress == null)
                throw new IllegalStateException("Must call openEntry before writing");
            crcAcc.update(b, off, len);
            def.setInput(b, off, len);
            while(!def.needsInput())
                deflate();
        * Gets a buffer full of coded data from the deflater and writes it to archive.
        private void deflate() throws IOException {
            int len = def.deflate(deflateBuf);
            totalCompressed += len;
            if(len > 0)
                archive.write(deflateBuf, 0, len);

  • Java.lang.Error: java.util.zip.ZipException: The system cannot find the fil

    I got maven 221 installed
    i got jdk 1.6 and 1.5 installed (have tested both)
    I have a strange error. All my co-workers can build but I cant. The only thing I can find is that I dont have installed BEA Weblogic but I dont want to have that installed. It should be able to run anyway.
    Could someone tell me what is wrong? If you need pom.xml I got that one as well.
    process-classes:
    [copy] Copying 4 files to C:\hudson\jobs\albpm_ip-identity-asserter_-_Build\workspace\target\mbean-content
    [mkdir] Created dir: C:\hudson\jobs\albpm_ip-identity-asserter_-_Build\workspace\target\mbean-jar
    [java] Creating an MJF from the contents of directory C:\hudson\jobs\albpm_ip-identity-asserter_-_Build\workspace\target\mbean-content...
    [java] Compiling the files...
    [java] Creating the list.
    [java] Doing the compile.
    [java] WLMaker-SubProcess: : Exception in thread "main" java.lang.Error: java.util.zip.ZipException: The system cannot find the file specified
    [java] WLMaker-SubProcess: :      at weblogic.management.commo.BeanGenDriver.getManagementTempDir(BeanGenDriver.java:93)
    [java] WLMaker-SubProcess: :      at weblogic.management.commo.BeanGenDriver.main(BeanGenDriver.java:117)
    [java] WLMaker-SubProcess: : Caused by: java.util.zip.ZipException: The system cannot find the file specified
    [java] WLMaker-SubProcess: :      at java.util.zip.ZipFile.open(Native Method)
    [java] WLMaker-SubProcess: :      at java.util.zip.ZipFile.<init>(ZipFile.java:203)
    [java] WLMaker-SubProcess: :      at java.util.jar.JarFile.<init>(JarFile.java:132)
    [java] WLMaker-SubProcess: :      at java.util.jar.JarFile.<init>(JarFile.java:97)
    [java] WLMaker-SubProcess: :      at weblogic.management.commo.BeanGenDriver.getManagementTempDir(BeanGenDriver.java:90)
    [java] WLMaker-SubProcess: :      ... 1 more
    [java] WLMaker-SubProcess: : Stopped draining WLMaker-SubProcess:
    [java] WLMaker-SubProcess: : Stopped draining WLMaker-SubProcess:
    [java] BeanGen code generation failed
    [HUDSON] Archiving C:\hudson\jobs\albpm_ip-identity-asserter_-Build\workspace\pom.xml to C:\hudson\jobs\albpmip-identity-asserter_-Build\modules\dk.skat.ip.integration.albpm$ip-identity-asserter\builds\2010-11-2213-41-28\archive\dk.skat.ip.integration.albpm\ip-identity-asserter\1.2\pom.xml
    [INFO] ------------------------------------------------------------------------

    from my experience, using weblogic jars can be a pain if the full install is not on the local box.
    Note that you dont have to 'install' it. Just copy the directory.
    Reason is that the jar files have manifests with relative classpaths.
    For an example of horror take a look at the weblogic.jar MANIFEST's classpath entry.
    -Fred

  • How do I compress a string with  java.util.zip - not a file ?

    How do I compress a string with java.util.zip?
    Is possible to compress something else except a file?

    Of course, compression works on bytes, not some higher level constructs like Strings or files.
    You can use the ZipOutputStream or DeflaterOutputStream for compression.
    And the javadoc for Deflater even has a code example of compressing a String.
    Edited by: Kayaman on May 22, 2011 5:04 PM

  • How to zip one file i have on disk with java.util.zip

    I don't know how to zip a file. I managed to do new html file, but i don't know how to zip it.
    This is my code:
    PrintWriter pw = new PrintWriter (new FileWriter(export), true);
    Thanks!

    heres a zipper class i wrote which i have butchered a bit to make more generic (its basic and at present only takes one zipentry etc, but very simple and should be easy to extend etc) Just pass it your file in its constructor and then call its zipme method. PS if it can be made better let me know so i can update my class, cheers.
    import java.io.*;
    import java.util.zip.*;
    import java.awt.*;
    class zipper
         public File file;
         public zipper(File f)
              file = new File(f);
         public void zipme()
              try
                   FileInputStream fin = new FileInputStream(file);
                   int a = (int)file.length();
                   byte b[] = new byte[a];
                   fin.read(b);
                   ZipEntry k = new ZipEntry(fin.getName());//represents a single file in a zip archive!
                   File newFile = new File("D:\\AZipFile.zip");
                   ZipOutputStream zi = new ZipOutputStream(new FileOutputStream(newFile));
                   zi.putNextEntry(k);
                   zi.write(b,0,a);
                   zi.close();
                   fin.close();
              catch(FileNotFoundException e)
                   //System.out.println("ERROR File not found");
              catch(IOException ee)
                   //System.out.println("ERROR IO exception in Zipping file");
    }

  • Java.util.zip.ZipException error in opening zip file

    Hello all,
    We are using Sun Java System web server 6.1 SP2. When I tried to deploy an application, I received this message: "Posted content length of --- exceeds limit of --- " the -dashes are the size of the file actually.
    I then added an init-param to the web.xml specifying the maximum size.
    After doing that, I tried to deploy the war file using administration interface, but received a network tcp/ip error. I then deployed it using command line wdeploy command. It worked but the web server won't start up after the deployment. The following error messages are found in the log file. Any thoughts as to whats wrong here? Is there a bug in SP2?
    [22/Sep/2006:17:30:44] finer ( 5668): ContextConfig[search]: URI='/search', ResourcePath='/WEB-INF/sun-web-search.tld' [22/Sep/2006:17:30:44] finer ( 5668): ContextConfig[search]:
    tldConfigJar(/WEB-INF/sun-web-search.tld): java.util.zip.ZipException: error in opening zip file
    [22/Sep/2006:17:30:44] finer ( 5668): ContextConfig[search]: URI='/jstl-fmt', ResourcePath='/WEB-INF/fmt.tld' [22/Sep/2006:17:30:44] finer ( 5668): ContextConfig[search]: tldConfigJar(/WEB-INF/fmt.tld): java.util.zip.ZipException: error in opening zip file
    [22/Sep/2006:17:30:48] failure ( 5668): CORE4007: Internal error: Unexpected Java exception thrown (java.lang.NoClassDefFoundError: org/xml/sax/ext/Attributes2, org/xml/sax/ext/Attributes2), stack: java.lang.NoClassDefFoundError: org/xml/sax/ext/Attributes2 at java.lang.ClassLoader.defineClass0(Native Method) at java.lang.ClassLoader.defineClass(ClassLoader.java:537) at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:123) at org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:1717) at org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:983) at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1431) at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1301) at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302) at org.apache.xerces.parsers.AbstractSAXParser.<init>(Unknown Source) at org.apache.xerces.parsers.SAXParser.<init>(Unknown Source) at org.apache.xerces.parsers.SAXParser.<init>(Unknown Source) at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.<init>(Unknown Source) at org.apache.xerces.jaxp.SAXParserImpl.<init>(Unknown Source) at org.apache.xerces.jaxp.SAXParserFactoryImpl.newSAXParser(Unknown Source) at org.apache.catalina.util.xml.XmlMapper.readXml(XmlMapper.java:274) at org.apache.catalina.startup.ContextConfig.defaultConfig(ContextConfig.java:882) at org.apache.catalina.startup.ContextConfig.start(ContextConfig.java:1004) at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:257) at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:155) at org.apache.catalina.core.StandardContext.start(StandardContext.java:3752) at com.iplanet.ias.web.WebModule.start(WebModule.java:257) at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1133) at org.apache.catalina.core.StandardHost.start(StandardHost.java:652) at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1133) at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:355) at org.apache.catalina.startup.Embedded.start(Embedded.java:995) at com.iplanet.ias.web.WebContainer.start(WebContainer.java:431) at com.iplanet.ias.web.WebContainer.startInstance(WebContainer.java:500) at com.iplanet.ias.server.J2EERunner.confPostInit(J2EERunner.java:161) [22/Sep/2006:17:30:48] failure ( 5668): CORE3186: Failed to set configuration

    ooks like you are running into bug: 4719677
    When you deploy a web application using the Administration Server from a
    remote machine, the maximum upload size by default is 10 MB. This can be
    changed by editing the
    install-root/bin/https/webapps/instance-app/WEB-INF/web.xml file. In the
    servlet webappdeploy, insert an init param named maxUploadSize with a
    value in bytes specifying the maximum upload size. Example:
    <init-param>
    <param-name>maxUploadSize</param-name>
    <param-value>90000000</param-value>
    </init-param>

  • Webb Exception - java.util.zip.ZipException: error in opening zip file

              I am tring to run my Servlet with myWAR.war. So I started first installing the CookieCounter example that came with weblogic, I did exactly as the document said but I getting the following exception:
              Thu Jan 04 11:26:45 MST 2001:<E> <HTTP> Error reading Web application '/weblogic/myserver/cookieWar.war'
              java.util.zip.ZipException: error in opening zip file
              at java.util.zip.ZipFile.open(Native Method)
              at java.util.zip.ZipFile.<init>(ZipFile.java:69)
              at weblogic.utils.jar.JarFile.<init>(JarFile.java:57)
              at weblogic.utils.jar.JarFile.<init>(JarFile.java:44)
              at weblogic.t3.srvr.HttpServer.loadWARContext(HttpServer.java:582)
              at weblogic.t3.srvr.HttpServer.initServletContexts(HttpServer.java, Compiled Code)
              at weblogic.t3.srvr.HttpServer.start(HttpServer.java:388)
              at weblogic.t3.srvr.T3Srvr.start(T3Srvr.java, Compiled Code)
              at weblogic.t3.srvr.T3Srvr.main(T3Srvr.java:827)
              at java.lang.reflect.Method.invoke(Native Method)
              at weblogic.Server.startServerDynamically(Server.java:99)
              at weblogic.Server.main(Server.java:65)
              at weblogic.Server.main(Server.java:55)
              at weblogic.NTServiceHelper.run(NTServiceHelper.java:19)
              at java.lang.Thread.run(Thread.java:479)
              Has anybody encountered the problem before I created the jar using jar cvf cookieWar.war cookie- under the command line
              

    I have seen problems like this in the past. When you create your war file, try using "jar
              cv0f" so that the jar file won't be compressed...
              mark bouchard wrote:
              > I am having this same error... the strange thing is i have two different ear files...
              > one of them works, the other doesn't. there are NO differences between them according
              > to Araxis Merge... both will deploy, and both show servlets as being registered,
              > but i can only call the servlets from one...
              >
              > what is BEA's suggested way of creating an ear file? on NT and on UNIX please....
              >
              > use the java.util.zip methods? or use a utility like jar or winzip? Personally,
              > i've found this deployment to be HIGHLY flakey at best.... my same ear files
              > deploy perfectly with iPlanet's app server.
              >
              > Mark Spotswood <[email protected]> wrote:
              > >I think this is basically the same as a file not found error.
              > >The error message says it can't open the file. Its looking
              > >for the file under: /weblogic/myserver/cookieWar.war
              > >Make sure the file is in that directory/readable, etc.
              > >--
              > >mark
              > >
              > >Paul Garduno wrote:
              > >
              > >> Just to let you know, I am getting the same error message. I haven't
              > >worked on it but hope to at some point. I would like to know if the
              > >Weblogic people have seen this error.
              > >>
              > >> Paul Garduno
              > >>
              > >> bionic99 wrote:
              > >>
              > >> > I am tring to run my Servlet with myWAR.war. So I started first installing
              > >the CookieCounter example that came with weblogic, I did exactly as
              > >the document said but I getting the following exception:
              > >> > Thu Jan 04 11:26:45 MST 2001:<E> <HTTP> Error reading Web application
              > >'/weblogic/myserver/cookieWar.war'
              > >> > java.util.zip.ZipException: error in opening zip file
              > >> > at java.util.zip.ZipFile.open(Native Method)
              > >> > at java.util.zip.ZipFile.<init>(ZipFile.java:69)
              > >> > at weblogic.utils.jar.JarFile.<init>(JarFile.java:57)
              > >> > at weblogic.utils.jar.JarFile.<init>(JarFile.java:44)
              > >> > at weblogic.t3.srvr.HttpServer.loadWARContext(HttpServer.java:582)
              > >> > at weblogic.t3.srvr.HttpServer.initServletContexts(HttpServer.java,
              > >Compiled Code)
              > >> > at weblogic.t3.srvr.HttpServer.start(HttpServer.java:388)
              > >> > at weblogic.t3.srvr.T3Srvr.start(T3Srvr.java, Compiled Code)
              > >> > at weblogic.t3.srvr.T3Srvr.main(T3Srvr.java:827)
              > >> > at java.lang.reflect.Method.invoke(Native Method)
              > >> > at weblogic.Server.startServerDynamically(Server.java:99)
              > >> > at weblogic.Server.main(Server.java:65)
              > >> > at weblogic.Server.main(Server.java:55)
              > >> > at weblogic.NTServiceHelper.run(NTServiceHelper.java:19)
              > >> > at java.lang.Thread.run(Thread.java:479)
              > >> >
              > >> > Has anybody encountered the problem before I created the jar using
              > >jar cvf cookieWar.war cookie- under the command line
              > >
              

  • Zipping files in a folder using java.util.zip

    hi guys,
    does any body has the java code for
    zipping files in a folder
    hi guys,
    actually i want to zip no of files in a folder .the folder can also have sub folder
    and after zipping when i extract the files manually i should
    maintain the same folder structure
    does any body has the code
    please reply me soon its a bit urgent

    hi smeee
    i tried running ur code but its not working
    here the command
    java c:\abc\ zzz.zip
    its saying
    no files or directories even though there's the
    directory present
    what's the solution Hi,
    Oops that was because of the error check added at the last moment..
    Anyway, You need to use the following command to run it :
    java ZipUtility c:\abc c:\zzz.zip
    Please use the following corrected code:
         Class to zip file(s).
         Requires jdk1.3.1.
         To run use the following command:
         java ZipUtility <directory or file to be zipped> <name of zip file to be created>
         Please specify absolute path names as its parameters while running this program.
    import java.util.zip.*;
    import java.io.*;
    public class ZipUtility {
         ZipOutputStream cpZipOutputStream = null;
         String strSource = "";
         String strTarget = "";
         String strSubstring = "";
         public static void main(String args[]) {
              if(     args == null || args.length < 2) {
                   System.out.println("Usage: java ZipUtility <directory or file to be zipped> <name of zip file to be created>");
                   return;
              ZipUtility udZipUtility = new ZipUtility();
              udZipUtility.strSource = args[0];
              udZipUtility.strTarget = args[1];
              udZipUtility.zip();
         private void zip(){
                        try
                             File cpFile = new File (strSource);
                             if (!cpFile.isFile() && !cpFile.isDirectory() ) {
                                  System.out.println("\nSource file/directory Not Found!");
                                  return;
                             if  (cpFile.isDirectory()) {
                                  strSubstring = strSource;;
                             } else {
                                  strSubstring = "";
                             cpZipOutputStream = new ZipOutputStream(new FileOutputStream(strTarget));
                             cpZipOutputStream.setLevel(9);
                             zipFiles( cpFile);
                             cpZipOutputStream.finish();
                             cpZipOutputStream.close();
                             System.out.println("\n Finished creating zip file " + strTarget + " from source " + strSource);
                        }catch (Exception e){
                             e.printStackTrace();
         private void  zipFiles(File cpFile) {
                   if (cpFile.isDirectory()) {
                        File [] fList = cpFile.listFiles() ;
                        for (int i=0; i< fList.length; i++){
                             zipFiles(fList) ;
                   } else {
                        try {
                             String strAbsPath = cpFile.getAbsolutePath();
                             String strZipEntryName ="";
                             if (!strSubstring.equals("") ){
                                  strZipEntryName = strAbsPath.substring(strSource.length()+1, strAbsPath.length());
                             } else {
                                  strZipEntryName = cpFile.getName();
                             byte[] b = new byte[ (int)(cpFile.length()) ];
                             FileInputStream cpFileInputStream = new FileInputStream (cpFile) ;
                             int i = cpFileInputStream.read(b, 0, (int)cpFile.length());
                             ZipEntry cpZipEntry = new ZipEntry(strZipEntryName);
                             cpZipOutputStream.putNextEntry(cpZipEntry );
                             cpZipOutputStream.write(b, 0, (int)cpFile.length());
                             cpZipOutputStream.closeEntry() ;
                        } catch (Exception e) {
                             e.printStackTrace();

  • Java.util.zip.ZipFile.entries() shows only 99 files but zip file is fine.

    Hi,
    I have a wierd issue with java.util.zip.ZipFile
    Code as simple as
    ZipFile file = new ZipFile("my.zip") ;
    System.out.println(file.size());
    For this particular zip file, it says 99 files found but the zip contains more than 60,000 files. I tried the zip with unzip and zip utilities and the zip file checks out fine. I even tried to unzip the contents, and zip 'em up all over again, just to eliminate the chances of corruption while the zip was being transferred over the network.
    The same program works fine with another zip containing more or less the same number of files and prints 63730.
    Any idea? This can not possibly be related to the type of files the zips contain? right? In any case, the contents of both zips are text/xml files.
    Any help would be greatly appreciated.
    Regards,
    ZiroFrequency

    I know its a problem with this particular zip. But whats interesting is that "unzip" can easily open / verify the zip and claims that it is a valid zip.
    As I wrote earlier, I unzipped the file and zipped up the contents again in a new zip but java can't still count the contents correctly.
    So I am thinking there is something to do with the "contents" of the xmls inside the zip? (characterset issues?)
    There are no exceptions thrown and no error anywhere :(
    I basically need to pinpoint the issue so that I can have it corrected upstream as this zip file processing is an ongoing process and I need to resolve it not just once but for the periodic executions.
    Hope this helps explain the issue.

  • Java.util.zip.ZipException: Too many open files on Linux

    Hi,
    We have web application running on Caucho's resin server on jdk 1.5.0_11 and Red hat Linux. We are noticing that java process is running out of file handles within 24-30 hours. We have file limit of 5000 which it consumes in 24 hours throwing 'java.util.zip.ZipException: Too many open files'.
    I have made sure all sorts of file handles are closed from application point of view. Here is the snapshot of lsof (list of file handles) from java process. The following list keeps growing until it runs out of limit. Do you have tips/suggestions on how to mitigate this problem (considering we dont want to increase ulimit for this process)? Also, can you make out any thing more from the description of file handles like, are they unclosed POP3 connections or URL connection to external sites?
    java 7156 resin 120u IPv4 34930051 UDP localhost.localdomain:59693
    java 7156 resin 121u IPv4 34927823 UDP localhost.localdomain:59663
    java 7156 resin 122u IPv4 34931861 UDP localhost.localdomain:59739
    java 7156 resin 123u IPv4 34932023 UDP localhost.localdomain:59745
    java 7156 resin 124u IPv4 34930054 UDP localhost.localdomain:59700
    java 7156 resin 125u IPv4 34927826 UDP localhost.localdomain:59665
    java 7156 resin 126u IPv4 34927829 UDP localhost.localdomain:59666
    java 7156 resin 127u IPv4 34930057 UDP localhost.localdomain:59703
    java 7156 resin 128u IPv4 34930713 UDP localhost.localdomain:59727
    java 7156 resin 129u IPv4 34930716 UDP localhost.localdomain:59730
    java 7156 resin 130u IPv4 34932238 UDP localhost.localdomain:59789
    java 7156 resin 131u IPv4 34932026 UDP localhost.localdomain:59749
    java 7156 resin 132u IPv4 34932221 UDP localhost.localdomain:59770
    java 7156 resin 133u IPv4 34932224 UDP localhost.localdomain:59775
    java 7156 resin 134u IPv4 34932029 UDP localhost.localdomain:59753
    java 7156 resin 135u IPv4 34932032 UDP localhost.localdomain:59754
    java 7156 resin 138u IPv4 34932035 UDP localhost.localdomain:59760
    java 7156 resin 139u IPv4 34932038 UDP localhost.localdomain:59763
    java 7156 resin 140u IPv4 34932227 UDP localhost.localdomain:59780
    java 7156 resin 141u IPv4 34932230 UDP localhost.localdomain:59781
    java 7156 resin 144u IPv4 34932234 UDP localhost.localdomain:59786
    java 7156 resin 146u IPv4 34932241 UDP localhost.localdomain:59792
    java 7156 resin 147u IPv4 34932247 UDP localhost.localdomain:59802

    Finally we resolved this issue. It was oracle driver which had some compatibility issue, we upgraded our Oracle client driver to newer version, and this fixed the problem. Base line, there was nothing wrong with application code, code was doing good resource clean up, but oracle driver was leaking handles per every connection.

  • Problems with java.util.zip

    I've got a odd problem here. I'm not sure if this is the appropriate forum but I couldn't find anyplace more appropriate.
    So the problem is...
    I create my ZIP file and if I open it in WinZip, no problem. But if I open the ZIP file using the 'Compressed Folders' feature of Windows Explorer I don't see any of the files. As far as I can tell, if the files I ZIP up do not contain any path information then they open fine via 'Compressed Folders'.
    Is this a bug in java.util.zip? Or is the 'Compressed Folders' feature in Windows Explorer half-baked?
    And finally is there any way for me to not include the path information of the files added to ZIP?
    Thanks.

    Looce:
    I'm more than willing to modify things.
    But I'm still curious why WinZip and Windows are treating the ZIP files differently.
    Also, the only way I can figure to get the files into the ZIP without the path information being stored in the ZIP file is by copying the files to the directory containing my application jar file and then passing in the file name without the path being specified. That is the only way FileInputStream would be able to find the files without including path information. This seems like a lot of unnecessary overhead.
    Another oddity is that if I create the ZIP archive using the file path for the FileInputStream and view the ZIP file using a HEX editor the entire path is being stored including the drive letter. But if you view the file using WinZip the path field seems to be removing the drive letter and only displaying the path. On top of that, even though the drive letter is contained in the archive if you unzip the file using WinZip it ignores the drive letter and unzips the file to whatever drive the archive is located on. In the grand scheme of things it makes sense for WinZip to ignore the drive letter.
    Thanks for you help anyways.

Maybe you are looking for

  • Query cfl

    hi how to make query cfl... i created combo box in system form..its have two type...job order, subcontracting... when i choose job order . its open production order list....when i choose subcontracting its open Purchase order list... Thanks & regards

  • Movies Purchased on ATV will not sync back to iTunes

    I've tried "Transfer Purchases" - no good. I've gone to Automatic Sync - no good. The movies and shows I've purchased on the ATV itself will not sync back to my iTunes library, but the movies I purchased from the computer will sync to the ATV. So ...

  • Pay monthly iphone say invalid sim when put in pay as u go sim

    Hi my brother gave me his i phone 4 as he has now had an up grade as his contract had ended. I have put in a pay as you go sim on the same network and it says invalid sim?

  • Verify Mac HD Startup disk error?

    Verifying volume "Macintosh HD" Checking HFS Plus volume. Checking Extents Overflow file. Checking Catalog file. Illegal name <----------------------------- Illegal name <------------------------------------ Checking multi-linked files. Checking mult

  • Journal voucher select fuction module

    Dear gurus, pls. tell me journal voucher fuction module or any idea. thank's & regards, Shiv Pujan Sharma