Java 类java.util.zip.ZipFile 实例源码

项目:can4eve    文件:RandomAccessLogReader.java   
/**
 * create me based on a (potentially zipped) file
 * 
 * @param file
 * @throws Exception
 */
public RandomAccessLogReader(File logFile) throws Exception {
  if (logFile.getName().endsWith(".zip")) {
    File unzipped = new File(logFile.getParentFile(), "unzipped");
    zipFile = new ZipFile(logFile);
    Enumeration<? extends ZipEntry> entries = zipFile.entries();
    if (entries.hasMoreElements()) {
      ZipEntry entry = entries.nextElement();
      if (!entry.isDirectory()) {
        if (!unzipped.isDirectory()) {
          unzipped.mkdir();
        }
        elmLogFile = new File(unzipped, entry.getName());
        InputStream in = zipFile.getInputStream(entry);
        OutputStream out = new FileOutputStream(elmLogFile);
        IOUtils.copy(in, out);
        IOUtils.closeQuietly(in);
        out.close();
      }
    }
  } else {
    elmLogFile = logFile;
  }
}
项目:Reer    文件:DefaultModuleRegistry.java   
private Properties loadModuleProperties(String name, File jarFile) {
    try {
        ZipFile zipFile = new ZipFile(jarFile);
        try {
            final String entryName = name + "-classpath.properties";
            ZipEntry entry = zipFile.getEntry(entryName);
            if (entry == null) {
                throw new IllegalStateException("Did not find " + entryName + " in " + jarFile.getAbsolutePath());
            }
            return GUtil.loadProperties(zipFile.getInputStream(entry));
        } finally {
            zipFile.close();
        }
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
项目:L2jBrasil    文件:ScriptPackage.java   
/**
 * @param pack The scriptFiles to set.
 */
private void addFiles(ZipFile pack)
{
    for (Enumeration<? extends ZipEntry> e = pack.entries(); e.hasMoreElements();)
    {
        ZipEntry entry = e.nextElement();
        if (entry.getName().endsWith(".xml"))
        {
            try
            {
                ScriptDocument newScript = new ScriptDocument(entry.getName(), pack.getInputStream(entry));
                _scriptFiles.add(newScript);
            }
            catch (IOException e1)
            {
                e1.printStackTrace();
            }
        }
        else if (!entry.isDirectory())
        {
            _otherFiles.add(entry.getName());
        }
    }
}
项目:CloudNet    文件:MasterTemplateLoader.java   
public MasterTemplateLoader unZip(String dest)
{
    try{

        ZipFile zipFile = new ZipFile(this.dest);
        ZipEntry z;
        Enumeration<? extends ZipEntry> entryEnumeration = zipFile.entries();
        while (entryEnumeration.hasMoreElements())
        {
            z = entryEnumeration.nextElement();
            extractEntry(zipFile, z, dest);
        }
        new File(this.dest).delete();
    }catch (Exception ex)
    {
        ex.printStackTrace();
    }
    return this;
}
项目:VirtualHook    文件:NativeLibraryHelperCompat.java   
private static Set<String> getABIsFromApk(String apk) {
    try {
        ZipFile apkFile = new ZipFile(apk);
        Enumeration<? extends ZipEntry> entries = apkFile.entries();
        Set<String> supportedABIs = new HashSet<String>();
        while (entries.hasMoreElements()) {
            ZipEntry entry = entries.nextElement();
            String name = entry.getName();
            if (name.contains("../")) {
                continue;
            }
            if (name.startsWith("lib/") && !entry.isDirectory() && name.endsWith(".so")) {
                String supportedAbi = name.substring(name.indexOf("/") + 1, name.lastIndexOf("/"));
                supportedABIs.add(supportedAbi);
            }
        }
        return supportedABIs;
    } catch (Exception e) {
        e.printStackTrace();
    }

    return null;
}
项目:incubator-netbeans    文件:GlobalSourceForBinaryImpl.java   
private static String findNBRoot(final ZipFile nbSrcZip) {
    String nbRoot = null;
    for (Enumeration<? extends ZipEntry> en = nbSrcZip.entries(); en.hasMoreElements(); ) {
        ZipEntry entry = (ZipEntry) en.nextElement();
        if (!entry.isDirectory()) {
            continue;
        }
        String name = entry.getName();
        if (!name.equals(NBBUILD_ENTRY) &&
                !(name.endsWith(NBBUILD_ENTRY) && name.substring(name.indexOf('/') + 1).equals(NBBUILD_ENTRY))) {
            continue;
        }
        ZipEntry xmlEntry = nbSrcZip.getEntry(name + "nbproject/project.xml"); // NOI18N
        if (xmlEntry != null) {
            nbRoot = name.substring(0, name.length() - NBBUILD_ENTRY.length());
            break;
        }
    }
    return nbRoot;
}
项目:NBANDROID-V2    文件:ApkUtils.java   
@Nullable
public ManifestData apkPackageName(File apkFile) {
    if (apkFile == null) {
        return null;
    }
    try {
        ZipFile zip = new ZipFile(apkFile);
        ZipEntry mft = zip.getEntry(AndroidConstants.ANDROID_MANIFEST_XML);

        ApkUtils decompresser = new ApkUtils();
        String xml = decompresser.decompressXML(ByteStreams.toByteArray(zip.getInputStream(mft)));
        ManifestData manifest = AndroidProjects.parseProjectManifest(new ByteArrayInputStream(xml.getBytes()));
        return manifest;
    } catch (IOException ex) {
        LOG.log(Level.INFO, "cannot get package name from apk file " + apkFile, ex);
        return null;
    }

}
项目:MCBot    文件:MappingDatabase.java   
public void reload() throws IOException {
    mappings.clear();
    ZipFile zipfile = new ZipFile(zip);

    try {
        for (MappingType type : MappingType.values()) {
            if (type.getCsvName() != null) {
                List<String> lines;
                lines = IOUtils.readLines(zipfile.getInputStream(zipfile.getEntry(type.getCsvName() + ".csv")), Charsets.UTF_8);

                lines.remove(0); // Remove header line

                for (String line : lines) {
                    String[] info = line.split(",", -1);
                    String comment = info.length > 3 ? Joiner.on(',').join(ArrayUtils.subarray(info, 3, info.length)) : "";
                    IMapping mapping = new IMapping.Impl(type, info[0], info[1], comment, Side.values()[Integer.valueOf(info[2])]);
                    mappings.put(type, mapping);
                }
            }
        }
    } finally {
        zipfile.close();
    }
}
项目:VASSAL-src    文件:ZipUpdater.java   
private long getCrc(ZipFile file, ZipEntry entry) throws IOException {
  long crc = -1;
  if (entry != null) {
    crc = entry.getCrc();
    if (crc < 0) {
      CRC32 checksum = new CRC32();

      final InputStream in = file.getInputStream(entry);
      try {
        final byte[] buffer = new byte[1024];
        int count;
        while ((count = in.read(buffer)) >= 0) {
          checksum.update(buffer, 0, count);
        }
        in.close();
        crc = checksum.getValue();
      }
      finally {
        IOUtils.closeQuietly(in);
      }
    }
  }
  return crc;
}
项目:openjdk-jdk10    文件:ZeroDate.java   
private static void testDate(byte[] data, int date, LocalDate expected) throws IOException {
    // set the datetime
    int endpos = data.length - ENDHDR;
    int cenpos = u16(data, endpos + ENDOFF);
    int locpos = u16(data, cenpos + CENOFF);
    writeU32(data, cenpos + CENTIM, date);
    writeU32(data, locpos + LOCTIM, date);

    // ensure that the archive is still readable, and the date is 1979-11-30
    Path path = Files.createTempFile("out", ".zip");
    try (OutputStream os = Files.newOutputStream(path)) {
        os.write(data);
    }
    try (ZipFile zf = new ZipFile(path.toFile())) {
        ZipEntry ze = zf.entries().nextElement();
        Instant actualInstant = ze.getLastModifiedTime().toInstant();
        Instant expectedInstant =
                expected.atStartOfDay().atZone(ZoneId.systemDefault()).toInstant();
        if (!actualInstant.equals(expectedInstant)) {
            throw new AssertionError(
                    String.format("actual: %s, expected: %s", actualInstant, expectedInstant));
        }
    } finally {
        Files.delete(path);
    }
}
项目:starcor.xul    文件:XulPluginManager.java   
public boolean init(File path) {
    _path = path;

    try {
        File parentFile = path.getParentFile();
        _classLoader = new DexClassLoader(_path.getAbsolutePath(), parentFile.getAbsolutePath(), null, getClass().getClassLoader());

        _pluginPackage = new ZipFile(_path);
        ZipEntry entry = _pluginPackage.getEntry("plugin.txt");
        BufferedReader reader = new BufferedReader(new InputStreamReader(_pluginPackage.getInputStream(entry)));
        String pluginClassName = reader.readLine();
        reader.close();

        Class<?> pluginClass = _classLoader.loadClass(pluginClassName);
        _plugin = (XulPlugin) pluginClass.newInstance();
        return true;
    } catch (Throwable e) {
        e.printStackTrace();
    }
    return false;
}
项目:Backmemed    文件:ShaderPackZip.java   
public InputStream getResourceAsStream(String resName)
{
    try
    {
        if (this.packZipFile == null)
        {
            this.packZipFile = new ZipFile(this.packFile);
        }

        String s = StrUtils.removePrefix(resName, "/");
        ZipEntry zipentry = this.packZipFile.getEntry(s);
        return zipentry == null ? null : this.packZipFile.getInputStream(zipentry);
    }
    catch (Exception var4)
    {
        return null;
    }
}
项目:Tengine    文件:GameLoader.java   
/**
 * Load zip entries from package to HashMap and check if meta-file is present
 * @param path path to package
 * @throws Exception thrown when meta-file is not present in package
 */
private static void loadAndValidate(String path) throws Exception {
    boolean found = false;
    zip = new ZipFile(path);
    Enumeration<? extends ZipEntry> entries = zip.entries();

    while (entries.hasMoreElements()) {
        ZipEntry entry = entries.nextElement();

        if (entry.getName().equals("meta-file") && !entry.isDirectory()) {
            found = true;
        }

        GameLoader.entries.put(entry.getName(), entry);
    }

    if (!found) {
        throw new Exception(String.format("'%s' is not valid game!", path));
    }
}
项目:ios-device-control    文件:SimulatorDeviceImpl.java   
private void unzipFile(Path zipPath, Path targetDirectory) throws IOException {
  try (ZipFile zipFile = new ZipFile(zipPath.toFile())) {
    for (Enumeration<? extends ZipEntry> entries = zipFile.entries();
        entries.hasMoreElements(); ) {
      ZipEntry entry = entries.nextElement();
      Path targetFile = targetDirectory.resolve(entry.getName());
      if (entry.isDirectory()) {
        Files.createDirectories(targetFile);
      } else {
        Files.createDirectories(targetFile.getParent());
        try (InputStream in = zipFile.getInputStream(entry)) {
          Files.copy(in, targetFile);
        }
      }
    }
  }
}
项目:school-website    文件:OperateFileUtils.java   
public static boolean uncompress(String zipFilePath, String descDir) throws IOException {
    //如果指定路径的压缩文件不存在,会抛出 IO EXCEPTION
    ZipFile zipFile = new ZipFile(zipFilePath);
    File pathFile = new File(descDir);
    if(!pathFile.exists()){
        pathFile.mkdirs();
    }
    Enumeration<? extends ZipEntry> zipEntries = zipFile.entries();
    while (zipEntries.hasMoreElements()) {
        ZipEntry zipEntry = zipEntries.nextElement();
        OutputStream outputStream = new FileOutputStream("D:/testZip/lala" + "/" + new File(zipEntry.getName()));
        InputStream inputStream = zipFile.getInputStream(zipEntry);
        int len = inputStream.read();
        while (len != -1) {
            outputStream.write(len);
            len = inputStream.read();
        }
        inputStream.close();
        outputStream.close();
    }
    return true;
}
项目:atlas    文件:Dex.java   
/**
 * Creates a new dex buffer from the dex file {@code file}.
 */
public Dex(File file) throws IOException {
    if (FileUtils.hasArchiveSuffix(file.getName())) {
        ZipFile zipFile = new ZipFile(file);
        ZipEntry entry = zipFile.getEntry(DexFormat.DEX_IN_JAR_NAME);
        if (entry != null) {
            loadFrom(zipFile.getInputStream(entry));
            zipFile.close();
        } else {
            throw new DexException("Expected " + DexFormat.DEX_IN_JAR_NAME + " in " + file);
        }
    } else if (file.getName().endsWith(".dex")) {
        loadFrom(new FileInputStream(file));
    } else {
        throw new DexException("unknown output extension: " + file);
    }
}
项目:incubator-netbeans    文件:RepositoryUpdater.java   
private boolean unpack (@NonNull final File packedFile, @NonNull File targetFolder) throws IOException {
    final ZipFile zf = new ZipFile(packedFile);
    final Enumeration<? extends ZipEntry> entries = zf.entries();
    try {
        while (entries.hasMoreElements()) {
            final ZipEntry entry = entries.nextElement();
            final File target = new File (targetFolder,entry.getName().replace('/', File.separatorChar));   //NOI18N
            if (entry.isDirectory()) {
                target.mkdirs();
            } else {
                //Some zip files don't have zip entries for folders
                target.getParentFile().mkdirs();
                try (final InputStream in = zf.getInputStream(entry);
                    final FileOutputStream out = new FileOutputStream(target)) {
                        FileUtil.copy(in, out);
                }
            }
        }
    } finally {
        zf.close();
    }
    return true;
}
项目:openjdk-jdk10    文件:MultiThreadedReadTest.java   
public static void main(String args[]) throws Exception {
    createZipFile();
    try (ZipFile zf = new ZipFile(new File(ZIPFILE_NAME))) {
        is = zf.getInputStream(zf.getEntry(ZIPENTRY_NAME));
        Thread[] threadArray = new Thread[NUM_THREADS];
        for (int i = 0; i < threadArray.length; i++) {
            threadArray[i] = new MultiThreadedReadTest();
        }
        for (int i = 0; i < threadArray.length; i++) {
            threadArray[i].start();
        }
        for (int i = 0; i < threadArray.length; i++) {
            threadArray[i].join();
        }
    } finally {
        FileUtils.deleteFileIfExistsWithRetry(Paths.get(ZIPFILE_NAME));
    }
}
项目:Equella    文件:IMSUtilities.java   
private ZipManifestResolver(ZipFile zip, String file)
{
    this.zip = zip;

    int i = file.lastIndexOf('/');
    if( i < 0 )
    {
        i = file.lastIndexOf('\\');
    }

    if( i < 0 )
    {
        this.base = "";
        this.file = file;
    }
    else
    {
        this.base = file.substring(0, i + 1);
        this.file = file.substring(i + 1);
    }
}
项目:jmt    文件:SessionLoader.java   
private StringMapping loadVarMapping(ZipFile zf, String varName) throws IOException {

        InputStream zis = zf.getInputStream(new ZipEntry(varName + "_Map" + JwatSession.BINext));
        //System.out.println("Entry " + varName+"_Map"+JwatSession.BINext);
        DataInputStream dis = new DataInputStream(zis);

        StringMapping map = new StringMapping();
        double val;
        String str;
        int numEl = dis.read();

        for (int i = 0; i < numEl; i++) {
            val = dis.readDouble();
            str = dis.readUTF();
            map.addNewMapping(val, str);
        }

        return map;
    }
项目:stupro_toscana_vorprojekt    文件:ArchiveHandler.java   
/**
 * gets the model.xml and transforms it the a one line string without whitespace between elements
 * @param modelFile model.xml
 * @param zipfile the archive file
 * @return the file as one line string
 */
private String transformXmlFileToString(ZipEntry modelFile, ZipFile zipfile) throws ArchiveException {
    StringBuilder builder = new StringBuilder();
    InputStream stream;
    try {
        stream = zipfile.getInputStream(modelFile);
        BufferedReader reader = new BufferedReader(new InputStreamReader(stream));
        String line;

        while( (line = reader.readLine()) != null )
        {
            line = line.trim();
            builder.append(line);
        }
    } catch (IOException e) {
        throw new ArchiveException("Transforming the XML to a single line string failed.");
    }
    return builder.toString();
}
项目:atlas    文件:TPatchTool.java   
private ZipFile newZipFile(File file) {
    try {
        return new ZipFile(file);
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}
项目:FSTestTools    文件:ZipImportCommandsTest.java   
@Theory
public void testCommand(ZipImportCommands command) throws Exception {
    final ZipImportResult result = command.execute(parameters);

    assertThat("ZipImportResult should never be null", result, is(ZipImportResult.VOID));

    verify(formatTemplates, atMost(1)).importStoreElement(any(ZipFile.class), any(ModuleImportHandler.class));
    verify(pageTemplates, atMost(1)).importStoreElement(any(ZipFile.class), any(ModuleImportHandler.class));
    verify(linkTemplates, atMost(1)).importStoreElement(any(ZipFile.class), any(ModuleImportHandler.class));
    verify(workflows, atMost(1)).importStoreElement(any(ZipFile.class), any(ModuleImportHandler.class));
    verify(mediaStore, atMost(1)).importStoreElement(any(ZipFile.class), any(ModuleImportHandler.class));
    verify(scriptes, atMost(1)).importStoreElement(any(ZipFile.class), any(ModuleImportHandler.class));
}
项目:digdes-2017-file-finder    文件:BasicZipCrawler.java   
private List<DetectedString> crawlZipEntry(ZipFile zipFile, ZipEntry zipEntry) throws IOException {
    if (!zipEntry.isDirectory()) {
        InputStream is = zipFile.getInputStream(zipEntry);
        String filename = zipEntry.getName();
        // TODO invent something better
        if (filename.endsWith(".xml")) {
            return (xmlCrawler.crawl(is)
                    .stream()
                    .map(fileStageBuilder -> fileStageBuilder.inZip(zipFile, filename))
                    .collect(Collectors.toList()));
        }
    }
    return Collections.emptyList();
}
项目:boohee_v5.6    文件:DexDiffPatchInternal.java   
private static boolean extractDexFile(ZipFile zipFile, ZipEntry entryFile, File extractTo,
                                      ShareDexDiffPatchInfo dexInfo) throws IOException {
    String fileMd5 = ShareTinkerInternals.isVmArt() ? dexInfo.destMd5InArt : dexInfo
            .destMd5InDvm;
    String rawName = dexInfo.rawName;
    boolean isJarMode = dexInfo.isJarMode;
    if (SharePatchFileUtil.isRawDexFile(rawName) && isJarMode) {
        return extractDexToJar(zipFile, entryFile, extractTo, fileMd5);
    }
    return BasePatchInternal.extract(zipFile, entryFile, extractTo, fileMd5, true);
}
项目:DecompiledMinecraft    文件:FileResourcePack.java   
protected InputStream getInputStreamByName(String name) throws IOException
{
    ZipFile zipfile = this.getResourcePackZipFile();
    ZipEntry zipentry = zipfile.getEntry(name);

    if (zipentry == null)
    {
        throw new ResourcePackFileNotFoundException(this.resourcePackFile, name);
    }
    else
    {
        return zipfile.getInputStream(zipentry);
    }
}
项目:letv    文件:ZipUtils.java   
public static ArrayList<File> upZipSelectedFile(File zipFile, String folderPath, String nameContains) throws ZipException, IOException {
    ArrayList<File> fileList = new ArrayList();
    File desDir = new File(folderPath);
    if (!desDir.exists()) {
        desDir.mkdir();
    }
    ZipFile zf = new ZipFile(zipFile);
    Enumeration<?> entries = zf.entries();
    while (entries.hasMoreElements()) {
        ZipEntry entry = (ZipEntry) entries.nextElement();
        if (entry.getName().contains(nameContains)) {
            InputStream in = zf.getInputStream(entry);
            File desFile = new File(new String(new StringBuilder(String.valueOf(folderPath)).append(File.separator).append(entry.getName()).toString().getBytes("8859_1"), "GB2312"));
            if (!desFile.exists()) {
                File fileParentDir = desFile.getParentFile();
                if (!fileParentDir.exists()) {
                    fileParentDir.mkdirs();
                }
                desFile.createNewFile();
            }
            OutputStream out = new FileOutputStream(desFile);
            byte[] buffer = new byte[1048576];
            while (true) {
                int realLength = in.read(buffer);
                if (realLength <= 0) {
                    break;
                }
                out.write(buffer, 0, realLength);
            }
            in.close();
            out.close();
            fileList.add(desFile);
        }
    }
    return fileList;
}
项目:DecompiledMinecraft    文件:FileResourcePack.java   
private ZipFile getResourcePackZipFile() throws IOException
{
    if (this.resourcePackZipFile == null)
    {
        this.resourcePackZipFile = new ZipFile(this.resourcePackFile);
    }

    return this.resourcePackZipFile;
}
项目:sig-seguimiento-vehiculos    文件:FileUploadZipServlet.java   
private String readZipFile(ZipFile zipFile) {
    String content = EMPTY;

    try {

        Enumeration<?> enu = zipFile.entries();
        if (enu.hasMoreElements()) {
            ZipEntry zipEntry = (ZipEntry) enu.nextElement();
            if (zipEntry.isDirectory()) {
                content = BAD_FORMAT;
            } else if (!(zipEntry.getName().equals(PRJ_FILE_NAME))) {
                content = BAD_FORMAT;
            } else {
                InputStream is = zipFile.getInputStream(zipEntry);
                content = new java.util.Scanner(is).useDelimiter("\\A")
                        .next();
            }

            // String name = zipEntry.getName();
            // long size = zipEntry.getSize();
            // long compressedSize = zipEntry.getCompressedSize();
            // LOG.info("name: " + name + " | size: " + size
            // + " | compressed size: " + compressedSize);

        }
        zipFile.close();

    } catch (IOException e) {
        LOG.error("Se produce error en ZipFile: " + e.getMessage());
        e.printStackTrace();
    }

    return content;
}
项目:ChronoBike    文件:JarItemEntry.java   
public byte[] loadBytes(ZipFile zipFile)
{
    try
    {
        InputStream inputStream = zipFile.getInputStream(m_zipEntry);
        if(inputStream != null)
        {
            int nSize= (int) m_zipEntry.getSize();  // -1 means unknown size.
            if (nSize != -1)
            {
                byte[] tb = new byte[nSize];
                int rb = 0;
                int nChunk = 0;
                while ((nSize - rb) > 0)
                {
                    nChunk = inputStream.read(tb, rb, nSize - rb);
                    if (nChunk == -1)
                    {
                        break;
                    }
                    rb += nChunk;
                }
                return tb;
            }
            inputStream.close();
        }
    }
    catch (IOException e)
    {
    }
    return null;
}
项目:FireFiles    文件:IoUtils.java   
/**
 * Closes 'zipfile', ignoring any checked exceptions. Does nothing if 'closeable' is null.
 */
public static void closeQuietly(ZipFile closeable) {
    if (closeable != null) {
        try {
            closeable.close();
        } catch (RuntimeException rethrown) {
            throw rethrown;
        } catch (Exception ignored) {
        }
    }
}
项目:GitHub    文件:ZipUtils.java   
/**
 * 获取压缩文件中的注释链表
 *
 * @param zipFile 压缩文件
 * @return 压缩文件中的注释链表
 * @throws IOException IO错误时抛出
 */
public static List<String> getComments(final File zipFile)
        throws IOException {
    if (zipFile == null) return null;
    List<String> comments = new ArrayList<>();
    Enumeration<?> entries = new ZipFile(zipFile).entries();
    while (entries.hasMoreElements()) {
        ZipEntry entry = ((ZipEntry) entries.nextElement());
        comments.add(entry.getComment());
    }
    return comments;
}
项目:L2jBrasil    文件:ScriptPackage.java   
public ScriptPackage(ZipFile pack)
{
    _scriptFiles = new ArrayList<>();
    _otherFiles = new ArrayList<>();
    _name = pack.getName();
    addFiles(pack);
}
项目:L2jBrasil    文件:JarClassLoader.java   
private byte[] loadClassData(String name) throws IOException
{
    byte[] classData = null;

    for(String jarFile : _jars)
    {
        try
        {
            File file = new File(jarFile);
            ZipFile zipFile = new ZipFile(file);
            String fileName = name.replace('.', '/') + ".class";
            ZipEntry entry = zipFile.getEntry(fileName);

            if(entry == null)
            {
                continue;
            }

            classData = new byte[(int) entry.getSize()];
            DataInputStream zipStream = new DataInputStream(zipFile.getInputStream(entry));
            zipStream.readFully(classData, 0, (int) entry.getSize());
            break;
        }
        catch(IOException e)
        {
            _log.log(Level.WARNING, jarFile + ":" + e.toString(), e);
            continue;
        }
    }
    if(classData == null)
        throw new IOException("class not found in " + _jars);
    return classData;
}
项目:neoscada    文件:OscarLoader.java   
public OscarLoader ( final File file ) throws Exception
{
    final ZipFile zfile = new ZipFile ( file );
    try
    {
        this.data = loadData ( zfile );
        this.ignoreFields = loadIgnoreData ( zfile );
    }
    finally
    {
        zfile.close ();
    }
}
项目:CoreX    文件:ZippedResourcePack.java   
public ZippedResourcePack(File file) {
    if (!file.exists()) {
        throw new IllegalArgumentException(Server.getInstance().getLanguage()
                .translateString("nukkit.resources.zip.not-found", file.getName()));
    }

    this.file = file;

    try (ZipFile zip = new ZipFile(file)) {
        ZipEntry entry = zip.getEntry("manifest.json");
        if (entry == null) {
            throw new IllegalArgumentException(Server.getInstance().getLanguage()
                    .translateString("nukkit.resources.zip.no-manifest"));
        } else {
            this.manifest = new JsonParser()
                    .parse(new InputStreamReader(zip.getInputStream(entry), StandardCharsets.UTF_8))
                    .getAsJsonObject();
        }
    } catch (IOException e) {
        Server.getInstance().getLogger().logException(e);
    }

    if (!this.verifyManifest()) {
        throw new IllegalArgumentException(Server.getInstance().getLanguage()
                .translateString("nukkit.resources.zip.invalid-manifest"));
    }
}
项目:CloudNet    文件:PacketInCreateTemplate.java   
private void extractEntry(ZipFile zipFile, ZipEntry entry, String destDir)
        throws IOException
{
    File file = new File(destDir, entry.getName());
    final byte[] BUFFER = new byte[0xFFFF];

    if (entry.isDirectory())
        file.mkdirs();
    else
    {
        new File(file.getParent()).mkdirs();

        InputStream is = null;
        OutputStream os = null;

        try
        {
            is = zipFile.getInputStream(entry);
            os = new FileOutputStream(file);

            int len;
            while ((len = is.read(BUFFER)) != -1)
                os.write(BUFFER, 0, len);
        } finally
        {
            if (os != null) os.close();
            if (is != null) is.close();
        }
    }
}
项目:CloudNet    文件:CloudGameServer.java   
private void extractEntry(ZipFile zipFile, ZipEntry entry, String destDir)
        throws IOException
{
    File file = new File(destDir, entry.getName());
    final byte[] BUFFER = new byte[0xFFFF];

    if (entry.isDirectory())
        file.mkdirs();
    else
    {
        new File(file.getParent()).mkdirs();

        InputStream is = null;
        OutputStream os = null;

        try
        {
            is = zipFile.getInputStream(entry);
            os = new FileOutputStream(file);

            int len;
            while ((len = is.read(BUFFER)) != -1)
                os.write(BUFFER, 0, len);
        } finally
        {
            if (os != null) os.close();
            if (is != null) is.close();
        }
    }
}
项目:Recaf    文件:Asm.java   
/**
 * Reads the classes of the given jar into a map.
 *
 * @param jarPath
 *            Path to jarfile to read classes from.
 * @return Map of classes from the given jarfile.
 * @throws IOException
 *             If an exception was encountered while reading the jarfile.
 */
public static Map<String, ClassNode> readClasses(String jarPath) throws IOException {
    Map<String, ClassNode> map = new HashMap<>();
    try (ZipFile file = new ZipFile(jarPath)) {
        Enumeration<? extends ZipEntry> entries = file.entries();
        while (entries.hasMoreElements()) {
            ZipEntry entry = entries.nextElement();
            if (entry.isDirectory() || !entry.getName().endsWith(".class")) {
                continue;
            }
            String name = null;
            Recaf.INSTANCE.logging.fine("Reading jar class: " + entry.getName(), 1);
            try (InputStream is = file.getInputStream(entry)) {
                ClassReader cr = new ClassReader(is);
                name = cr.getClassName();
                map.put(cr.getClassName(), getNode(cr));
            } catch (IndexOutOfBoundsException ioobe) {
                if (name == null) {
                    Recaf.INSTANCE.logging.error(new RuntimeException("Failed reading class from: " + entry.getName(),
                            ioobe));
                } else {
                    Recaf.INSTANCE.logging.error(new RuntimeException("Failed reading into node structure: " + name, ioobe));
                }
            }
        }
    }
    return map;
}
项目:multidexlib2    文件:ZipFileDexContainer.java   
public static boolean isZipFile(File zip) {
    if (!zip.isFile()) return false;
    try {
        ZipFile zipFile = new ZipFile(zip);
        zipFile.close();
        return true;
    } catch (IOException e) {
        return false;
    }
}