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


Java ZipEntry.setMethod方法代码示例

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


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

示例3: 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

示例4: 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

示例5: 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

示例6: getOutputStream

import java.util.zip.ZipEntry; //导入方法依赖的package包/类
/**
 * Gets an {@link OutputStream} to write to the given file.
 *
 * <b>Note:</b> It is imperative the that calling code ensures that this
 * stream is eventually closed, since the returned stream holds a write
 * lock on the archive.
 *
 * @param path the path to the file in the archive
 * @param compress whether to compress the file
 * @return an <code>OutputStream</code> for the requested file
 * @throws IOException
 */
public OutputStream getOutputStream(String path, boolean compress)
                                                         throws IOException {
  w.lock();
  try {
    openIfClosed();

    modified = true;

    // set up new ZipEntry
    final ZipEntry ze = new ZipEntry(path);
    ze.setMethod(compress ? ZipEntry.DEFLATED : ZipEntry.STORED);

    // create new temp file
    final File tf = File.createTempFile("zip", ".tmp", Info.getTempDir());

    // set up new Entry
    final Entry e = new Entry(ze, tf);
    final Entry old = entries.put(path, e);

    // clean up old temp file
    if (old != null && old.file != null) {
      old.file.delete();
    }

    return new ZipArchiveOutputStream(
      new FileOutputStream(e.file), new CRC32(), e.ze
    );
  }
  catch (IOException ex) {
    w.unlock();
    throw ex;
  }
}
 
开发者ID:ajmath,项目名称:VASSAL-src,代码行数:46,代码来源:ZipArchive.java

示例7: 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

示例8: 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

示例9: writeZipFile

import java.util.zip.ZipEntry; //导入方法依赖的package包/类
private static void writeZipFile(String name, String comment)
    throws IOException
{
    try (FileOutputStream fos = new FileOutputStream(name);
         ZipOutputStream zos = new ZipOutputStream(fos))
    {
        zos.setComment(comment);
        ZipEntry ze = new ZipEntry(entryName);
        ze.setMethod(ZipEntry.DEFLATED);
        zos.putNextEntry(ze);
        new DataOutputStream(zos).writeUTF(entryContents);
        zos.closeEntry();
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:15,代码来源:Comment.java

示例10: writeEntry

import java.util.zip.ZipEntry; //导入方法依赖的package包/类
private void writeEntry(JarOutputStream j, String name,
                        long mtime, long lsize, boolean deflateHint,
                        ByteBuffer data0, ByteBuffer data1) throws IOException {
    int size = (int)lsize;
    if (size != lsize)
        throw new IOException("file too large: "+lsize);

    CRC32 crc32 = _crc32;

    if (_verbose > 1)
        Utils.log.fine("Writing entry: "+name+" size="+size
                         +(deflateHint?" deflated":""));

    if (_buf.length < size) {
        int newSize = size;
        while (newSize < _buf.length) {
            newSize <<= 1;
            if (newSize <= 0) {
                newSize = size;
                break;
            }
        }
        _buf = new byte[newSize];
    }
    assert(_buf.length >= size);

    int fillp = 0;
    if (data0 != null) {
        int size0 = data0.capacity();
        data0.get(_buf, fillp, size0);
        fillp += size0;
    }
    if (data1 != null) {
        int size1 = data1.capacity();
        data1.get(_buf, fillp, size1);
        fillp += size1;
    }
    while (fillp < size) {
        // Fill in rest of data from the stream itself.
        int nr = in.read(_buf, fillp, size - fillp);
        if (nr <= 0)  throw new IOException("EOF at end of archive");
        fillp += nr;
    }

    ZipEntry z = new ZipEntry(name);
    z.setTime(mtime * 1000);

    if (size == 0) {
        z.setMethod(ZipOutputStream.STORED);
        z.setSize(0);
        z.setCrc(0);
        z.setCompressedSize(0);
    } else if (!deflateHint) {
        z.setMethod(ZipOutputStream.STORED);
        z.setSize(size);
        z.setCompressedSize(size);
        crc32.reset();
        crc32.update(_buf, 0, size);
        z.setCrc(crc32.getValue());
    } else {
        z.setMethod(Deflater.DEFLATED);
        z.setSize(size);
    }

    j.putNextEntry(z);

    if (size > 0)
        j.write(_buf, 0, size);

    j.closeEntry();
    if (_verbose > 0) Utils.log.info("Writing " + Utils.zeString(z));
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:73,代码来源:NativeUnpack.java

示例11: readEntry

import java.util.zip.ZipEntry; //导入方法依赖的package包/类
static ZipEntry readEntry(ByteBuffer in) throws IOException {

        int sig = in.getInt();
        if (sig != CENSIG) {
             throw new ZipException("Central Directory Entry not found");
        }

        in.position(8);
        int gpbf = in.getShort() & 0xffff;

        if ((gpbf & GPBF_UNSUPPORTED_MASK) != 0) {
            throw new ZipException("Invalid General Purpose Bit Flag: " + gpbf);
        }

        int compressionMethod = in.getShort() & 0xffff;
        int time = in.getShort() & 0xffff;
        int modDate = in.getShort() & 0xffff;

        // These are 32-bit values in the file, but 64-bit fields in this object.
        long crc = ((long) in.getInt()) & 0xffffffffL;
        long compressedSize = ((long) in.getInt()) & 0xffffffffL;
        long size = ((long) in.getInt()) & 0xffffffffL;

        int nameLength = in.getShort() & 0xffff;
        int extraLength = in.getShort() & 0xffff;
        int commentByteCount = in.getShort() & 0xffff;

        // This is a 32-bit value in the file, but a 64-bit field in this object.
        in.position(42);
        long localHeaderRelOffset = ((long) in.getInt()) & 0xffffffffL;

        byte[] nameBytes = new byte[nameLength];
        in.get(nameBytes, 0, nameBytes.length);
        String name = new String(nameBytes, 0, nameBytes.length, UTF_8);

        ZipEntry entry = new ZipEntry(name);
        entry.setMethod(compressionMethod);
        entry.setTime(getTime(time, modDate));

        entry.setCrc(crc);
        entry.setCompressedSize(compressedSize);
        entry.setSize(size);

        // The RI has always assumed UTF-8. (If GPBF_UTF8_FLAG isn't set, the encoding is
        // actually IBM-437.)
        if (commentByteCount > 0) {
            byte[] commentBytes = new byte[commentByteCount];
            in.get(commentBytes, 0, commentByteCount);
            entry.setComment(new String(commentBytes, 0, commentBytes.length, UTF_8));
        }

        if (extraLength > 0) {
            byte[] extra = new byte[extraLength];
            in.get(extra, 0, extraLength);
            entry.setExtra(extra);
        }

        return entry;

    }
 
开发者ID:mit-cml,项目名称:appinventor-extensions,代码行数:61,代码来源:ZipEntryReader.java


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