Examples of ZipInputStream


Examples of java.util.zip.ZipInputStream

     getResources(
       String    resource_name )
  {
    List  result = new ArrayList();
   
    ZipInputStream  zis = null;
 
    try{
      zis = new ZipInputStream(
          new BufferedInputStream( new FileInputStream( contents ) ));
       
      while( true ){
       
        ZipEntry  entry = zis.getNextEntry();
         
        if ( entry == null ){
         
          break;
        }
       
        String  name = entry.getName();
       
        int pos = name.indexOf( resource_name + "/" );
       
        if ( pos != -1 ){
                   
          if ( name.endsWith( ".vuze" )){
           
            ByteArrayOutputStream baos = new ByteArrayOutputStream( 16*1024 );
           
            byte[]  buffer = new byte[16*1024];
           
            while( true ){
           
              int  len = zis.read( buffer );
             
              if ( len <= 0 ){
               
                break;
              }
             
              baos.write( buffer, 0, len );
            }
           
            result.add( new ByteArrayInputStream( baos.toByteArray()));
          }
        }
      }
    }catch( Throwable e ){
     
      Debug.out( e );
     
    }finally{
     
      if ( zis != null ){
       
        try{
          zis.close();
         
        }catch( Throwable e ){
        }
      }
    }
View Full Code Here

Examples of java.util.zip.ZipInputStream

   */
  private boolean readData(final InputStream in)
  {
    try
    {
      final ZipInputStream iconJar = new ZipInputStream(in);
      ZipEntry ze = iconJar.getNextEntry();
      while (ze != null)
      {
        final String fullName = ze.getName();
        if (fullName.endsWith(".gif"))
        {
          final String category = getCategory(fullName);
          final String name = getName(fullName);
          final Image image = getImage(iconJar);
          final Long bytes = new Long(ze.getSize());
          //logger.debug ("Add Icon: " + name);
          addIconEntry(name, category, image, bytes);
        }
        iconJar.closeEntry();
        ze = iconJar.getNextEntry();
      }
    }
    catch (IOException e)
    {
      logger.warn("Unable to load the Icons", e);
View Full Code Here

Examples of java.util.zip.ZipInputStream

    final Object data = request.getSession().getAttribute("report:" + reportName);
    if (data instanceof byte[] == false)
    {
      throw new ContentIOException("No such repository");
    }
    final ZipInputStream zin = new ZipInputStream(new ByteArrayInputStream((byte[]) data));
    ZipEntry ze = zin.getNextEntry();
    while (ze != null)
    {
      final String fullName = ze.getName();
      if (fullName.equals(fileName) == false)
      {
        zin.closeEntry();
        ze = zin.getNextEntry();
        continue;
      }

      response.setContentLength((int) ze.getSize());

      final String contextMimeType = getServletContext().getMimeType(fileName);
      if (contextMimeType != null)
      {
        response.setContentType(contextMimeType);
      }

      final ServletOutputStream outputStream = response.getOutputStream();
      IOUtils.getInstance().copyStreams(zin, outputStream);
      outputStream.flush();
    }
    zin.close();
  }
View Full Code Here

Examples of java.util.zip.ZipInputStream

    private static String getOriginalDbName(String fileName, String db) throws IOException {
        InputStream in = null;
        try {
            in = IOUtils.openFileInputStream(fileName);
            ZipInputStream zipIn = new ZipInputStream(in);
            String originalDbName = null;
            boolean multiple = false;
            while (true) {
                ZipEntry entry = zipIn.getNextEntry();
                if (entry == null) {
                    break;
                }
                String entryName = entry.getName();
                zipIn.closeEntry();
                String name = getDatabaseNameFromFileName(entryName);
                if (name != null) {
                    if (db.equals(name)) {
                        originalDbName = name;
                        // we found the correct database
                        break;
                    } else if (originalDbName == null) {
                        originalDbName = name;
                        // we found a database, but maybe another one
                    } else {
                        // we have found multiple databases, but not the correct
                        // one
                        multiple = true;
                    }
                }
            }
            zipIn.close();
            if (multiple && !db.equals(originalDbName)) {
                throw new IOException("Multiple databases found, but not " + db);
            }
            return originalDbName;
        } finally {
View Full Code Here

Examples of java.util.zip.ZipInputStream

                    originalDbName = originalDbName.substring(1);
                }
                originalDbLen = originalDbName.length();
            }
            in = IOUtils.openFileInputStream(zipFileName);
            ZipInputStream zipIn = new ZipInputStream(in);
            while (true) {
                ZipEntry entry = zipIn.getNextEntry();
                if (entry == null) {
                    break;
                }
                String fileName = entry.getName();
                // restoring windows backups on linux and vice versa
                fileName = fileName.replace('\\', SysProperties.FILE_SEPARATOR.charAt(0));
                fileName = fileName.replace('/', SysProperties.FILE_SEPARATOR.charAt(0));
                if (fileName.startsWith(SysProperties.FILE_SEPARATOR)) {
                    fileName = fileName.substring(1);
                }
                boolean copy = false;
                if (db == null) {
                    copy = true;
                } else if (fileName.startsWith(originalDbName + ".")) {
                    fileName = db + fileName.substring(originalDbLen);
                    copy = true;
                }
                if (copy) {
                    OutputStream o = null;
                    try {
                        o = IOUtils.openFileOutputStream(directory + SysProperties.FILE_SEPARATOR + fileName, false);
                        IOUtils.copy(zipIn, o);
                        o.close();
                    } finally {
                        IOUtils.closeSilently(o);
                    }
                }
                zipIn.closeEntry();
            }
            zipIn.closeEntry();
            zipIn.close();
        } catch (IOException e) {
            throw DbException.convertIOException(e, zipFileName);
        } finally {
            IOUtils.closeSilently(in);
        }
View Full Code Here

Examples of java.util.zip.ZipInputStream

            if (in == null) {
                return null;
            }
            return IOUtils.readBytesAndClose(in, 0);
        }
        ZipInputStream zipIn = new ZipInputStream(in);
        try {
            while (true) {
                ZipEntry entry = zipIn.getNextEntry();
                if (entry == null) {
                    break;
                }
                String entryName = entry.getName();
                if (!entryName.startsWith("/")) {
                    entryName = "/" + entryName;
                }
                if (entryName.equals(name)) {
                    ByteArrayOutputStream out = new ByteArrayOutputStream();
                    IOUtils.copy(zipIn, out);
                    zipIn.closeEntry();
                    return out.toByteArray();
                }
                zipIn.closeEntry();
            }
        } catch (IOException e) {
            // if this happens we have a real problem
            e.printStackTrace();
        } finally {
            zipIn.close();
        }
        return null;
    }
