本文整理汇总了Java中java.util.zip.ZipInputStream.close方法的典型用法代码示例。如果您正苦于以下问题:Java ZipInputStream.close方法的具体用法?Java ZipInputStream.close怎么用?Java ZipInputStream.close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.zip.ZipInputStream
的用法示例。
在下文中一共展示了ZipInputStream.close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getZipEntries
import java.util.zip.ZipInputStream; //导入方法依赖的package包/类
/**
* 获取jar文件的entry列表
*
* @param jarFile
* @return
*/
public static List<String> getZipEntries(File jarFile) throws IOException {
List<String> entries = new ArrayList<String>();
FileInputStream fis = new FileInputStream(jarFile);
ZipInputStream zis = new ZipInputStream(fis);
try {
// loop on the entries of the jar file package and put them in the final jar
ZipEntry entry;
while ((entry = zis.getNextEntry()) != null) {
// do not take directories or anything inside a potential META-INF folder.
if (entry.isDirectory()) {
continue;
}
String name = entry.getName();
entries.add(name);
}
} finally {
zis.close();
}
return entries;
}
示例2: unzip
import java.util.zip.ZipInputStream; //导入方法依赖的package包/类
public static void unzip(final InputStream zipfile, final File directory) throws IOException {
final ZipInputStream zfile = new ZipInputStream(zipfile);
ZipEntry entry;
while ((entry = zfile.getNextEntry()) != null) {
final File file = new File(directory, entry.getName());
if (entry.isDirectory()) {
file.mkdirs();
} else {
file.getParentFile().mkdirs();
try {
StreamUtilities.copy(zfile, file);
} catch (IOException e) {
log.log(Level.SEVERE, e.getMessage(), e);
}
}
}
zfile.close();
}
示例3: getASiCSSignature
import java.util.zip.ZipInputStream; //导入方法依赖的package包/类
/** Obtiene la firma de un contenedor ASiC-S.
* @param asic Contendor ASiC-S.
* @param signatureFilename Nombre de la entrada del ZIP con las firmas a obtener.
* @return Firma de un contenedor ASiC-S.
* @throws IOException Si hay algún error en el tratamiento de datos. */
private static byte[] getASiCSSignature(final byte[] asic, final String signatureFilename) throws IOException {
if (asic == null || asic.length < 1) {
throw new IllegalArgumentException(
"La firma ASiC proporcionada no puede ser nula ni vacia" //$NON-NLS-1$
);
}
if (signatureFilename == null) {
throw new IllegalArgumentException(
"La firma entrada de firma del ASiC no puede ser nula" //$NON-NLS-1$
);
}
final ZipInputStream zis = new ZipInputStream(new ByteArrayInputStream(asic));
ZipEntry entry;
while((entry = zis.getNextEntry()) != null) {
if (signatureFilename.equals(entry.getName())) {
final byte[] sig = AOUtil.getDataFromInputStream(zis);
zis.close();
return sig;
}
}
throw new IOException(
"Los datos proporcionados no son una firma ASiC-S conteniendo la entrada " + signatureFilename //$NON-NLS-1$
);
}
示例4: unzip
import java.util.zip.ZipInputStream; //导入方法依赖的package包/类
@SneakyThrows
private void unzip(byte[] data, String outputFolder) {
byte[] buffer = new byte[1024];
File folder = new File(outputFolder);
if (!folder.exists()) {
folder.mkdir();
}
ZipInputStream zis = new ZipInputStream(new ByteArrayInputStream(data));
ZipEntry ze = zis.getNextEntry();
while (ze != null) {
String fileName = ze.getName();
File newFile = new File(outputFolder + "/" + fileName);
new File(newFile.getParent()).mkdirs();
if (!newFile.exists())
newFile.createNewFile();
FileOutputStream fos = new FileOutputStream(newFile);
int len;
while ((len = zis.read(buffer)) > 0) {
fos.write(buffer, 0, len);
}
fos.close();
ze = zis.getNextEntry();
}
zis.closeEntry();
zis.close();
}
示例5: ESRIShapefile
import java.util.zip.ZipInputStream; //导入方法依赖的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");
}
示例6: unzip
import java.util.zip.ZipInputStream; //导入方法依赖的package包/类
private static void unzip(InputStream source, FileObject targetFolder) throws IOException {
//installation
ZipInputStream zip=new ZipInputStream(source);
try {
ZipEntry ent;
while ((ent = zip.getNextEntry()) != null) {
if (ent.isDirectory()) {
FileUtil.createFolder(targetFolder, ent.getName());
} else {
FileObject destFile = FileUtil.createData(targetFolder,ent.getName());
FileLock lock = destFile.lock();
try {
OutputStream out = destFile.getOutputStream(lock);
try {
FileUtil.copy(zip, out);
} finally {
out.close();
}
} finally {
lock.releaseLock();
}
}
}
} finally {
zip.close();
}
}
示例7: searchJar
import java.util.zip.ZipInputStream; //导入方法依赖的package包/类
private List<RpcMethodDefinition> searchJar(String jarpath, String serviceName) throws IOException {
List<RpcMethodDefinition> defs = new ArrayList<>();
File jarFile = new File(jarpath);
if (!jarFile.exists() || jarFile.isDirectory()) {
return defs;
}
ZipInputStream zip = new ZipInputStream(new FileInputStream(jarFile));
ZipEntry ze;
while ((ze = zip.getNextEntry()) != null) {
String entryName = ze.getName();
if (entryName.endsWith(".proto")) {
ZipFile zipFile = new ZipFile(jarFile);
try (InputStream in = zipFile.getInputStream(ze)) {
defs.addAll(inspectProtoFile(in, serviceName));
if (!defs.isEmpty()) {
zipFile.close();
break;
}
}
zipFile.close();
}
}
zip.close();
return defs;
}
示例8: run
import java.util.zip.ZipInputStream; //导入方法依赖的package包/类
@Override
public void run() {
super.run();
try {
listener.zipStart();
long sumLength = 0;
// 获取解压之后文件的大小,用来计算解压的进度
long ziplength = getZipTrueSize(zipFileString);
FileInputStream inputStream = new FileInputStream(zipFileString);
ZipInputStream inZip = new ZipInputStream(inputStream);
ZipEntry zipEntry;
String szName = "";
while ((zipEntry = inZip.getNextEntry()) != null) {
szName = zipEntry.getName();
if (zipEntry.isDirectory()) {
szName = szName.substring(0, szName.length() - 1);
File folder = new File(outPathString + File.separator + szName);
folder.mkdirs();
} else {
File file = new File(outPathString + File.separator + szName);
file.createNewFile();
FileOutputStream out = new FileOutputStream(file);
int len;
byte[] buffer = new byte[1024];
while ((len = inZip.read(buffer)) != -1) {
sumLength += len;
int progress = (int) ((sumLength * 100) / ziplength);
updateProgress(progress, listener);
out.write(buffer, 0, len);
out.flush();
}
out.close();
}
}
listener.zipSuccess();
inZip.close();
} catch (Exception e) {
listener.zipFail();
}
}
示例9: unzip
import java.util.zip.ZipInputStream; //导入方法依赖的package包/类
/**
* Extracts a zip file specified by the zipFilePath to a directory specified by
* destDirectory (will be created if does not exists)
* @param zipFilePath
* @param destDirectory
* @throws IOException
*/
public void unzip(String zipFilePath, String destDirectory) throws IOException {
File destDir = new File(destDirectory);
if (!destDir.exists()) {
destDir.mkdir();
}
ZipInputStream zipIn = new ZipInputStream(new FileInputStream(zipFilePath));
ZipEntry entry = zipIn.getNextEntry();
// iterates over entries in the zip file
while (entry != null) {
String filePath = destDirectory + File.separator + entry.getName();
if (!entry.isDirectory()) {
// if the entry is a file, extracts itnew File(newFile.getParent()).mkdirs();
byte[] buffer = new byte[1024];
String fileName = entry.getName();
File newFile = new File(destDirectory + File.separator + fileName);
FileOutputStream fos = new FileOutputStream(newFile);int len;
while ((len = zipIn.read(buffer)) > 0) {
fos.write(buffer, 0, len);
}
fos.close();
} else {
// if the entry is a directory, make the directory
File dir = new File(filePath);
dir.mkdir();
}
zipIn.closeEntry();
entry = zipIn.getNextEntry();
}
zipIn.close();
}
示例10: unzip
import java.util.zip.ZipInputStream; //导入方法依赖的package包/类
public void unzip() throws IOException {
ZipInputStream zis = new ZipInputStream(mApkInputStream);
for (ZipEntry e = zis.getNextEntry(); e != null; e = zis.getNextEntry()) {
String name = e.getName();
if (!e.isDirectory()) {
File file = new File(mWorkspacePath, name);
System.out.println(file);
file.getParentFile().mkdirs();
FileOutputStream fos = new FileOutputStream(file);
StreamUtils.write(zis, fos);
fos.close();
}
}
zis.close();
}
示例11: unzip
import java.util.zip.ZipInputStream; //导入方法依赖的package包/类
public static ArrayList<File> unzip(InputStream fin, String location) {
dirChecker("", location);
ArrayList<File> savedFiles = new ArrayList<>();
try {
ZipInputStream zin = new ZipInputStream(fin);
ZipEntry entry;
while ((entry = zin.getNextEntry()) != null) {
File file = new File(location + "/" + entry.getName());
savedFiles.add(file);
if (file.exists())
continue;
if (entry.isDirectory()) {
dirChecker(entry.getName(), location);
} else {
FileOutputStream fOut = new FileOutputStream(file);
fOut.write(IOUtils.toByteArray(zin));
zin.closeEntry();
fOut.close();
}
}
zin.close();
} catch(Exception e) {
e.printStackTrace();
}
return savedFiles;
}
示例12: unzip
import java.util.zip.ZipInputStream; //导入方法依赖的package包/类
public static void unzip(ZipInputStream zis, File targetDirectory) throws IOException {
try {
ZipEntry ze;
int count;
byte[] buffer = new byte[BUFFER_SIZE];
while ((ze = zis.getNextEntry()) != null) {
File file = new File(targetDirectory, ze.getName());
File dir = ze.isDirectory() ? file : file.getParentFile();
if (!dir.isDirectory() && !dir.mkdirs())
throw new FileNotFoundException("Failed to ensure directory: " +
dir.getAbsolutePath());
if (ze.isDirectory())
continue;
FileOutputStream fout = new FileOutputStream(file);
try {
while ((count = zis.read(buffer)) != -1)
fout.write(buffer, 0, count);
} finally {
fout.close();
}
/* if time should be restored as well
long time = ze.getTime();
if (time > 0)
file.setLastModified(time);
*/
}
} finally {
zis.close();
}
}
示例13: unzip
import java.util.zip.ZipInputStream; //导入方法依赖的package包/类
public static List<File> unzip(File file, String extension, File directory) throws IOException {
int bufferLength = 2048;
byte buffer[] = new byte[bufferLength];
List<File> foundFiles = new ArrayList<File>();
ZipInputStream zipInputStream = new ZipInputStream(
new BufferedInputStream(new FileInputStream(file)));
ZipEntry entry;
File tempDir = directory;
if (tempDir == null || !directory.isDirectory()) {
tempDir = File.createTempFile("unzipped" + UUID.randomUUID(), "", new File(System
.getProperty("java.io.tmpdir")));
tempDir.delete();
tempDir.mkdir();
}
while ((entry = zipInputStream.getNextEntry()) != null) {
int count;
File entryFile = new File(tempDir, entry.getName());
entryFile.createNewFile();
FileOutputStream fos = new FileOutputStream(entryFile);
BufferedOutputStream dest = new BufferedOutputStream(fos,
bufferLength);
while ((count = zipInputStream.read(buffer, 0, bufferLength)) != -1) {
dest.write(buffer, 0, count);
}
dest.flush();
dest.close();
if (entry.getName().endsWith("." + extension)) {
foundFiles.add(entryFile);
}
}
zipInputStream.close();
deleteResources(file);
return foundFiles;
}
示例14: extractContents
import java.util.zip.ZipInputStream; //导入方法依赖的package包/类
private Map<String, byte[]> extractContents(InputStream inputStream)
throws IOException {
Map<String, byte[]> contents = new HashMap<String, byte[]>();
// assumption: the zip is non-empty
ZipInputStream zip = new ZipInputStream(inputStream);
ZipEntry entry;
while ((entry = zip.getNextEntry()) != null) {
if (entry.isDirectory()) continue;
ByteArrayOutputStream contentStream = new ByteArrayOutputStream();
ByteStreams.copy(zip, contentStream);
contents.put(entry.getName(), contentStream.toByteArray());
}
zip.close();
return contents;
}
示例15: read
import java.util.zip.ZipInputStream; //导入方法依赖的package包/类
public IfcModelInterface read(InputStream in, String filename, long fileSize, ByteProgressReporter byteProgressReporter) throws DeserializeException {
mode = Mode.HEADER;
if (filename != null && (filename.toUpperCase().endsWith(".ZIP") || filename.toUpperCase().endsWith(".IFCZIP"))) {
ZipInputStream zipInputStream = new ZipInputStream(in);
ZipEntry nextEntry;
try {
nextEntry = zipInputStream.getNextEntry();
if (nextEntry == null) {
throw new DeserializeException("Zip files must contain exactly one IFC-file, this zip-file looks empty");
}
if (nextEntry.getName().toUpperCase().endsWith(".IFC")) {
IfcModelInterface model = null;
FakeClosingInputStream fakeClosingInputStream = new FakeClosingInputStream(zipInputStream);
model = read(fakeClosingInputStream, fileSize, byteProgressReporter);
if (model.size() == 0) {
throw new DeserializeException("Uploaded file does not seem to be a correct IFC file");
}
if (zipInputStream.getNextEntry() != null) {
zipInputStream.close();
throw new DeserializeException("Zip files may only contain one IFC-file, this zip-file contains more files");
} else {
zipInputStream.close();
return model;
}
} else {
throw new DeserializeException("Zip files must contain exactly one IFC-file, this zip-file seems to have one or more non-IFC files");
}
} catch (IOException e) {
throw new DeserializeException(e);
}
} else {
return read(in, fileSize, byteProgressReporter);
}
}