Examples of ZipInputStream


Examples of java.util.zip.ZipInputStream

        try {
            String entryName = getEntryName(fileName);
            if (entryName.length() == 0) {
                return true;
            }
            ZipInputStream file = openZip(fileName);
            boolean result = false;
            while (true) {
                ZipEntry entry = file.getNextEntry();
                if (entry == null) {
                    break;
                }
                if (entry.getName().equals(entryName)) {
                    result = true;
                    break;
                }
                file.closeEntry();
            }
            file.close();
            return result;
        } catch (IOException e) {
            return false;
        }
    }
View Full Code Here

Examples of java.util.zip.ZipInputStream

        try {
            String entryName = getEntryName(fileName);
            if (entryName.length() == 0) {
                return true;
            }
            ZipInputStream file = openZip(fileName);
            boolean result = false;
            while (true) {
                ZipEntry entry = file.getNextEntry();
                if (entry == null) {
                    break;
                }
                String n = entry.getName();
                if (n.equals(entryName)) {
                    result = entry.isDirectory();
                    break;
                } else  if (n.startsWith(entryName)) {
                    if (n.length() == entryName.length() + 1) {
                        if (n.equals(entryName + "/")) {
                            result = true;
                            break;
                        }
                    }
                }
                file.closeEntry();
            }
            file.close();
            return result;
        } catch (IOException e) {
            return false;
        }
    }
View Full Code Here

Examples of java.util.zip.ZipInputStream

    }

    public long length(String fileName) {
        try {
            String entryName = getEntryName(fileName);
            ZipInputStream file = openZip(fileName);
            long result = 0;
            while (true) {
                ZipEntry entry = file.getNextEntry();
                if (entry == null) {
                    break;
                }
                if (entry.getName().equals(entryName)) {
                    result = entry.getSize();
                    if (result == -1) {
                        result = 0;
                        while (true) {
                            long x = file.skip(16 * Constants.IO_BUFFER_SIZE);
                            if (x == 0) {
                                break;
                            }
                            result += x;
                        }
                    }
                    break;
                }
                file.closeEntry();
            }
            file.close();
            return result;
        } catch (IOException e) {
            return 0;
        }
    }
View Full Code Here

Examples of java.util.zip.ZipInputStream

                path += "!";
            }
            if (!path.endsWith("/")) {
                path += "/";
            }
            ZipInputStream file = openZip(path);
            String dirName = getEntryName(path);
            String prefix = path.substring(0, path.length() - dirName.length());
            ArrayList<String> list = New.arrayList();
            while (true) {
                ZipEntry entry = file.getNextEntry();
                if (entry == null) {
                    break;
                }
                String name = entry.getName();
                if (name.startsWith(dirName) && name.length() > dirName.length()) {
                    int idx = name.indexOf('/', dirName.length());
                    if (idx < 0 || idx >= name.length() - 1) {
                        list.add(prefix + name);
                    }
                }
                file.closeEntry();
            }
            file.close();
            String[] result = new String[list.size()];
            list.toArray(result);
            return result;
        } catch (IOException e) {
            throw DbException.convertIOException(e, "listFiles " + path);
View Full Code Here

Examples of java.util.zip.ZipInputStream

    public FileObject openFileObject(String fileName, String mode) throws IOException {
        String entryName = getEntryName(fileName);
        if (entryName.length() == 0) {
            throw new FileNotFoundException(fileName);
        }
        ZipInputStream in = openZip(fileName);
        while (true) {
            ZipEntry entry = in.getNextEntry();
            if (entry == null) {
                break;
            }
            if (entry.getName().equals(entryName)) {
                return new FileObjectZip2(fileName, entryName, in, length(fileName));
            }
            in.closeEntry();
        }
        in.close();
        throw new FileNotFoundException(fileName);
    }
View Full Code Here

Examples of java.util.zip.ZipInputStream

        return fileName;
    }

    private ZipInputStream openZip(String fileName) throws IOException {
        fileName = unwrap(fileName);
        return new ZipInputStream(IOUtils.openFileInputStream(fileName));
    }
