Package java.util.zip

Examples of java.util.zip.ZipEntry


   */
  protected void readContentFromZipFile(HttpDoc doc, ZipFile contentZip)
    throws IOException {
    byte[] content = null;
    for (Enumeration enumeration = contentZip.entries(); enumeration.hasMoreElements();) {
      ZipEntry zipEntry = (ZipEntry) enumeration.nextElement();
      if (zipEntry.getName().startsWith("content")) {
        InputStream is = contentZip.getInputStream(zipEntry);
        int length = (int) zipEntry.getSize();
        content = new byte[length];
        int startPos = 0;
        while (startPos < length) {
          startPos += is.read(content, startPos, length - startPos);
        }
View Full Code Here


        new BufferedOutputStream(new FileOutputStream(tempF));
      bos.write(zip);
      bos.close();*/
     
      ZipInputStream zis = new ZipInputStream(new ByteArrayInputStream(zip));
      ZipEntry ze;
      final byte[] buff = new byte[1024];
      while ((ze = zis.getNextEntry()) != null) {
//        System.out.println("Cache: inflating " + ze.getName());
        if (ze.isDirectory()) {
          new File(cacheDir, ze.getName()).mkdir();
          continue;
        }
        BufferedOutputStream bo =
          new BufferedOutputStream(new FileOutputStream(new File(cacheDir, ze.getName())));
        while (true) {
          int amountRead = zis.read(buff);
          if (amountRead == -1) {
            break;
          }
View Full Code Here

                }
            }
        } else {
            byte[] buf = new byte[1024];
            int len;
            ZipEntry entry = new ZipEntry(file.getPath());
            FileInputStream fis = new FileInputStream(file);
            BufferedInputStream bis = new BufferedInputStream(fis);
            zos.putNextEntry(entry);
            while ((len = bis.read(buf)) >= 0) {
                zos.write(buf, 0, len);
View Full Code Here

                Enumeration en = zipfile.entries();
                HashMap newRepositories = new HashMap();
                HashMap newResources = new HashMap();

                while (en.hasMoreElements()) {
                    ZipEntry entry = (ZipEntry) en.nextElement();
                    String eName = entry.getName();

                    if (!eName.regionMatches(0, entryPath, 0, entryPath.length())) {
                        // names don't match - not a child of ours
                        continue;
                    }
                    String[] entrypath = StringUtils.split(eName, "/");
                    if (depth > 0 && !shortName.equals(entrypath[depth-1])) {
                        // catch case where our name is Foo and other's is FooBar
                        continue;
                    }

                    // create new repositories and resources for all entries with a
                    // path depth of this.depth + 1
                    if (entrypath.length == depth + 1 && !entry.isDirectory()) {
                        // create a new child resource
                        ZipResource resource = new ZipResource(entry.getName(), this);
                        newResources.put(resource.getShortName(), resource);
                    } else if (entrypath.length > depth) {
                        // create a new child repository
                        if (!newRepositories.containsKey(entrypath[depth])) {
                            ZipEntry child = composeChildEntry(entrypath[depth]);
                            ZipRepository rep = new ZipRepository(file, this, child);
                            newRepositories.put(entrypath[depth], rep);
                        }
                    }
                }
View Full Code Here

        }
    }

    private ZipEntry composeChildEntry(String name) {
        if (entryPath == null || entryPath.length() == 0) {
            return new ZipEntry(name);
        } else if (entryPath.endsWith("/")) {
            return new ZipEntry(entryPath + name);
        } else {
            return new ZipEntry(entryPath + "/" + name);
        }
    }
View Full Code Here

    public InputStream getInputStream() throws IOException {
        ZipFile zipfile = null;
        try {
            zipfile = repository.getZipFile();
            ZipEntry entry = zipfile.getEntry(entryName);
            if (entry == null) {
                throw new IOException("Zip resource " + this + " does not exist");
            }
            int size = (int) entry.getSize();
            byte[] buf = new byte[size];
            InputStream in = zipfile.getInputStream(entry);
            int read = 0;
            while (read < size) {
                int r = in.read(buf, read, size-read);
View Full Code Here

    public String getContent(String encoding) throws IOException {
        ZipFile zipfile = null;
        try {
            zipfile = repository.getZipFile();
            ZipEntry entry = zipfile.getEntry(entryName);
            if (entry == null) {
                throw new IOException("Zip resource " + this + " does not exist");
            }
            InputStream in = zipfile.getInputStream(entry);
            int size = (int) entry.getSize();
            byte[] buf = new byte[size];
            int read = 0;
            while (read < size) {
                int r = in.read(buf, read, size-read);
                if (r == -1)
View Full Code Here

  /**
   * Returns the size of the file or 0 if it does not exist.
   */
  public long size()
  {
    ZipEntry entry ;
   
    try
    {
      if ( this.isInArchive() )
      {
        entry = this.archiveEntry() ;
        // if ( DEBUG ) com.mdcs.joi.Inspector.inspectWait( entry ) ;
        return entry.getSize() ;
      }
      else
      {
        return this.getFile().length() ;
      }
View Full Code Here

   * Returns the timestamp of when the file was last modified
   * or 0 in any case of error.
   */
  public long lastModified()
  {
    ZipEntry entry ;
   
    try
    {
      if ( this.isInArchive() )
      {
        entry = this.archiveEntry() ;
        return entry.getTime() ;
      }
      else
      {
        return this.getFile().lastModified() ;
      }
View Full Code Here

   * Returns an opened input stream on the file defined by this locator.
   */
  public InputStream getInputStream()
    throws Exception
  {
    ZipEntry entry ;
   
    if ( this.isInArchive() )
    {
      entry = this.archiveEntry() ;
      return this.container().getInputStream( entry ) ;
View Full Code Here

TOP

Related Classes of java.util.zip.ZipEntry

Copyright © 2015 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.