本文整理汇总了Java中java.util.zip.ZipInputStream.available方法的典型用法代码示例。如果您正苦于以下问题:Java ZipInputStream.available方法的具体用法?Java ZipInputStream.available怎么用?Java ZipInputStream.available使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.zip.ZipInputStream
的用法示例。
在下文中一共展示了ZipInputStream.available方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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");
}
示例2: 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;
}
示例3: 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;
long size;
int iIndex=0;
while ((ze = zis.getNextEntry()) != null) {
iIndex++;
size = ze.getSize();
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);
if(iIndex==1) {
zipedFiles.putExtra(AppConstants.Download.FILES, context.getString(R.string.extract) + " " + fout.getChannel().size()
+ " ( " + (int) (fout.getChannel().size() * 100) / ze.getSize() + "%)");
}else{
zipedFiles.putExtra(AppConstants.Download.FILES, context.getString(R.string.extract) + " " + iIndex+" off "+"607"
+ " ( " + (int) (iIndex * 100 )/607 + "%)");
}
zipedFiles.putExtra(AppConstants.Download.TYPE , downloadType);
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;
}