View Full Code Here

Examples of java.util.zip.ZipInputStream

    private void unzip(String zipFileName, String targetDir) {
        InputStream in = null;
        try {
            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);
                }
                OutputStream o = null;
                try {
                    o = IOUtils.openFileOutputStream(targetDir + SysProperties.FILE_SEPARATOR + fileName, false);
                    IOUtils.copy(zipIn, o);
                    o.close();
                } finally {
                    IOUtils.closeSilently(o);
                }
                zipIn.closeEntry();
            }
            zipIn.closeEntry();
            zipIn.close();
        } catch (IOException e) {
            error(e);
        } finally {
            IOUtils.closeSilently(in);
        }
View Full Code Here

Examples of java.util.zip.ZipInputStream

    throws Exception {

    if (debug)
      System.out.println("RAConfig.extractFromJAR(" + fileName +  "," + reader + ")");

    ZipInputStream stream = new ZipInputStream(reader);
    ZipEntry currEntry = stream.getNextEntry();
    while (stream.available() > 0) {
      if (currEntry == null) break;
      if (currEntry.getName().equalsIgnoreCase(fileName)) {
        // the fileName is found, return the InputStream.
        if (debug)
          System.out.println("RAConfig.extractFromJAR : currEntry = " + currEntry);
        else if (verbose)
          System.out.println("extract \"" + fileName + "\" from JAR.");

        return stream;
      }
      currEntry = stream.getNextEntry();
    }
    // close the stream and return null if file not found.
    stream.close();
    return null;
  }
View Full Code Here

Examples of java.util.zip.ZipInputStream

        return false;
    }

    private InputStream retrieveJavaSource(String classname) {
       
        ZipInputStream zipIn = null;
        try {
            Version wgaVersion = (Version) WGADesignConfigurationModel.VERSIONCOMPLIANCE_TO_WGA_VERSION.get(_versionCompliance.getKey());
            if (wgaVersion != null) {
                InputStream sourceIn;
                try {
                    sourceIn = Plugin.getDefault().getResourceAsStream("resources/wga/source_" + wgaVersion.getMajorVersion() + "_" + wgaVersion.getMinorVersion() + ".jar");
                }
                catch (Exception e) {
                    Plugin.getDefault().logError("Unable to find source for wga version compliance '" + wgaVersion.getMajorVersion() + "." + wgaVersion.getMinorVersion() + "'.");
                    return null;
                }               
                zipIn = new ZipInputStream(sourceIn);
                ZipEntry entry = zipIn.getNextEntry();
                while (entry != null) {
                    String sourceName = entry.getName();
                    sourceName = sourceName.replaceAll("/", ".");
                    if (sourceName.endsWith(".java")) {
                        sourceName = sourceName.substring(0, sourceName.length() - ".java".length());
                    }
                    if (sourceName.equals(classname)) {
                        return zipIn;
                    }
                    entry = zipIn.getNextEntry();
                }
            }
        }
        catch (IOException e) {
        }
       
        // source not found
        try {
            zipIn.close();
        }
        catch (IOException e) {
        }
       
        return null;
View Full Code Here

Examples of java.util.zip.ZipInputStream

  public DocumentIterator iterator() {
      try {
        return new AbstractDocumentIterator() {
          final Reference2ObjectArrayMap<Enum<?>,Object> metadata = new Reference2ObjectArrayMap<Enum<?>,Object>( new Enum[ 1 ], new Object[ 1 ] );

          ZipInputStream zis = new ZipInputStream( new FileInputStream( zipFile.getName() ) );
          public Document nextDocument() throws IOException {
            ZipEntry entry;
            String name;
            do {
              entry = zis.getNextEntry();
              if ( entry == null ) return null;
              name = entry.getName();
            } while ( !Character.isDigit( name.charAt( 0 ) ) )
            String title = entry.getComment();
            if ( DEBUG ) LOGGER.debug( "Reading sequentially document " + title + ", name: " + entry.getName() );
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.