當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。