本文整理汇总了Java中java.util.zip.ZipInputStream.getNextEntry方法的典型用法代码示例。如果您正苦于以下问题:Java ZipInputStream.getNextEntry方法的具体用法?Java ZipInputStream.getNextEntry怎么用?Java ZipInputStream.getNextEntry使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.zip.ZipInputStream
的用法示例。
在下文中一共展示了ZipInputStream.getNextEntry方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: decompressForZip
import java.util.zip.ZipInputStream; //导入方法依赖的package包/类
/**
* Zip解压数据
*
* @param zipStr
* @return
*/
public static String decompressForZip(String zipStr) {
if (TextUtils.isEmpty(zipStr)) {
return "0";
}
byte[] t = Base64.decode(zipStr, Base64.DEFAULT);
try {
ByteArrayOutputStream out = new ByteArrayOutputStream();
ByteArrayInputStream in = new ByteArrayInputStream(t);
ZipInputStream zip = new ZipInputStream(in);
zip.getNextEntry();
byte[] buffer = new byte[1024];
int n = 0;
while ((n = zip.read(buffer, 0, buffer.length)) > 0) {
out.write(buffer, 0, n);
}
zip.close();
in.close();
out.close();
return out.toString();
} catch (IOException e) {
e.printStackTrace();
}
return "0";
}
示例2: saveEntries
import java.util.zip.ZipInputStream; //导入方法依赖的package包/类
private void saveEntries(Path tempDirectory, String rootEntryName, long maxZipEntrySize) throws IOException, FileNotFoundException {
ZipInputStream zis = (ZipInputStream) inputStream;
for (ZipEntry e; (e = zis.getNextEntry()) != null;) {
String currentEntryName = e.getName();
if (!e.getName().startsWith(rootEntryName)) {
continue;
}
validateZipEntrySize(e, maxZipEntrySize);
validateEntry(currentEntryName);
Path filePath = resolveTempEntryPath(currentEntryName, rootEntryName, tempDirectory);
if (e.getName().endsWith(ARCHIVE_ENTRY_SEPARATOR)) {
Files.createDirectories(filePath);
} else {
createFile(filePath);
}
}
}
示例3: unZipFile
import java.util.zip.ZipInputStream; //导入方法依赖的package包/类
public static void unZipFile(InputStream source, FileObject rootFolder) throws IOException {
try {
ZipInputStream str = new ZipInputStream(source);
ZipEntry entry;
while ((entry = str.getNextEntry()) != null) {
if (entry.isDirectory()) {
FileUtil.createFolder(rootFolder, entry.getName());
continue;
}
FileObject fo = FileUtil.createData(rootFolder, entry.getName());
FileLock lock = fo.lock();
try {
OutputStream out = fo.getOutputStream(lock);
try {
FileUtil.copy(str, out);
} finally {
out.close();
}
} finally {
lock.releaseLock();
}
}
} finally {
source.close();
}
}
示例4: zipAndUnzipWrongEncodedBytes
import java.util.zip.ZipInputStream; //导入方法依赖的package包/类
@Test(expected = IllegalArgumentException.class)
public void zipAndUnzipWrongEncodedBytes() throws IOException {
ZipOutputOf<byte[]> zos = IoStream.bytes().zipOutputStream("UTF-16");
try {
zos.putNextEntry(new ZipEntry("ééé"));
zos.write("aaaaaaa".getBytes());
} finally {
zos.close();
}
ZipInputStream zis = IoStream.bytes(zos.get()).zipInputStream("UTF-8");
try {
ZipEntry ze = zis.getNextEntry();
assertThat(ze.getName()).isEqualTo("ééé");
} finally {
zis.close();
}
}
示例5: saveEntries
import java.util.zip.ZipInputStream; //导入方法依赖的package包/类
private static void saveEntries(Path tempDirectory, String rootEntryName, InputStream inputStream)
throws IOException, FileNotFoundException {
ZipInputStream zis = (ZipInputStream) inputStream;
for (ZipEntry e; (e = zis.getNextEntry()) != null;) {
String currentEntryName = e.getName();
if (!e.getName().startsWith(rootEntryName)) {
continue;
}
validateEntry(currentEntryName);
Path filePath = resolveTempEntryPath(currentEntryName, rootEntryName, tempDirectory);
if (e.getName().endsWith(ARCHIVE_ENTRY_SEPARATOR)) {
Files.createDirectories(filePath);
} else {
createFile(filePath, inputStream);
}
}
}
示例6: unzip
import java.util.zip.ZipInputStream; //导入方法依赖的package包/类
private byte[] unzip( byte[] input_data ) throws Exception
{
ZipInputStream zipStream = new ZipInputStream( new ByteArrayInputStream( input_data ) );
ZipEntry entry = null;
byte[] result = null;
while ( (entry = zipStream.getNextEntry()) != null )
{
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] buff = new byte[1024];
int count = 0, loop = 0;
while ( (count = zipStream.read( buff )) != -1 )
{
baos.write( buff, 0, count );
// NLog.i("[OfflineFileParser] unzip read loop : " + loop);
if ( loop++ > 1048567 )
{
throw new Exception();
}
}
result = baos.toByteArray();
zipStream.closeEntry();
}
zipStream.close();
return result;
}
示例7: loadMetaData
import java.util.zip.ZipInputStream; //导入方法依赖的package包/类
private ImmutableList<String> loadMetaData() {
final Optional<String> token = remoteTokenService.getToken();
if (!token.isPresent()) {
LOGGER.error("unable to obtain auth token. not trying to fetch the latest meta data");
return null;
}
try {
final InputStream body = downloadLatestMetadataZip(token.get());
if (body == null) {
return ImmutableList.of(); //no metadata loaded
}
final ZipInputStream zis = new ZipInputStream(body);
ZipEntry entry;
ImmutableList<String> ret = null;
while ((entry = zis.getNextEntry()) != null) {
final String entryName = entry.getName();
if (entryName.equals("fileinfo")) {
ret = readSiaPathsFromInfo(zis);
} else {
digestSiaFile(entry, zis);
}
}
//one of those files must have been fileinfo...
if (ret == null) {
LOGGER.warn("fileinfo not found in metadata");
return ImmutableList.of();
} else {
LOGGER.info("loaded backup from metadata service");
}
return ret;
} catch (UnirestException | IOException e) {
LOGGER.error("unable to load backup from metadata service");
return null;
}
}
示例8: unzipSource
import java.util.zip.ZipInputStream; //导入方法依赖的package包/类
private ByteSource unzipSource(ByteSource byteSource) {
return new ByteSource() {
@Override
public InputStream openStream() throws IOException {
ZipInputStream zipInputStream = new ZipInputStream(byteSource.openBufferedStream());
zipInputStream.getNextEntry();//一个zip里面就一个文件
return zipInputStream;
}
};
}
示例9: 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();
}
}
示例10: unzipData
import java.util.zip.ZipInputStream; //导入方法依赖的package包/类
private String unzipData(InputStream is, String extension,
File writeDirectory) throws IOException {
String baseFileName = UUID.randomUUID().toString();
ZipInputStream zipInputStream = new ZipInputStream(is);
ZipEntry entry;
String returnFile = null;
while ((entry = zipInputStream.getNextEntry()) != null) {
String currentExtension = entry.getName();
int beginIndex = currentExtension.lastIndexOf(".") + 1;
currentExtension = currentExtension.substring(beginIndex);
String fileName = baseFileName + "." + currentExtension;
File currentFile = new File(writeDirectory, fileName);
if (!writeDirectory.exists()) {
writeDirectory.mkdir();
}
currentFile.createNewFile();
FileOutputStream fos = new FileOutputStream(currentFile);
org.apache.commons.io.IOUtils.copy(zipInputStream, fos);
if (currentExtension.equalsIgnoreCase(extension)) {
returnFile = currentFile.getAbsolutePath();
}
fos.close();
}
zipInputStream.close();
return returnFile;
}
示例11: 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();
}
}
示例12: extractBinFilesFromJar
import java.util.zip.ZipInputStream; //导入方法依赖的package包/类
private void extractBinFilesFromJar(File outFolder, File jarFile) throws IOException {
File jarOutFolder = getOutFolderForJarFile(outFolder, jarFile);
FileUtils.deleteQuietly(jarOutFolder);
FileUtils.forceMkdir(jarOutFolder);
try (Closer localCloser = Closer.create()) {
FileInputStream fis = localCloser.register(new FileInputStream(jarFile));
ZipInputStream zis = localCloser.register(new ZipInputStream(fis));
ZipEntry entry;
while ((entry = zis.getNextEntry()) != null) {
if (entry.isDirectory()) {
continue;
}
String name = entry.getName();
if (!isResource(name)) {
continue;
}
// get rid of the path. We don't need it since the file name includes the domain
name = new File(name).getName();
File out = new File(jarOutFolder, name);
//noinspection ResultOfMethodCallIgnored
FileOutputStream fos = localCloser.register(new FileOutputStream(out));
ByteStreams.copy(zis, fos);
zis.closeEntry();
}
}
}
示例13: read
import java.util.zip.ZipInputStream; //导入方法依赖的package包/类
@Override
public long read(InputStream in, String filename, long fileSize) throws DeserializeException {
mode = Mode.HEADER;
if (filename != null && (filename.toUpperCase().endsWith(".ZIP") || filename.toUpperCase().endsWith(".IFCZIP"))) {
ZipInputStream zipInputStream = new ZipInputStream(in);
try {
ZipEntry 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")) {
FakeClosingInputStream fakeClosingInputStream = new FakeClosingInputStream(zipInputStream);
long size = read(fakeClosingInputStream, fileSize);
if (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 size;
} 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);
}
}
示例14: unpackZipFile
import java.util.zip.ZipInputStream; //导入方法依赖的package包/类
/**
* Unpacks a ZIP file to disk.
* All entries are unpacked, even {@code META-INF/MANIFEST.MF} if present.
* Parent directories are created as needed (even if not mentioned in the ZIP);
* empty ZIP directories are created too.
* Existing files are overwritten.
* @param zip a ZIP file
* @param dir the base directory in which to unpack (need not yet exist)
* @throws IOException in case of problems
*/
public static void unpackZipFile(File zip, File dir) throws IOException {
byte[] buf = new byte[8192];
InputStream is = new FileInputStream(zip);
try {
ZipInputStream zis = new ZipInputStream(is);
ZipEntry entry;
while ((entry = zis.getNextEntry()) != null) {
String name = entry.getName();
int slash = name.lastIndexOf('/');
File d = new File(dir, name.substring(0, slash).replace('/', File.separatorChar));
if (!d.isDirectory() && !d.mkdirs()) {
throw new IOException("could not make " + d);
}
if (slash != name.length() - 1) {
File f = new File(dir, name.replace('/', File.separatorChar));
OutputStream os = new FileOutputStream(f);
try {
int read;
while ((read = zis.read(buf)) != -1) {
os.write(buf, 0, read);
}
} finally {
os.close();
}
}
}
} finally {
is.close();
}
}
示例15: 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();
}
}