当前位置: 首页>>代码示例>>Java>>正文


Java ZipEntry.setSize方法代码示例

本文整理汇总了Java中java.util.zip.ZipEntry.setSize方法的典型用法代码示例。如果您正苦于以下问题:Java ZipEntry.setSize方法的具体用法?Java ZipEntry.setSize怎么用?Java ZipEntry.setSize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.zip.ZipEntry的用法示例。


在下文中一共展示了ZipEntry.setSize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: zipEntries

import java.util.zip.ZipEntry; //导入方法依赖的package包/类
private ByteArrayOutputStream zipEntries(List<Pair<String, byte[]>> entryList) throws IOException {
    ByteArrayOutputStream buffer = new ByteArrayOutputStream(8192);
    try (ZipOutputStream jar = new ZipOutputStream(buffer)) {
        jar.setMethod(ZipOutputStream.STORED);
        final CRC32 crc = new CRC32();
        for (Pair<String, byte[]> entry : entryList) {
            byte[] bytes = entry.second;
            final ZipEntry newEntry = new ZipEntry(entry.first);
            newEntry.setMethod(ZipEntry.STORED); // chose STORED method
            crc.reset();
            crc.update(entry.second);
            newEntry.setCrc(crc.getValue());
            newEntry.setSize(bytes.length);
            writeEntryToJar(newEntry, bytes, jar);
        }
        jar.flush();
    }
    return buffer;
}
 
开发者ID:yrom,项目名称:shrinker,代码行数:20,代码来源:JarProcessor.java

示例2: writeToZip

import java.util.zip.ZipEntry; //导入方法依赖的package包/类
/**
 * Write the dex program resources to @code{archive} and the proguard resource as its sibling.
 */
public void writeToZip(Path archive, OutputMode outputMode) throws IOException {
  OpenOption[] options =
      new OpenOption[] {StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING};
  try (Closer closer = Closer.create()) {
    try (ZipOutputStream out = new ZipOutputStream(Files.newOutputStream(archive, options))) {
      List<Resource> dexProgramSources = getDexProgramResources();
      for (int i = 0; i < dexProgramSources.size(); i++) {
        ZipEntry zipEntry = new ZipEntry(outputMode.getOutputPath(dexProgramSources.get(i), i));
        byte[] bytes =
            ByteStreams.toByteArray(closer.register(dexProgramSources.get(i).getStream()));
        zipEntry.setSize(bytes.length);
        out.putNextEntry(zipEntry);
        out.write(bytes);
        out.closeEntry();
      }
    }
  }
}
 
开发者ID:inferjay,项目名称:r8,代码行数:22,代码来源:AndroidApp.java

示例3: getCompressedData

import java.util.zip.ZipEntry; //导入方法依赖的package包/类
@Override
protected byte[] getCompressedData() throws IOException {
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    try (ZipOutputStream os = new ZipOutputStream(bos)) {

        ZipEntry entry1 = new ZipEntry("data.xiidm");
        byte[] data = getUncompressedData();
        entry1.setSize(data.length);
        os.putNextEntry(entry1);
        os.write(data);
        os.closeEntry();

        ZipEntry entry2 = new ZipEntry("extra_data.xiidm");
        byte[] extraData = getExtraUncompressedData();
        entry2.setSize(extraData.length);
        os.putNextEntry(entry2);
        os.write(extraData);
        os.closeEntry();
    }

    return bos.toByteArray();
}
 
开发者ID:powsybl,项目名称:powsybl-core,代码行数:23,代码来源:ZipMemDataSourceTest.java

示例4: main

