本文整理汇总了Java中org.apache.tools.zip.ZipFile.close方法的典型用法代码示例。如果您正苦于以下问题:Java ZipFile.close方法的具体用法?Java ZipFile.close怎么用?Java ZipFile.close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.tools.zip.ZipFile
的用法示例。
在下文中一共展示了ZipFile.close方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isFileConflict
import org.apache.tools.zip.ZipFile; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private boolean isFileConflict(File file) throws IOException{
ZipFile zip = new ZipFile(file, "GBK");
ZipEntry entry;
String name;
String filename;
File outFile;
boolean fileConflict=false;
Enumeration<ZipEntry> en = zip.getEntries();
while (en.hasMoreElements()) {
entry = en.nextElement();
name = entry.getName();
if (!entry.isDirectory()) {
name = entry.getName();
filename = name;
outFile = new File(realPathResolver.get(filename));
if(outFile.exists()){
fileConflict=true;
break;
}
}
}
zip.close();
return fileConflict;
}
示例2: getPlugPerms
import org.apache.tools.zip.ZipFile; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private String getPlugPerms(File file) throws IOException{
ZipFile zip = new ZipFile(file, "GBK");
ZipEntry entry;
String name,filename;
File propertyFile;
String plugPerms="";
Enumeration<ZipEntry> en = zip.getEntries();
while (en.hasMoreElements()) {
entry = en.nextElement();
name = entry.getName();
if (!entry.isDirectory()) {
name = entry.getName();
filename = name;
//读取属性文件的plug.mark属性
if(filename.startsWith(PLUG_FILE_PREFIX)&&filename.endsWith(".properties")){
propertyFile = new File(realPathResolver.get(filename));
Properties p=new Properties();
p.load(new FileInputStream(propertyFile));
plugPerms=p.getProperty(PLUG_PERMS);
}
}
}
zip.close();
return plugPerms;
}
示例3: getInputStream
import org.apache.tools.zip.ZipFile; //导入方法依赖的package包/类
/**
* Return an InputStream for reading the contents of this Resource.
* @return an InputStream object.
* @throws IOException if the zip file cannot be opened,
* or the entry cannot be read.
*/
public InputStream getInputStream() throws IOException {
if (isReference()) {
return ((Resource) getCheckedRef()).getInputStream();
}
final ZipFile z = new ZipFile(getZipfile(), getEncoding());
ZipEntry ze = z.getEntry(getName());
if (ze == null) {
z.close();
throw new BuildException("no entry " + getName() + " in "
+ getArchive());
}
return new FilterInputStream(z.getInputStream(ze)) {
public void close() throws IOException {
FileUtils.close(in);
z.close();
}
protected void finalize() throws Throwable {
try {
close();
} finally {
super.finalize();
}
}
};
}
示例4: unZipFile
import org.apache.tools.zip.ZipFile; //导入方法依赖的package包/类
public static void unZipFile(String archive, String decompressDir) throws IOException, FileNotFoundException, ZipException{
BufferedInputStream bufIn = null;
ZipFile zipFile = new ZipFile(archive, "GBK");
Enumeration<?> enumeration = zipFile.getEntries();
while (enumeration.hasMoreElements()) {
ZipEntry zipEntry = (ZipEntry) enumeration.nextElement();
String entryName = zipEntry.getName();
String entryPath = decompressDir +"/" + entryName;
if(zipEntry.isDirectory()){
System.out.println("Decompressing directory -- " + entryName);
File decompDirFile = new File(entryPath);
if(!decompDirFile.exists()){
decompDirFile.mkdirs();
}
}else {
System.out.println("Decompressing file -- " + entryName);
String fileDir = entryPath.substring(0, entryPath.lastIndexOf("/"));
File fileDirFile = new File(fileDir);
if(!fileDirFile.exists()){
fileDirFile.mkdirs();
}
BufferedOutputStream bufOut = new BufferedOutputStream(new FileOutputStream(decompressDir + "/" + entryName));
bufIn = new BufferedInputStream(zipFile.getInputStream(zipEntry));
byte[] readBuf = new byte[2048];
int readCount = bufIn.read(readBuf);
while (readCount != -1){
bufOut.write(readBuf, 0, readCount);
readCount = bufIn.read(readBuf);
}
bufOut.close();
}
}
zipFile.close();
}
示例5: deleteZipFile
import org.apache.tools.zip.ZipFile; //导入方法依赖的package包/类
public void deleteZipFile(File file) throws IOException {
//根据压缩包删除解压后的文件
// 用默认编码或UTF-8编码解压会乱码!windows7的原因吗
ZipFile zip = new ZipFile(file, "GBK");
ZipEntry entry;
String name;
String filename;
File directory;
//删除文件
Enumeration<ZipEntry> en = zip.getEntries();
while (en.hasMoreElements()) {
entry = en.nextElement();
if (!entry.isDirectory()) {
name = entry.getName();
filename = name;
directory = new File(realPathResolver.get(filename));
if(directory.exists()){
directory.delete();
}
}
}
//删除空文件夹
en= zip.getEntries();
while (en.hasMoreElements()) {
entry = en.nextElement();
if (entry.isDirectory()) {
name = entry.getName();
filename = name;
directory = new File(realPathResolver.get(filename));
if(!directoryHasFile(directory)){
directory.delete();
}
}
}
zip.close();
}
示例6: closeQuietly
import org.apache.tools.zip.ZipFile; //导入方法依赖的package包/类
public static void closeQuietly(@Nullable ZipFile zipFile) {
if (zipFile != null) {
try {
zipFile.close();
} catch (IOException ignored) {
// No operations.
}
}
}
示例7: unzip
import org.apache.tools.zip.ZipFile; //导入方法依赖的package包/类
static private void unzip(File dir, File zipFile) throws IOException {
dir = dir.getAbsoluteFile(); // without absolutization, getParentFile below seems to fail
ZipFile zip = new ZipFile(zipFile);
@SuppressWarnings("unchecked")
Enumeration<ZipEntry> entries = zip.getEntries();
try {
while (entries.hasMoreElements()) {
ZipEntry e = entries.nextElement();
File f = new File(dir, e.getName());
if (e.isDirectory()) {
f.mkdirs();
} else {
File p = f.getParentFile();
if (p != null) {
p.mkdirs();
}
InputStream input = zip.getInputStream(e);
try {
IOUtils.copy(input, f);
} finally {
input.close();
}
try {
FilePath target = new FilePath(f);
int mode = e.getUnixMode();
if (mode!=0) // Ant returns 0 if the archive doesn't record the access mode
target.chmod(mode);
} catch (InterruptedException ex) {
LOGGER.log(Level.WARNING, "unable to set permissions", ex);
}
f.setLastModified(e.getTime());
}
}
} finally {
zip.close();
}
}
示例8: unZipFile
import org.apache.tools.zip.ZipFile; //导入方法依赖的package包/类
public void unZipFile(File file) throws IOException {
// 用默认编码或UTF-8编码解压会乱码!windows7的原因吗?
//解压之前要坚持是否冲突
ZipFile zip = new ZipFile(file, "GBK");
ZipEntry entry;
String name;
String filename;
File outFile;
File pfile;
byte[] buf = new byte[1024];
int len;
InputStream is = null;
OutputStream os = null;
Enumeration<ZipEntry> en = zip.getEntries();
while (en.hasMoreElements()) {
entry = en.nextElement();
name = entry.getName();
if (!entry.isDirectory()) {
name = entry.getName();
filename = name;
outFile = new File(realPathResolver.get(filename));
if(outFile.exists()){
break;
}
pfile = outFile.getParentFile();
if (!pfile.exists()) {
// pfile.mkdirs();
createFolder(outFile);
}
try {
is = zip.getInputStream(entry);
os = new FileOutputStream(outFile);
while ((len = is.read(buf)) != -1) {
os.write(buf, 0, len);
}
} finally {
if (is != null) {
is.close();
is = null;
}
if (os != null) {
os.close();
os = null;
}
}
}
}
zip.close();
}
示例9: unzip
import org.apache.tools.zip.ZipFile; //导入方法依赖的package包/类
/**
* 使用 org.apache.tools.zip.ZipFile 解压文件,它与 java 类库中的 java.util.zip.ZipFile
* 使用方式是一新的,只不过多了设置编码方式的 接口。
* 注,apache 没有提供 ZipInputStream 类,所以只能使用它提供的ZipFile 来读取压缩文件。
*
* @param archive
* 压缩包路径
* @param decompressDir
* 解压路径
* @throws IOException
* IOException
* @throws FileNotFoundException
* FileNotFoundException
* @throws ZipException
* ZipException
*/
public synchronized static void unzip(String archive, String decompressDir)
throws IOException, FileNotFoundException, ZipException {
BufferedInputStream bi;
ZipFile zf = new ZipFile(archive, encoding);// 支持中文
Enumeration<ZipEntry> e = zf.getEntries();
while (e.hasMoreElements()) {
ZipEntry ze = e.nextElement();
String entryName = ze.getName();
String path = decompressDir + "/" + entryName;
if (ze.isDirectory()) {
logger.debug("正在创建解压目录 - " + entryName);
File decompressDirFile = new File(path);
if (!decompressDirFile.exists()) {
decompressDirFile.mkdirs();
}
} else {
logger.debug("正在创建解压文件 - " + entryName);
String fileDir = path.substring(0, path.lastIndexOf("/"));
File fileDirFile = new File(fileDir);
if (!fileDirFile.exists()) {
fileDirFile.mkdirs();
}
BufferedOutputStream bos = new BufferedOutputStream(
new FileOutputStream(decompressDir + "/" + entryName));
bi = new BufferedInputStream(zf.getInputStream(ze));
byte[] readContent = new byte[1024];
int readCount = bi.read(readContent);
while (readCount != -1) {
bos.write(readContent, 0, readCount);
readCount = bi.read(readContent);
}
bos.close();
bi.close();
}
}
zf.close();
}