本文整理汇总了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();
}
};
}
示例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;
}
示例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();
}
示例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.");
}
}
示例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();
}
}
示例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();
}
}
示例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() ;
}
示例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();
}
}
示例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();
}
示例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;
}
示例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);
}
}
示例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;
}
示例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));
}
}
}
示例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");
}
示例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;
}
}