本文整理汇总了Java中java.util.zip.ZipFile.getInputStream方法的典型用法代码示例。如果您正苦于以下问题:Java ZipFile.getInputStream方法的具体用法?Java ZipFile.getInputStream怎么用?Java ZipFile.getInputStream使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.zip.ZipFile
的用法示例。
在下文中一共展示了ZipFile.getInputStream方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: readClass
import java.util.zip.ZipFile; //导入方法依赖的package包/类
@Override
public byte[] readClass(String className) throws IOException {
byte[] ret = null;
ZipFile zf = new ZipFile(absPath);
for (Enumeration<? extends java.util.zip.ZipEntry> ez = zf.entries(); ez.hasMoreElements();) {
java.util.zip.ZipEntry ze = ez.nextElement();
if (className.equals(ze.toString())) {
ret = new byte[(int)ze.getSize()];
InputStream is = zf.getInputStream(ze);
int len = ret.length;
int offset = 0;
while (offset < len) {
offset += is.read(ret, offset, len-offset);
}
return ret;
}
}
return ret;
}
示例2: parseItemInformation
import java.util.zip.ZipFile; //导入方法依赖的package包/类
/**
* Parses the item information of the dataset into valid vectors and puts it into the dataset.
*
* @param zipFile the zip file containing the item information of the dataset
* @throws IOException if the zip file does not contain the file for the item information
* @throws ParsingFailedException if there is a syntax error in the file
*/
private void parseItemInformation(ZipFile zipFile) throws IOException, ParsingFailedException {
InputStream stream = zipFile.getInputStream(zipFile.getEntry(ITEM_FILE));
BufferedReader br = new BufferedReader(new InputStreamReader(stream, StandardCharsets.UTF_8));
itemsDeclared = 0;
String line;
while ((line = readNonCommentLine(br)) != null) {
// read the item feature data
if (line.startsWith(FEATURE_DECLARATION) && itemsDeclared != 0) {
br.close();
throw new ParsingFailedException(FEATURE_AFTER_VALUE);
} else if (line.startsWith(FEATURE_DECLARATION)) {
// Already parsed
} else {
itemsDeclared++;
parseItemVectorLine(line);
}
}
br.close();
}
示例3: unpack
import java.util.zip.ZipFile; //导入方法依赖的package包/类
private boolean unpack (@NonNull final File packedFile, @NonNull File targetFolder) throws IOException {
final ZipFile zf = new ZipFile(packedFile);
final Enumeration<? extends ZipEntry> entries = zf.entries();
try {
while (entries.hasMoreElements()) {
final ZipEntry entry = entries.nextElement();
final File target = new File (targetFolder,entry.getName().replace('/', File.separatorChar)); //NOI18N
if (entry.isDirectory()) {
target.mkdirs();
} else {
//Some zip files don't have zip entries for folders
target.getParentFile().mkdirs();
try (final InputStream in = zf.getInputStream(entry);
final FileOutputStream out = new FileOutputStream(target)) {
FileUtil.copy(in, out);
}
}
}
} finally {
zf.close();
}
return true;
}
示例4: searchJar
import java.util.zip.ZipFile; //导入方法依赖的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;
}
示例5: getInputStreamByName
import java.util.zip.ZipFile; //导入方法依赖的package包/类
protected InputStream getInputStreamByName(String name) throws IOException
{
ZipFile zipfile = this.getResourcePackZipFile();
ZipEntry zipentry = zipfile.getEntry(name);
if (zipentry == null)
{
throw new ResourcePackFileNotFoundException(this.resourcePackFile, name);
}
else
{
return zipfile.getInputStream(zipentry);
}
}
示例6: upZipFile
import java.util.zip.ZipFile; //导入方法依赖的package包/类
/**
* 解压缩一个文件
*
* @param zipFile 压缩文件
* @param folderPath 解压缩的目标目录
* @throws IOException 当解压缩过程出错时抛出
*/
public static void upZipFile(File zipFile, String folderPath) throws ZipException, IOException {
File desDir = new File(folderPath);
if (!desDir.exists()) {
desDir.mkdirs();
}
ZipFile zf = new ZipFile(zipFile);
for (Enumeration<?> entries = zf.entries(); entries.hasMoreElements();) {
ZipEntry entry = ((ZipEntry)entries.nextElement());
InputStream in = zf.getInputStream(entry);
String name = entry.getName();
name = name.split("_")[0];
String str = folderPath + File.separator + name+".apk";
str = new String(str.getBytes("8859_1"), "GB2312");
File desFile = new File(str);
if (!desFile.exists()) {
File fileParentDir = desFile.getParentFile();
if (!fileParentDir.exists()) {
fileParentDir.mkdirs();
}
desFile.createNewFile();
}
OutputStream out = new FileOutputStream(desFile);
byte buffer[] = new byte[BUFF_SIZE];
int realLength;
while ((realLength = in.read(buffer)) > 0) {
out.write(buffer, 0, realLength);
}
in.close();
out.close();
}
}
示例7: extract
import java.util.zip.ZipFile; //导入方法依赖的package包/类
private static void extract(ZipFile apk, ZipEntry dexFile, File extractTo, String extractedFilePrefix) throws IOException, FileNotFoundException {
Throwable th;
InputStream in = apk.getInputStream(dexFile);
File tmp = File.createTempFile(extractedFilePrefix, EXTRACTED_SUFFIX, extractTo.getParentFile());
Log.i(TAG, "Extracting " + tmp.getPath());
try {
ZipOutputStream out = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(tmp)));
try {
ZipEntry classesDex = new ZipEntry("classes.dex");
classesDex.setTime(dexFile.getTime());
out.putNextEntry(classesDex);
byte[] buffer = new byte[16384];
for (int length = in.read(buffer); length != -1; length = in.read(buffer)) {
out.write(buffer, 0, length);
}
out.closeEntry();
out.close();
Log.i(TAG, "Renaming to " + extractTo.getPath());
if (tmp.renameTo(extractTo)) {
closeQuietly(in);
tmp.delete();
return;
}
throw new IOException("Failed to rename \"" + tmp.getAbsolutePath() + "\" to \"" + extractTo.getAbsolutePath() + "\"");
} catch (Throwable th2) {
th = th2;
ZipOutputStream zipOutputStream = out;
closeQuietly(in);
tmp.delete();
throw th;
}
} catch (Throwable th3) {
th = th3;
closeQuietly(in);
tmp.delete();
throw th;
}
}
示例8: unzipIntoTempDirectory
import java.util.zip.ZipFile; //导入方法依赖的package包/类
static File unzipIntoTempDirectory(File file) throws IOException {
final int random = new SecureRandom().nextInt();
final File tmpDirectory = new File(System.getProperty("java.io.tmpdir"), "tmpdcd" + random);
// on ajoute random au répertoire temporaire pour l'utilisation d'instances en parallèle
if (!tmpDirectory.exists() && !tmpDirectory.mkdirs()) {
throw new IOException(tmpDirectory + " can't be created");
}
final ZipFile zipFile = new ZipFile(file);
try {
final byte[] buffer = new byte[64 * 1024]; // buffer de 64 Ko pour la décompression
final Enumeration<? extends ZipEntry> entries = zipFile.entries();
while (entries.hasMoreElements() && !Thread.currentThread().isInterrupted()) {
final ZipEntry zipEntry = entries.nextElement();
final boolean toBeCopied = zipEntry.getName().endsWith(".class")
|| isViewFile(zipEntry.getName());
if (toBeCopied && !zipEntry.isDirectory()) {
final File tmpFile = new File(tmpDirectory, zipEntry.getName());
if (!tmpFile.getParentFile().exists() && !tmpFile.getParentFile().mkdirs()) {
throw new IOException(tmpFile.getParentFile() + " can't be created");
}
final InputStream input = zipFile.getInputStream(zipEntry);
final OutputStream output = new BufferedOutputStream(
new FileOutputStream(tmpFile), (int) zipEntry.getSize());
try {
copy(buffer, input, output);
} finally {
input.close();
output.close();
}
}
}
} finally {
zipFile.close();
}
return tmpDirectory;
}
示例9: process
import java.util.zip.ZipFile; //导入方法依赖的package包/类
public static List<String> process(File jarFile, String key) throws Throwable {
List<String> mostlikelyacustomer = new ArrayList<>();
ZipFile zipFile = new ZipFile(jarFile);
Enumeration<? extends ZipEntry> entries = zipFile.entries();
try {
while (entries.hasMoreElements()) {
ZipEntry entry = entries.nextElement();
if (!entry.isDirectory() && entry.getName().endsWith(".class")) {
try (InputStream in = zipFile.getInputStream(entry)) {
ClassReader cr = new ClassReader(in);
ClassNode classNode = new ClassNode();
cr.accept(classNode, 0);
String currentextraction;
if ((currentextraction = isWatermark(classNode, key)) != null) {
mostlikelyacustomer.add(currentextraction);
}
}
}
}
} finally {
String zipcomment;
if ((zipcomment = zipCommentIsWatermark(zipFile, key)) != null) {
mostlikelyacustomer.add(zipcomment);
}
zipFile.close();
}
return mostlikelyacustomer;
}
示例10: Package
import java.util.zip.ZipFile; //导入方法依赖的package包/类
/**
* Load from String representation of JSON object or from a zip file path.
* @param jsonStringSource
* @param strict
* @throws IOException
* @throws DataPackageException
* @throws ValidationException
*/
public Package(String jsonStringSource, boolean strict) throws IOException, DataPackageException, ValidationException{
this.strictValidation = strict;
// If zip file is given.
if(jsonStringSource.toLowerCase().endsWith(".zip")){
// Read in memory the file inside the zip.
ZipFile zipFile = new ZipFile(jsonStringSource);
ZipEntry entry = zipFile.getEntry(DATAPACKAGE_FILENAME);
// Throw exception if expected datapackage.json file not found.
if(entry == null){
throw new DataPackageException("The zip file does not contain the expected file: " + DATAPACKAGE_FILENAME);
}
// Read the datapackage.json file inside the zip
try(InputStream is = zipFile.getInputStream(entry)){
StringBuilder out = new StringBuilder();
try(BufferedReader reader = new BufferedReader(new InputStreamReader(is))){
String line = null;
while ((line = reader.readLine()) != null) {
out.append(line);
}
}
// Create and set the JSONObject for the datapackage.json that was read from inside the zip file.
this.setJson(new JSONObject(out.toString()));
// Validate.
this.validate();
}
}else{
// Create and set the JSONObject fpr the String representation of desriptor JSON object.
this.setJson(new JSONObject(jsonStringSource));
// If String representation of desriptor JSON object is provided.
this.validate();
}
}
示例11: parseFromJson
import java.util.zip.ZipFile; //导入方法依赖的package包/类
private void parseFromJson(ZipEntry modelEntry, ZipFile zipFile) throws Exception
{
BufferedReader reader = new BufferedReader(new InputStreamReader(zipFile.getInputStream(modelEntry)));
String json = reader.readLine();
json = json.replaceAll("@", "").replaceAll(json.substring(1, 2), "");
JsonTechneModel model = JsonHelper.parseTechneModel(new ByteArrayInputStream(json.getBytes()));
for (Models models : model.Techne.Models)
{
Model tblmodel = models.Model;
for (Shape shape : tblmodel.Geometry.Shape)
{
boolean mirrored = shape.IsMirrored;
String[] offset = shape.Offset.split(",");
String[] position = shape.Position.split(",");
String[] rotation = shape.Rotation.split(",");
String[] size = shape.Size.split(",");
String[] textureOffset = shape.TextureOffset.split(",");
TechneBox box = new TechneBox(this, shape.name);
box.setTextureOffset(Integer.parseInt(textureOffset[0]), Integer.parseInt(textureOffset[1]));
box.mirror = mirrored;
box.setOffset(Float.parseFloat(offset[0]), Float.parseFloat(offset[1]), Float.parseFloat(offset[2]));
box.setDimensions(Integer.parseInt(size[0]), Integer.parseInt(size[1]), Integer.parseInt(size[2]));
box.setRotationPoint(Float.parseFloat(position[0]), Float.parseFloat(position[1]) - 23.4f,
Float.parseFloat(position[2]));
box.setRotateAngles(Float.parseFloat(rotation[0]), Float.parseFloat(rotation[1]),
Float.parseFloat(rotation[2]));
box.setTextureSize(textureSizeX, textureSizeY);
boxes.add(box);
}
}
}
示例12: getFileStream
import java.util.zip.ZipFile; //导入方法依赖的package包/类
/**
* @deprecated Use {@link #getFileStream(String)} instead.
*/
@Deprecated
public static InputStream getFileStream(File zip, String file)
throws IOException {
try {
final ZipFile z = new ZipFile(zip);
return z.getInputStream(z.getEntry(file));
}
catch (Exception e) {
throw new IOException("Couldn't locate " + file + " in " + zip.getName()
+ ": " + e.getMessage());
}
}
示例13: copy
import java.util.zip.ZipFile; //导入方法依赖的package包/类
private void copy(ZipFile zipFile, File targetFile, ZipEntry entry) {
try (InputStream inputStream = zipFile.getInputStream(entry)) {
Files.copy(inputStream, targetFile.toPath());
} catch (IOException e) {
throw new RuntimeException(
format("Cannot write entry to file: {0}: {1}", e.getMessage(), targetFile.getAbsolutePath()), e);
}
}
示例14: unpack
import java.util.zip.ZipFile; //导入方法依赖的package包/类
public static void unpack(File zipfile) {
try {
ZipFile zip = new ZipFile(zipfile);
ZipEntry info = zip.getEntry("__PROJECT_INFO__");
BufferedReader in = new BufferedReader(new InputStreamReader(zip.getInputStream(info), "UTF-8"));
String pId = in.readLine();
String pTitle = in.readLine();
String pStartD = in.readLine();
String pEndD = in.readLine();
Project prj = ProjectManager.createProject(pId, pTitle, new CalendarDate(pStartD), null);
if (pEndD != null)
prj.setEndDate(new CalendarDate(pEndD));
//File prDir = new File(JN_DOCPATH + prj.getID());
Enumeration files;
for (files = zip.entries(); files.hasMoreElements();){
ZipEntry ze = (ZipEntry)files.nextElement();
if ( ze.isDirectory() )
{
File theDirectory = new File (JN_DOCPATH + prj.getID()+ "/" + ze.getName() );
// create this directory (including any necessary parent directories)
theDirectory.mkdirs();
theDirectory = null;
}
if ((!ze.getName().equals("__PROJECT_INFO__")) && (!ze.isDirectory())) {
FileOutputStream out = new FileOutputStream(JN_DOCPATH + prj.getID() +"/"+ ze.getName());
InputStream inp = zip.getInputStream(ze);
byte[] buffer = new byte[1024];
int len;
while((len = inp.read(buffer)) >= 0)
out.write(buffer, 0, len);
inp.close();
out.close();
}
}
zip.close();
CurrentStorage.get().storeProjectManager();
}
catch (Exception ex) {
new ExceptionDialog(ex, "Failed to read from "+zipfile, "Make sure that this file is a Memoranda project archive.");
}
}
示例15: processUpload
import java.util.zip.ZipFile; //导入方法依赖的package包/类
protected ImportResult processUpload(ZipFile zipFile, String filename) throws IOException
{
if (zipFile.size() > 2)
{
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "cmm.rest_api.model.import_invalid_zip_package");
}
CustomModel customModel = null;
String shareExtModule = null;
Enumeration<? extends ZipEntry> entries = zipFile.entries();
while (entries.hasMoreElements())
{
ZipEntry entry = entries.nextElement();
if (!entry.isDirectory())
{
final String entryName = entry.getName();
try (InputStream input = new BufferedInputStream(zipFile.getInputStream(entry), BUFFER_SIZE))
{
if (!(entryName.endsWith(CustomModelServiceImpl.SHARE_EXT_MODULE_SUFFIX)) && customModel == null)
{
try
{
M2Model m2Model = M2Model.createModel(input);
customModel = importModel(m2Model);
}
catch (DictionaryException ex)
{
if (shareExtModule == null)
{
// Get the input stream again, as the zip file doesn't support reset.
try (InputStream moduleInputStream = new BufferedInputStream(zipFile.getInputStream(entry), BUFFER_SIZE))
{
shareExtModule = getExtensionModule(moduleInputStream, entryName);
}
if (shareExtModule == null)
{
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "cmm.rest_api.model.import_invalid_zip_entry_format", new Object[] { entryName });
}
}
else
{
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "cmm.rest_api.model.import_invalid_model_entry", new Object[] { entryName });
}
}
}
else
{
shareExtModule = getExtensionModule(input, entryName);
if (shareExtModule == null)
{
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "cmm.rest_api.model.import_invalid_ext_module_entry", new Object[] { entryName });
}
}
}
}
}
return new ImportResult(customModel, shareExtModule);
}