本文整理汇总了Java中java.util.zip.ZipInputStream.closeEntry方法的典型用法代码示例。如果您正苦于以下问题:Java ZipInputStream.closeEntry方法的具体用法?Java ZipInputStream.closeEntry怎么用?Java ZipInputStream.closeEntry使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.zip.ZipInputStream
的用法示例。
在下文中一共展示了ZipInputStream.closeEntry方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: expandZippedApplication
import java.util.zip.ZipInputStream; //导入方法依赖的package包/类
private void expandZippedApplication(InputStream stream, ApplicationDescription desc)
throws IOException {
ZipInputStream zis = new ZipInputStream(stream);
ZipEntry entry;
File appDir = new File(appsDir, desc.name());
while ((entry = zis.getNextEntry()) != null) {
if (!entry.isDirectory()) {
byte[] data = ByteStreams.toByteArray(zis);
zis.closeEntry();
File file = new File(appDir, entry.getName());
createParentDirs(file);
write(data, file);
}
}
zis.close();
}
示例2: InMemoryZipFile
import java.util.zip.ZipInputStream; //导入方法依赖的package包/类
public InMemoryZipFile(byte[] zipBuffer) throws IOException {
ZipInputStream zin = new ZipInputStream(new ByteArrayInputStream(zipBuffer));
while(true) {
ZipEntry entry;
do {
if((entry = zin.getNextEntry()) == null) {
zin.close();
return;
}
} while(entry.isDirectory());
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
byte[] buf = new byte[10240];
int length;
while((length = zin.read(buf)) != -1) {
buffer.write(buf, 0, length);
}
zin.closeEntry();
this.contents.put(entry.getName(), buffer.toByteArray());
}
}
示例3: unzip
import java.util.zip.ZipInputStream; //导入方法依赖的package包/类
public static 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 it
extractFile(zipIn, filePath);
} else {
// if the entry is a directory, make the directory
File dir = new File(filePath);
dir.mkdir();
}
zipIn.closeEntry();
entry = zipIn.getNextEntry();
}
zipIn.close();
}
示例4: unzipRemoteFile
import java.util.zip.ZipInputStream; //导入方法依赖的package包/类
public static void unzipRemoteFile(String localFileName, String directoryPath){
try {
FileInputStream fin = new FileInputStream(localFileName);
ZipInputStream zin = new ZipInputStream(fin);
ZipEntry ze = null;
while ((ze = zin.getNextEntry()) != null) {
Log.v("Decompress", "Unzipping " + ze.getName());
if(ze.isDirectory()) {
Common.dirChecker(directoryPath + File.separator + ze.getName());
} else {
FileOutputStream fout = new FileOutputStream(directoryPath + File.separator + ze.getName());
for (int c = zin.read(); c != -1; c = zin.read()) {
fout.write(c);
}
zin.closeEntry();
fout.close();
}
}
zin.close();
} catch(Exception e) {
Log.e("Decompress", "unzip", e);
}
}
示例5: seekToEntry
import java.util.zip.ZipInputStream; //导入方法依赖的package包/类
private Optional<ZipEntry> seekToEntry(ZipInputStream inputStream, String entryPath) throws IOException {
ZipEntry zipEntry;
while ((zipEntry = inputStream.getNextEntry()) != null) {
if (zipEntry.getName().startsWith(entryPath)) {
return Optional.of(zipEntry);
}
inputStream.closeEntry();
}
return Optional.empty();
}
示例6: doZipUpload
import java.util.zip.ZipInputStream; //导入方法依赖的package包/类
private void doZipUpload(final File file)
{
UploadWorker worker = new UploadWorker(file)
{
@Override
protected String construct(InputStream in) throws Exception
{
String agreementName = null;
ZipEntry entry;
ZipInputStream zin = new ZipInputStream(in);
while( (entry = zin.getNextEntry()) != null )
{
if( !entry.isDirectory() )
{
String name = FOLDER + entry.getName();
if( name.endsWith(".htm") || name.endsWith(".html") //$NON-NLS-1$ //$NON-NLS-2$
|| name.endsWith(".xsl") || name.endsWith(".xslt") ) //$NON-NLS-1$ //$NON-NLS-2$
{
agreementName = name;
}
FileUploader.upload(adminService, stagingId, name, zin);
}
zin.closeEntry();
}
return agreementName;
}
};
worker.start();
}
示例7: unZip
import java.util.zip.ZipInputStream; //导入方法依赖的package包/类
public static void unZip(File zip, File output) {
byte[] buffer = new byte[1024];
try {
if(!output.exists()) {
output.mkdirs();
}
if(!output.isDirectory()) {
//System.err.println("\"" + output.getAbsolutePath() + "\" isnt a directory");
return;
}
ZipInputStream zis = new ZipInputStream(new FileInputStream(zip));
ZipEntry ze = zis.getNextEntry();
while(ze != null) {
if(ze.isDirectory()) {
ze = zis.getNextEntry();
continue;
}
String fileName = ze.getName();
File newFile = new File(output.getAbsolutePath() + File.separator + fileName);
//System.out.println("File unzip: " + newFile.getAbsolutePath());
new File(newFile.getParent()).mkdirs();
FileOutputStream fos = new FileOutputStream(newFile);
int len;
while ((len = zis.read(buffer)) > 0) {
fos.write(buffer, 0, len);
}
fos.close();
zis.closeEntry();
ze = zis.getNextEntry();
}
zis.close();
} catch (Exception ex) {
System.err.println(ex);
}
}
示例8: process
import java.util.zip.ZipInputStream; //导入方法依赖的package包/类
public void process(File file) throws Exception {
final ZipInputStream zip = new ZipInputStream( new FileInputStream( file ) );
try {
ZipEntry entry;
while ( (entry = zip.getNextEntry()) != null ) {
final byte[] bytes = ByteCodeHelper.readByteCode( zip );
entryHandler.handleEntry( entry, bytes );
zip.closeEntry();
}
}
finally {
zip.close();
}
}
示例9: uncompress
import java.util.zip.ZipInputStream; //导入方法依赖的package包/类
public static boolean uncompress(File zipFile) {
boolean success = false;
try {
FileInputStream fis = new FileInputStream(zipFile);
ZipInputStream zis = new ZipInputStream(new BufferedInputStream(fis));
ZipEntry entry;
File destFolder = new File(zipFile.getParent(), FileUtils.getNameFromFilename(zipFile.getName()));
destFolder.mkdirs();
while ((entry = zis.getNextEntry()) != null) {
File dest = new File(destFolder, entry.getName());
dest.getParentFile().mkdirs();
if(entry.isDirectory()) {
if (!dest.exists()) {
dest.mkdirs();
}
} else {
int size;
byte[] buffer = new byte[2048];
FileOutputStream fos = new FileOutputStream(dest);
BufferedOutputStream bos = new BufferedOutputStream(fos, buffer.length);
while ((size = zis.read(buffer, 0, buffer.length)) != -1) {
bos.write(buffer, 0, size);
}
bos.flush();
bos.close();
IoUtils.flushQuietly(bos);
IoUtils.closeQuietly(bos);
}
zis.closeEntry();
}
IoUtils.closeQuietly(zis);
IoUtils.closeQuietly(fis);
success = true;
} catch (Exception e) {
e.printStackTrace();
}
return success;
}
示例10: upZipFile
import java.util.zip.ZipInputStream; //导入方法依赖的package包/类
public static void upZipFile(Context context,String assetPath,String outputFolderPath){
File desDir = new File(outputFolderPath);
if (!desDir.isDirectory()) {
desDir.mkdirs();
}
try {
InputStream inputStream = context.getResources().getAssets().open(assetPath);
ZipInputStream zipInputStream=new ZipInputStream(inputStream);
ZipEntry zipEntry;
while ((zipEntry = zipInputStream.getNextEntry()) != null) {
Log.d(TAG, "upZipFile: "+zipEntry.getName());
if(zipEntry.isDirectory()) {
File tmpFile=new File(outputFolderPath,zipEntry.getName());
//Log.d(TAG, "upZipFile: folder "+tmpFile.getAbsolutePath());
if(!tmpFile.isDirectory())
tmpFile.mkdirs();
} else {
File desFile = new File(outputFolderPath +"/"+ zipEntry.getName());
if(desFile.exists()) continue;
OutputStream out = new FileOutputStream(desFile);
//Log.d(TAG, "upZipFile: "+desFile.getAbsolutePath());
byte buffer[] = new byte[1024];
int realLength;
while ((realLength = zipInputStream.read(buffer)) > 0) {
out.write(buffer, 0, realLength);
}
zipInputStream.closeEntry();
out.close();
}
}
zipInputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
示例11: writeZip
import java.util.zip.ZipInputStream; //导入方法依赖的package包/类
/**
* Copies the content of a Jar/Zip archive into the receiver archive.
* <p/>An optional {@link IZipEntryFilter} allows to selectively choose which files
* to copy over.
*
* @param input the {@link InputStream} for the Jar/Zip to copy.
* @param filter the filter or <code>null</code>
* @throws IOException
*/
public void writeZip(InputStream input, IZipEntryFilter filter)
throws IOException, IZipEntryFilter.ZipAbortException {
ZipInputStream zis = new ZipInputStream(input);
try {
// loop on the entries of the intermediary package and put them in the final package.
ZipEntry entry;
while ((entry = zis.getNextEntry()) != null) {
String name = entry.getName();
// do not take directories or anything inside a potential META-INF folder.
if (entry.isDirectory() || name.startsWith("META-INF/")) {
continue;
}
// if we have a filter, we check the entry against it
if (filter != null && filter.checkEntry(name) == false) {
continue;
}
JarEntry newEntry;
// Preserve the STORED method of the input entry.
if (entry.getMethod() == JarEntry.STORED) {
newEntry = new JarEntry(entry);
} else {
// Create a new entry so that the compressed len is recomputed.
newEntry = new JarEntry(name);
}
writeEntry(zis, newEntry);
zis.closeEntry();
}
} finally {
zis.close();
}
}
示例12: 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)
*/
public static void unzip(File file, File destDir) throws IOException
{
if (!destDir.exists())
{
destDir.mkdir();
}
ZipInputStream zipIn = new ZipInputStream(new FileInputStream(file));
ZipEntry entry = zipIn.getNextEntry();
// iterates over entries in the zip file
while (entry != null)
{
File entryFile = new File(destDir, entry.getName());
if (!entry.isDirectory())
{
// if the entry is a file, extracts it
extractFile(zipIn, entryFile);
}
else
{
// if the entry is a directory, make the directory
entryFile.mkdir();
}
zipIn.closeEntry();
entry = zipIn.getNextEntry();
}
zipIn.close();
}
示例13: doZipUpload
import java.util.zip.ZipInputStream; //导入方法依赖的package包/类
private void doZipUpload(final File file)
{
UploadWorker worker = new UploadWorker(file)
{
@Override
protected String construct(InputStream in) throws IOException
{
String agreementName = null;
ZipEntry entry;
ZipInputStream zin = new ZipInputStream(in);
while( (entry = zin.getNextEntry()) != null )
{
if( !entry.isDirectory() )
{
String name = FOLDER + entry.getName();
if( name.endsWith(".htm") || name.endsWith(".html") //$NON-NLS-1$ //$NON-NLS-2$
|| name.endsWith(".xsl") || name.endsWith(".xslt") ) //$NON-NLS-1$ //$NON-NLS-2$
{
agreementName = name;
}
FileUploader.upload(adminService, stagingId, name, zin);
}
zin.closeEntry();
}
return agreementName;
}
};
worker.start();
}
示例14: uncompress
import java.util.zip.ZipInputStream; //导入方法依赖的package包/类
private boolean uncompress(File zipFile) {
boolean success = false;
try {
FileInputStream fis = new FileInputStream(zipFile);
ZipInputStream zis = new ZipInputStream(new BufferedInputStream(fis));
ZipEntry entry;
File destFolder = new File(zipFile.getParent(), FileUtils.getNameFromFilename(zipFile.getName()));
destFolder.mkdirs();
while ((entry = zis.getNextEntry()) != null) {
publishProgress(entry.getName().substring(1));
publishProgress(""+0);
File dest = new File(destFolder, entry.getName());
dest.getParentFile().mkdirs();
if(entry.isDirectory()) {
if (!dest.exists()) {
dest.mkdirs();
}
} else {
int size;
byte[] buffer = new byte[2048];
FileOutputStream fos = new FileOutputStream(dest);
BufferedOutputStream bos = new BufferedOutputStream(fos, buffer.length);
long readData=0;
final long totalFile=entry.getSize();
while ((size = zis.read(buffer, 0, buffer.length)) != -1) {
bos.write(buffer, 0, size);
readData+=size;
doProgress(readData,totalFile);
}
bos.flush();
bos.close();
FileUtils.notifyChange(mContex,dest.getAbsolutePath());
}
zis.closeEntry();
}
success = true;
} catch (Exception e) {
e.printStackTrace();
}
return success;
}
示例15: doInBackground
import java.util.zip.ZipInputStream; //导入方法依赖的package包/类
@Override
protected Void doInBackground(String... params) {
try {
is = new FileInputStream(params[0] + "/" + params[1]);
zis = new ZipInputStream(new BufferedInputStream(is));
byte[] buffer = new byte[1024 * 3];
int count;
while ((ze = zis.getNextEntry()) != null) {
filename = ze.getName();
if (ze.isDirectory()) {
File fmd = new File(params[0] + "/" + filename);
fmd.mkdirs();
continue;
}
FileOutputStream fout = new FileOutputStream(params[0] + "/" + filename);
int total = zis.available();
while ((count = zis.read(buffer)) != -1) {
fout.write(buffer, 0, count);
fileCount++;
Intent zipedFiles = new Intent(AppConstants.Download.INTENT);
zipedFiles.putExtra(AppConstants.Download.FILES, context.getString(R.string.extract) + " " + fileCount);
zipedFiles.putExtra(AppConstants.Download.DOWNLOAD, AppConstants.Download.IN_EXTRACT);
LocalBroadcastManager.getInstance(context).sendBroadcast(zipedFiles);
}
File zipFile = new File(params[0] + "/" + params[1]);
zipFile.delete();
if (zipFile.getAbsolutePath().contains("tafseer")) {
copyFile(new File(Environment.getExternalStorageDirectory().getAbsolutePath() + QuranApplication.getInstance()
.getString(R.string.app_folder_path) + "/tafaseer/" + params[1].replace(AppConstants.Extensions.ZIP, AppConstants.Extensions.SQLITE)),
new File(params[0] + "/" + params[1].replace(AppConstants.Extensions.ZIP, AppConstants.Extensions.SQLITE)));
}
fout.close();
zis.closeEntry();
}
//send broadcast of success or failed
LocalBroadcastManager.getInstance(context).sendBroadcast(new Intent(AppConstants.Download.INTENT)
.putExtra(AppConstants.Download.DOWNLOAD, AppConstants.Download.SUCCESS ));
zis.close();
} catch (IOException e) {
e.printStackTrace();
return null;
}
return null;
}