import java.util.zip.ZipEntry; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
    URLConnection conn = B7050028.class.getResource("B7050028.class").openConnection();
    int len = conn.getContentLength();
    byte[] data = new byte[len];
    InputStream is = conn.getInputStream();
    is.read(data);
    is.close();
    conn.setDefaultUseCaches(false);
    File jar = File.createTempFile("B7050028", ".jar");
    jar.deleteOnExit();
    OutputStream os = new FileOutputStream(jar);
    ZipOutputStream zos = new ZipOutputStream(os);
    ZipEntry ze = new ZipEntry("B7050028.class");
    ze.setMethod(ZipEntry.STORED);
    ze.setSize(len);
    CRC32 crc = new CRC32();
    crc.update(data);
    ze.setCrc(crc.getValue());
    zos.putNextEntry(ze);
    zos.write(data, 0, len);
    zos.closeEntry();
    zos.finish();
    zos.close();
    os.close();
    System.out.println(new URLClassLoader(new URL[] {new URL("jar:" + jar.toURI() + "!/")}, ClassLoader.getSystemClassLoader().getParent()).loadClass(B7050028.class.getName()));
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:27,代码来源:B7050028.java

示例5: writeEntry

import java.util.zip.ZipEntry; //导入方法依赖的package包/类
private void writeEntry(ZipFile zf, ZipOutputStream os, ZipEntry ze)
        throws IOException {
    ZipEntry ze2 = new ZipEntry(ze.getName());
    ze2.setMethod(ze.getMethod());
    ze2.setTime(ze.getTime());
    ze2.setComment(ze.getComment());
    ze2.setExtra(ze.getExtra());
    if (ze.getMethod() == ZipEntry.STORED) {
        ze2.setSize(ze.getSize());
        ze2.setCrc(ze.getCrc());
    }
    os.putNextEntry(ze2);
    writeBytes(zf, ze, os);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:15,代码来源:JarSigner.java

示例6: writeEntry

import java.util.zip.ZipEntry; //导入方法依赖的package包/类
private static void writeEntry(String name, Set<String> written, ZipOutputStream zos, File f) throws IOException, FileNotFoundException {
    if (!written.add(name)) {
        return;
    }
    int idx = name.lastIndexOf('/', name.length() - 2);
    if (idx != -1) {
        writeEntry(name.substring(0, idx + 1), written, zos, f.getParentFile());
    }
    ZipEntry ze = new ZipEntry(name);
    ze.setTime(f.lastModified());
    if (name.endsWith("/")) {
        ze.setMethod(ZipEntry.STORED);
        ze.setSize(0);
        ze.setCrc(0);
        zos.putNextEntry(ze);
    } else {
        InputStream is = new FileInputStream(f);
        ze.setMethod(ZipEntry.DEFLATED);
        ze.setSize(f.length());
        CRC32 crc = new CRC32();
        try {
            copyStreams(is, null, crc);
        } finally {
            is.close();
        }
        ze.setCrc(crc.getValue());
        zos.putNextEntry(ze);
        InputStream zis = new FileInputStream(f);
        try {
            copyStreams(zis, zos, null);
        } finally {
            zis.close();
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:36,代码来源:ExportZIP.java

示例7: writeZipFileEntry

import java.util.zip.ZipEntry; //导入方法依赖的package包/类
private static void writeZipFileEntry(ZipOutputStream zos, String zipEntryName, byte[] byteArray) throws IOException {
    int byteArraySize = byteArray.length;

    CRC32 crc = new CRC32();
    crc.update(byteArray, 0, byteArraySize);

    ZipEntry entry = new ZipEntry(zipEntryName);
    entry.setMethod(ZipEntry.STORED);
    entry.setSize(byteArraySize);
    entry.setCrc(crc.getValue());

    zos.putNextEntry(entry);
    zos.write(byteArray, 0, byteArraySize);
    zos.closeEntry();
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:16,代码来源:ProjectLibraryProviderTest.java

示例8: addEntry

import java.util.zip.ZipEntry; //导入方法依赖的package包/类
private static void addEntry(String name, InputStream in, ZipOutputStream out)
    throws IOException {
  ZipEntry zipEntry = new ZipEntry(name);
  byte[] bytes = ByteStreams.toByteArray(in);
  zipEntry.setSize(bytes.length);
  out.putNextEntry(zipEntry);
  out.write(bytes);
  out.closeEntry();
}
 
开发者ID:inferjay,项目名称:r8,代码行数:10,代码来源:CompatDx.java

示例9: testUnZip

import java.util.zip.ZipEntry; //导入方法依赖的package包/类
@Test (timeout = 30000)
public void testUnZip() throws IOException {
  // make sa simple zip
  setupDirs();
  
  // make a simple tar:
  final File simpleZip = new File(del, FILE);
  OutputStream os = new FileOutputStream(simpleZip); 
  ZipOutputStream tos = new ZipOutputStream(os);
  try {
    ZipEntry ze = new ZipEntry("foo");
    byte[] data = "some-content".getBytes("UTF-8");
    ze.setSize(data.length);
    tos.putNextEntry(ze);
    tos.write(data);
    tos.closeEntry();
    tos.flush();
    tos.finish();
  } finally {
    tos.close();
  }
  
  // successfully untar it into an existing dir:
  FileUtil.unZip(simpleZip, tmp);
  // check result:
  assertTrue(new File(tmp, "foo").exists());
  assertEquals(12, new File(tmp, "foo").length());
  
  final File regularFile = new File(tmp, "QuickBrownFoxJumpsOverTheLazyDog");
  regularFile.createNewFile();
  assertTrue(regularFile.exists());
  try {
    FileUtil.unZip(simpleZip, regularFile);
    assertTrue("An IOException expected.", false);
  } catch (IOException ioe) {
    // okay
  }
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:39,代码来源:TestFileUtil.java

示例10: compressFile

import java.util.zip.ZipEntry; //导入方法依赖的package包/类
public static boolean compressFile(File toCompress, File target) {
    if (target == null || toCompress == null) {
        return false;
    }
    try {
        final Uri uri = Uri.fromFile(toCompress);
        final String rootPath = Utils.getParentUrl(uri.toString());
        final int rootOffset = rootPath.length();

        ZipOutputStream zos = new ZipOutputStream(FileEditorFactory.getFileEditorForUrl(Uri.fromFile(target), null).getOutputStream());
        ZipEntry entry = new ZipEntry(uri.toString().substring(rootOffset));
        byte[] bytes = new byte[1024];
        InputStream fis = FileEditorFactory.getFileEditorForUrl(uri, null).getInputStream();
        entry.setSize(toCompress.length());
        entry.setTime(toCompress.lastModified());
        zos.putNextEntry(entry);
        int count;
        while ((count = fis.read(bytes)) > 0) {
            zos.write(bytes, 0, count);
        }
        zos.closeEntry();
        closeSilently(fis);
        closeSilently(zos);
        return true;
    }
    catch (Exception e) {
        e.printStackTrace();
        return false;
    }
}
 
开发者ID:archos-sa,项目名称:aos-FileCoreLibrary,代码行数:31,代码来源:ZipUtils.java

示例11: writeEntry

import java.util.zip.ZipEntry; //导入方法依赖的package包/类
private long writeEntry(InputStream zis, ZipOutputStream output, ZipEntry newEntry) throws IOException {
  // FIXME: is there a better way to do this, so that the whole input
  // stream isn't in memory at once?
  final byte[] contents = IOUtils.toByteArray(zis);
  final CRC32 checksum = new CRC32();
  checksum.update(contents);
  if (newEntry.getMethod() == ZipEntry.STORED) {
    newEntry.setSize(contents.length);
    newEntry.setCrc(checksum.getValue());
  }
  output.putNextEntry(newEntry);
  output.write(contents, 0, contents.length);
  return checksum.getValue();
}
 
开发者ID:ajmath,项目名称:VASSAL-src,代码行数:15,代码来源:ZipUpdater.java

示例12: copyUnknownFiles

import java.util.zip.ZipEntry; //导入方法依赖的package包/类
private void copyUnknownFiles(File appDir, ZipOutputStream outputFile, Map<String, String> files)
        throws IOException {
    File unknownFileDir = new File(appDir, UNK_DIRNAME);

    // loop through unknown files
    for (Map.Entry<String,String> unknownFileInfo : files.entrySet()) {
        File inputFile = new File(unknownFileDir, unknownFileInfo.getKey());
        if (inputFile.isDirectory()) {
            continue;
        }

        ZipEntry newEntry = new ZipEntry(unknownFileInfo.getKey());
        int method = Integer.parseInt(unknownFileInfo.getValue());
        LOGGER.fine(String.format("Copying unknown file %s with method %d", unknownFileInfo.getKey(), method));
        if (method == ZipEntry.STORED) {
            newEntry.setMethod(ZipEntry.STORED);
            newEntry.setSize(inputFile.length());
            newEntry.setCompressedSize(-1);
            BufferedInputStream unknownFile = new BufferedInputStream(new FileInputStream(inputFile));
            CRC32 crc = BrutIO.calculateCrc(unknownFile);
            newEntry.setCrc(crc.getValue());
        } else {
            newEntry.setMethod(ZipEntry.DEFLATED);
        }
        outputFile.putNextEntry(newEntry);

        BrutIO.copy(inputFile, outputFile);
        outputFile.closeEntry();
    }
}
 
开发者ID:imkiva,项目名称:AndroidApktool,代码行数:31,代码来源:Androlib.java

示例13: addEntry

import java.util.zip.ZipEntry; //导入方法依赖的package包/类
public static void addEntry(ZipOutputStream os, String path, byte[] content) throws IOException {
    ZipEntry entry = new ZipEntry(path);
    entry.setSize(content.length);
    os.putNextEntry(entry);
    os.write(content);
    os.closeEntry();
}
 
开发者ID:syndesisio,项目名称:syndesis,代码行数:8,代码来源:IntegrationHandler.java

示例14: zipFolder

import java.util.zip.ZipEntry; //导入方法依赖的package包/类
/**
 * Zip a given folder
 * 
 * @param dirPath
 *            a given folder: must be all files (not sub-folders)
 * @param filePath
 *            zipped file
 * @throws Exception
 */
public static void zipFolder(String dirPath, String filePath) throws Exception {
	File outFile = new File(filePath);
	ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(outFile));
	int bytesRead;
	byte[] buffer = new byte[1024];
	CRC32 crc = new CRC32();
	for (File file : listFiles(dirPath)) {
		BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file));
		crc.reset();
		while ((bytesRead = bis.read(buffer)) != -1) {
			crc.update(buffer, 0, bytesRead);
		}
		bis.close();

		// Reset to beginning of input stream
		bis = new BufferedInputStream(new FileInputStream(file));
		ZipEntry entry = new ZipEntry(file.getName());
		entry.setMethod(ZipEntry.STORED);
		entry.setCompressedSize(file.length());
		entry.setSize(file.length());
		entry.setCrc(crc.getValue());
		zos.putNextEntry(entry);
		while ((bytesRead = bis.read(buffer)) != -1) {
			zos.write(buffer, 0, bytesRead);
		}
		bis.close();
	}
	zos.close();

	Logs.debug("A zip-file is created to: {}", outFile.getPath());
}
 
开发者ID:xiaojieliu7,项目名称:MicroServiceProject,代码行数:41,代码来源:FileIO.java

示例15: getEntry

import java.util.zip.ZipEntry; //导入方法依赖的package包/类
@Override
public ZipEntry getEntry() {
	ZipEntry zipEntry = new ZipEntry(path);
	if (!file.isDirectory()) {
		zipEntry.setSize(file.length());
	}
	zipEntry.setTime(0L);

	return zipEntry;
}
 
开发者ID:Azzurite,项目名称:MinecraftServerSync,代码行数:11,代码来源:OnlyContentZipEntrySource.java


注:本文中的java.util.zip.ZipEntry.setSize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。