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


Java ZipEntry.getSize方法代码示例

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


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

示例1: ZipFullEntry

import java.util.zip.ZipEntry; //导入方法依赖的package包/类
public ZipFullEntry(ZipInputStream stream, ZipEntry e, boolean isParentJarFile) {
    insideJar = isParentJarFile;
    entry = e;
    contentsGetter = () -> {
        try {
            long size = e.getSize();
            // Note: This will fail to properly read 2gb+ files, but we have other problems if that's in this JAR file.
            if (size <= 0) {
                return Optional.empty();
            }
            byte[] buffer = new byte[(int) size];
            stream.read(buffer);
            return Optional.of(new ByteInputStream(new byte[(int) e.getSize()], buffer.length));
        } catch (IOException ex) {
            Logger.getLogger(ZipFullEntry.class.getName()).log(Level.SEVERE, null, ex);
            return Optional.empty();
        }
    };
}
 
开发者ID:Adobe-Consulting-Services,项目名称:aem-epic-tool,代码行数:20,代码来源:ZipFullEntry.java

示例2: getDigests

import java.util.zip.ZipEntry; //导入方法依赖的package包/类
private String[] getDigests(
        ZipEntry ze, ZipFile zf, MessageDigest[] digests)
        throws IOException {

    int n, i;
    try (InputStream is = zf.getInputStream(ze)) {
        long left = ze.getSize();
        byte[] buffer = new byte[8192];
        while ((left > 0)
                && (n = is.read(buffer, 0, buffer.length)) != -1) {
            for (i = 0; i < digests.length; i++) {
                digests[i].update(buffer, 0, n);
            }
            left -= n;
        }
    }

    // complete the digests
    String[] base64Digests = new String[digests.length];
    for (i = 0; i < digests.length; i++) {
        base64Digests[i] = Base64.getEncoder()
                .encodeToString(digests[i].digest());
    }
    return base64Digests;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:26,代码来源:JarSigner.java

示例3: unpack

import java.util.zip.ZipEntry; //导入方法依赖的package包/类
private void unpack (String filename) throws IOException {
    File zipLarge = new File(getDataDir(), filename);
    ZipInputStream is = new ZipInputStream(new BufferedInputStream(new FileInputStream(zipLarge)));
    ZipEntry entry;
    while ((entry = is.getNextEntry()) != null) {
        File unpacked = new File(workDir, entry.getName());
        FileChannel channel = new FileOutputStream(unpacked).getChannel();
        byte[] bytes = new byte[2048];
        try {
            int len;
            long size = entry.getSize();
            while (size > 0 && (len = is.read(bytes, 0, 2048)) > 0) {
                ByteBuffer buffer = ByteBuffer.wrap(bytes, 0, len);
                int j = channel.write(buffer);
                size -= len;
            }
        } finally {
            channel.close();
        }
    }
    ZipEntry e = is.getNextEntry();
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:23,代码来源:CheckoutTest.java

示例4: loadClassData

import java.util.zip.ZipEntry; //导入方法依赖的package包/类
private byte[] loadClassData(String p_name) throws ClassNotFoundException {
    try {
        String  name = p_name.replace('.', '/') + ".class";
        ZipEntry entry = zip.getEntry(name);
        InputStream in = zip.getInputStream(entry);
        long size = entry.getSize();
        if (size == -1) {
            System.out.println("This file is broken");
            throw new ClassNotFoundException("Fuck");
        }
        
        try (DataInputStream dataIn = new DataInputStream(in)) {
            byte[] b = new byte[(int) size];
            dataIn.readFully(b);
            return b;
        }
    } catch (IOException ex) {
        throw new ClassNotFoundException("I hate shit.");
    }
}
 
开发者ID:addertheblack,项目名称:myster,代码行数:21,代码来源:JarClassLoader.java

示例5: unZipFile

import java.util.zip.ZipEntry; //导入方法依赖的package包/类
/**
 * Descompactar um arquivo zip.
 * @param zipFilePath informar o caminho completo do arquivo zip.
 * @param fileName se necessário informar o nome do arquivo que deve ser descompactado ou nulo para todos.
 * @param directory informar o diretório onde os arquivo serão descompactados.
 * @param iZipFile se necessário, informar uma {@link IZipFile}.
 * @throws IOException
 */
public static void unZipFile(String zipFilePath, String fileName, String directory, IZipFile iZipFile) throws IOException {
    FileInputStream streamZipFile = new FileInputStream(zipFilePath);
    ZipInputStream streamZips = new ZipInputStream(streamZipFile);
    try {
        ZipEntry zipEntry = null;
        while ((zipEntry = streamZips.getNextEntry()) != null) {
            long sizeZip = zipEntry.getSize();
            long sizeProcessed = 0;
            if (!zipEntry.isDirectory()) {
                if ( (fileName == null) || zipEntry.getName().contains(fileName)) {
                    byte[] buf = new byte[1024];
                    int bytesRead;
                    String fileOutputName = String.format("%s/%s", directory, zipEntry.getName());
                    FileOutputStream fileOutputStream = new FileOutputStream(fileOutputName);
                    while ((bytesRead = streamZips.read(buf)) > 0) {
                        sizeProcessed += bytesRead;
                        fileOutputStream.write(buf, 0, bytesRead);
                        if (iZipFile != null) iZipFile.progress(sizeZip, sizeProcessed);
                    }
                }
            }

        }
    } finally {
        if (streamZipFile != null) streamZipFile.close();
        if (streamZips != null) streamZips.close();
    }
}
 
开发者ID:brolam,项目名称:OpenHomeAnalysis,代码行数:37,代码来源:OhaHelper.java

示例6: resource

import java.util.zip.ZipEntry; //导入方法依赖的package包/类
@Override
public byte[] resource(String path) throws IOException {
    if (nonexistentResources.contains(path)) {
        return null;
    }
    JarFile jf;
    try {
        jf = getJarFile(path);
    } catch (ZipException ex) {
        if (warnedFiles.add(file)) {
            LOGGER.log(Level.INFO, "Cannot open " + file, ex);
            dumpFiles(file, -1);
        }
        return null;
    }
    try {
        ZipEntry ze = jf.getEntry(path);
        if (ze == null) {
            nonexistentResources.add(path);
            return null;
        }

        if (LOGGER.isLoggable(Level.FINER)) {
            LOGGER.log(Level.FINER, "Loading {0} from {1}", new Object[] {path, file.getPath()});
        }
    
        int len = (int)ze.getSize();
        byte[] data = new byte[len];
        InputStream is = jf.getInputStream(ze);
        int count = 0;
        while (count < len) {
            count += is.read(data, count, len-count);
        }
        return data;
    } finally {
        releaseJarFile();
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:39,代码来源:JarClassLoader.java

示例7: zeString

import java.util.zip.ZipEntry; //导入方法依赖的package包/类
static String zeString(ZipEntry ze) {
    int store = (ze.getCompressedSize() > 0) ?
        (int)( (1.0 - ((double)ze.getCompressedSize()/(double)ze.getSize()))*100 )
        : 0 ;
    // Follow unzip -lv output
    return ze.getSize() + "\t" + ze.getMethod()
        + "\t" + ze.getCompressedSize() + "\t"
        + store + "%\t"
        + new Date(ze.getTime()) + "\t"
        + Long.toHexString(ze.getCrc()) + "\t"
        + ze.getName() ;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:13,代码来源:Utils.java

示例8: getSize

import java.util.zip.ZipEntry; //导入方法依赖的package包/类
@Override
protected long getSize () throws IOException {
    ZipFile zf = new ZipFile (archiveFile);
    try {
        ZipEntry ze = zf.getEntry(this.resName);
        return ze == null ? 0L : ze.getSize();
    } finally {
        zf.close();
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:11,代码来源:FileObjects.java

示例9: ZipFile2

import java.util.zip.ZipEntry; //导入方法依赖的package包/类
public ZipFile2(String zipPath, ZipEntry entry) {
    if (entry == null)
        throw new IllegalArgumentException("file must not be null");
    if(!zipPath.endsWith("/"))
        zipPath += "/";
   
    mPath = zipPath+entry.getName();
    mLength = entry.getSize();
    mIsFile = !entry.isDirectory();
    mLastModified = entry.getTime();
}
 
开发者ID:archos-sa,项目名称:aos-FileCoreLibrary,代码行数:12,代码来源:ZipFile2.java

示例10: unzipIntoTempDirectory

import java.util.zip.ZipEntry; //导入方法依赖的package包/类
static File unzipIntoTempDirectory(File file) throws IOException {
	final int random = new SecureRandom().nextInt();
	final File tmpDirectory = new File(System.getProperty("java.io.tmpdir"), "tmpdcd" + random);
	// on ajoute random au répertoire temporaire pour l'utilisation d'instances en parallèle
	if (!tmpDirectory.exists() && !tmpDirectory.mkdirs()) {
		throw new IOException(tmpDirectory + " can't be created");
	}
	final ZipFile zipFile = new ZipFile(file);
	try {
		final byte[] buffer = new byte[64 * 1024]; // buffer de 64 Ko pour la décompression
		final Enumeration<? extends ZipEntry> entries = zipFile.entries();
		while (entries.hasMoreElements() && !Thread.currentThread().isInterrupted()) {
			final ZipEntry zipEntry = entries.nextElement();
			final boolean toBeCopied = zipEntry.getName().endsWith(".class")
					|| isViewFile(zipEntry.getName());
			if (toBeCopied && !zipEntry.isDirectory()) {
				final File tmpFile = new File(tmpDirectory, zipEntry.getName());
				if (!tmpFile.getParentFile().exists() && !tmpFile.getParentFile().mkdirs()) {
					throw new IOException(tmpFile.getParentFile() + " can't be created");
				}
				final InputStream input = zipFile.getInputStream(zipEntry);
				final OutputStream output = new BufferedOutputStream(
						new FileOutputStream(tmpFile), (int) zipEntry.getSize());
				try {
					copy(buffer, input, output);
				} finally {
					input.close();
					output.close();
				}
			}
		}
	} finally {
		zipFile.close();
	}
	return tmpDirectory;
}
 
开发者ID:evernat,项目名称:dead-code-detector,代码行数:37,代码来源:DcdHelper.java

示例11: validateZipEntrySize

import java.util.zip.ZipEntry; //导入方法依赖的package包/类
public static void validateZipEntrySize(ZipEntry zipEntry, long maxEntrySize) {

        if (zipEntry.getSize() > maxEntrySize) {
            throw new ContentException(Messages.ERROR_SIZE_OF_UNCOMPRESSED_FILE_EXCEEDS_MAX_SIZE_LIMIT, zipEntry.getSize(),
                zipEntry.getName(), maxEntrySize);
        }
    }
 
开发者ID:SAP,项目名称:cf-mta-deploy-service,代码行数:8,代码来源:StreamUtil.java

示例12: getNextEntry

import java.util.zip.ZipEntry; //导入方法依赖的package包/类
@Override
public ArchiveEntry getNextEntry() throws IOException
{
	if (entries.hasMoreElements())
	{
		ZipEntry zipEntry = entries.nextElement();
		stream = zipFile.getInputStream(zipEntry);
		return new ArchiveEntry(zipEntry.getName().replace('\\', '/'), zipEntry.isDirectory(), zipEntry.getSize());
	}
	else return null;
}
 
开发者ID:equella,项目名称:Equella,代码行数:12,代码来源:FileSystemServiceImpl.java

示例13: analyseClassFiles

import java.util.zip.ZipEntry; //导入方法依赖的package包/类
private static void analyseClassFiles(ZipFile zipFile, String source, ArrayList<UnresolvedNode> unresolvedNodes,
        StringPattern reflectionPattern) throws IOException {
    final Enumeration<? extends ZipEntry> entries = zipFile.entries();
    while (entries.hasMoreElements()) {
        final ZipEntry entry = entries.nextElement();
        if (!entry.isDirectory() && entry.getName().endsWith(".class")) {
            final InputStream stream = zipFile.getInputStream(entry);
            final int size = (int) entry.getSize();
            unresolvedNodes.add(Parser.createNode(stream, source, size, reflectionPattern));
        }
    }
}
 
开发者ID:sake92,项目名称:hepek-classycle,代码行数:13,代码来源:Parser.java

示例14: ESRIShapefile

import java.util.zip.ZipEntry; //导入方法依赖的package包/类
public ESRIShapefile( ZipInputStream zip ) throws IOException {
	filename = null;
	boolean hasDBF = false;
	boolean hasSHP = false;
	ZipEntry entry = zip.getNextEntry();
	while( zip.available()!=0 ) {
		String name = entry.getName();
	System.out.println( name );
		if( name.endsWith(".dbf") || name.endsWith(".shp") ) {
			filename = name.substring( 0, name.lastIndexOf(".") );
		} else if( !name.endsWith(".link") ) {
		//	zip.closeEntry();
			entry = zip.getNextEntry();
			continue;
		}
		int size = (int)entry.getSize();
		byte[] buffer = new byte[size];
		int off = 0;
		int len=size;
		while( (len = zip.read(buffer, off, size-off)) < size-off )off+=len;
		ByteArrayInputStream in = new ByteArrayInputStream(buffer);
		if( name.endsWith(".dbf") ) {
			hasDBF = true;
			dbfFile = new DBFFile( in );
		} else if(name.endsWith(".shp")) {
			shapes = new Vector();
			hasSHP = true;
			readShapes(in);
		} else if(name.endsWith(".link")) {
			readProperties(in);
		}
		entry = zip.getNextEntry();
	//	zip.closeEntry();
	}
	zip.close();
	selected = new Vector();
	initColors();
	if( hasDBF && hasSHP )return;
	else throw new IOException("insufficient information");
}
 
开发者ID:iedadata,项目名称:geomapapp,代码行数:41,代码来源:ESRIShapefile.java

示例15: readClassFile

import java.util.zip.ZipEntry; //导入方法依赖的package包/类
private byte[] readClassFile(String name, String classFileLocation)
                      throws IOException {
    String classFileName = name + ".class"; // NOI18N
    File location = new File(classFileLocation);

    if (location.isDirectory()) {
        return MiscUtils.readFileIntoBuffer(new FileOrZipEntry(classFileLocation, classFileName));
    } else { // Should be .jar file
             // The following code may be used at different stages of JFluid work, with different initialization states, so
             // it's coded defensively. If it can use an available open ZipFile, it will use it, otherwise it will open its own.

        ZipFile zip = null;

        if (classPath == null) {
            classPath = ClassRepository.getClassPath();
        }

        if (classPath != null) {
            try {
                zip = classPath.getZipFileForName(classFileLocation);
            } catch (ZipException e2) {
                throw new IOException("Could not open archive " + classFileLocation); // NOI18N
            }
        } else {
            throw new IOException("Could not get classpath for " + classFileName + " in " + classFileLocation); // NOI18N
        }

        ZipEntry entry = zip.getEntry(classFileName);

        if (entry == null) {
            throw new IOException("Could not find entry for " + classFileName + " in " + classFileLocation); // NOI18N
        }

        int len = (int) entry.getSize();
        byte[] buf = new byte[len];
        InputStream in = zip.getInputStream(entry);
        int readBytes;
        int ofs = 0;
        int remBytes = len;

        do {
            readBytes = in.read(buf, ofs, remBytes);
            ofs += readBytes;
            remBytes -= readBytes;
        } while (ofs < len);

        in.close();

        return buf;
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:52,代码来源:ClassFileCache.java


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