View Full Code Here

Examples of java.util.zip.ZipInputStream

                    in = new BufferedInputStream(zipurl.openStream());

                    if (Debug.debugging("zip")) {
                        Debug.output(" unzipping " + zipFileName);
                    }
                    ZipInputStream zin = new ZipInputStream(in);
                    ZipEntry e;

                    while ((e = zin.getNextEntry()) != null) {

                        if (e.isDirectory()) {
                            new File(toDir, e.getName()).mkdirs();
                        } else {
                            if (Debug.debugging("zip")) {
                                Debug.output(" unzipping " + e.getName());
                            }
                            unzip(zin, new File(toDir, e.getName()));
                        }
                    }
                    zin.close();
                    if (deleteAfter) {
                        if (Debug.debugging("zip")) {
                            Debug.output("unzipping complete, deleting zip file");
                        }
View Full Code Here

Examples of java.util.zip.ZipInputStream

}

public void unzip()
     throws Exception
{
     ZipInputStream zis = new ZipInputStream(zipUrl.openStream());
     java.util.zip.ZipEntry zipEntry;
     while((zipEntry = zis.getNextEntry()) != null)
         saveEntry(zis, zipEntry);
}
View Full Code Here

Examples of java.util.zip.ZipInputStream

    /**
     * Load the classes, resources, etc.
     */
    public JarInfo loadJar() throws IOException {
        //System.out.println("Enter> JarLoader.loadJar()");
        ZipInputStream zis = null;
        Manifest mf = null;

        boolean empty = true;

        try {
            zis = new ZipInputStream(jarStream);
            ZipEntry ent = null;

            while ((ent = zis.getNextEntry()) != null) {
                empty = false;

                String name = ent.getName();

                if (Manifest.isManifestName(name)) {
                    /* the object we're loading */
                    ByteArrayOutputStream baos = new ByteArrayOutputStream();
                    byte buffer[] = new byte[1024];

                    for (;;) {
                        int len = zis.read(buffer);
                        if (len < 0) {
                            break;
                        }
                        baos.write(buffer, 0, len);
                    }

                    byte[] buf = baos.toByteArray();
                    mf = new Manifest(buf);
                }

            }

        } catch (IOException ex) {
            throw ex;
        } catch (Throwable th) {
            th.printStackTrace();
            throw new IOException("loadJar caught: " + th);
        } finally {
            if (zis != null) {
                try {
                    zis.close();
                } catch (Exception ex) {
                    // ignore
                }
            }
        }
View Full Code Here

Examples of java.util.zip.ZipInputStream

    }
  }
  public static final int BUFFER = 4096;
  public static void speedupZip(InputStream input, OutputStream output)
    throws IOException {
    ZipInputStream in = new ZipInputStream(input);
    ZipOutputStream out = new ZipOutputStream(output);
    ZipEntry inentry;
    ZipEntry outentry;
    int count;
    byte[] buffer = new byte[BUFFER];
    while ((inentry = in.getNextEntry()) != null) {
      outentry = new ZipEntry(inentry.getName());
      logger.debug("Extra: " + inentry.getExtra());
      outentry.setExtra(inentry.getExtra());
      logger.debug("time: " + inentry.getTime());
      outentry.setTime(inentry.getTime());
      logger.debug("method: " + inentry.getMethod());
      outentry.setMethod(inentry.getMethod());
      logger.debug("comment: " + inentry.getComment());
      outentry.setComment(inentry.getComment());
      logger.debug("CRC: " + inentry.getCrc());
      if (inentry.getCrc() != -1) {
        outentry.setCrc(inentry.getCrc());
      }
      logger.debug("size: " + inentry.getSize());
      if (inentry.getSize() != -1) {
        outentry.setSize(inentry.getSize());
      }
      out.putNextEntry(outentry);
      if (!inentry.isDirectory()) {
        if (inentry.getName().endsWith(".jar")
          || inentry.getName().endsWith(".zip")
          || inentry.getName().endsWith(".war")
          || inentry.getName().endsWith(".ear")) {
          speedupZip(in, out);
        } else if (inentry.getName().endsWith(".class")) {
          speedup(in, inentry.getName(), out);
        } else {
          while ((count = in.read(buffer, 0, BUFFER)) != -1) {
            out.write(buffer, 0, count);
          }
        }

      }
      out.closeEntry();
      in.closeEntry();
    }
    out.close();
    in.close();
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.