当前位置: 首页>>代码示例>>Java>>正文


Java ZipInputStream类代码示例

本文整理汇总了Java中net.lingala.zip4j.io.ZipInputStream的典型用法代码示例。如果您正苦于以下问题:Java ZipInputStream类的具体用法?Java ZipInputStream怎么用?Java ZipInputStream使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ZipInputStream类属于net.lingala.zip4j.io包,在下文中一共展示了ZipInputStream类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: closeFileHandlers

import net.lingala.zip4j.io.ZipInputStream; //导入依赖的package包/类
private void closeFileHandlers(ZipInputStream is, OutputStream os) throws IOException{
	//Close output stream
	if (os != null) {
		os.close();
		os = null;
	}
	
	//Closing inputstream also checks for CRC of the the just extracted file.
	//If CRC check has to be skipped (for ex: to cancel the unzip operation, etc)
	//use method is.close(boolean skipCRCCheck) and set the flag,
	//skipCRCCheck to false
	//NOTE: It is recommended to close outputStream first because Zip4j throws 
	//an exception if CRC check fails
	if (is != null) {
		is.close();
		is = null;
	}
}
 
开发者ID:joielechong,项目名称:Zip4jAndroid,代码行数:19,代码来源:ExtractAllFilesWithInputStreams.java

示例2: extract

import net.lingala.zip4j.io.ZipInputStream; //导入依赖的package包/类
private byte[] extract(ZipFile zipFile, String file, boolean isFileMandatory) throws ZipException, IOException {
    // Files in the zip are flattened, so remove the folder prefix if there is one
    String fileName = getFileNameFromPath(file);

    // Extract from zip
    FileHeader header = zipFile.getFileHeader(fileName);
    if (header == null) {
        if (isFileMandatory) {
            // Mandatory file not found - throw exception
            throw new IllegalArgumentException(String.format("File %s missing from model run outputs", fileName));
        } else {
            // Optional file not found - return null
            return null;
        }
    } else {
        try (ZipInputStream inputStream = zipFile.getInputStream(header)) {
            return IOUtils.toByteArray(inputStream);
        }
    }
}
 
开发者ID:SEEG-Oxford,项目名称:ABRAID-MP,代码行数:21,代码来源:MainHandler.java

示例3: getInputStream

import net.lingala.zip4j.io.ZipInputStream; //导入依赖的package包/类
public static ZipInputStream getInputStream(File source, String fileName) {
    try {
        ZipFile zipFile = new ZipFile(source);
        return zipFile.getInputStream(zipFile.getFileHeader(fileName));
    } catch (ZipException e) {
        e.printStackTrace();
    }
    return null;
}
 
开发者ID:IzzelAliz,项目名称:LCL,代码行数:10,代码来源:ZipUtils.java

示例4: getInputStream

import net.lingala.zip4j.io.ZipInputStream; //导入依赖的package包/类
/**
 * Returns an input stream for reading the contents of the Zip file corresponding
 * to the input FileHeader. Throws an exception if the FileHeader does not exist
 * in the ZipFile
 * @param fileHeader
 * @return ZipInputStream
 * @throws ZipException
 */
public ZipInputStream getInputStream(FileHeader fileHeader) throws ZipException {
	if (fileHeader == null) {
		throw new ZipException("FileHeader is null, cannot get InputStream");
	}
	
	checkZipModel();
	
	if (zipModel == null) {
		throw new ZipException("zip model is null, cannot get inputstream");
	}
	
	Unzip unzip = new Unzip(zipModel);
	return unzip.getInputStream(fileHeader);
}
 
开发者ID:joielechong,项目名称:Zip4jAndroid,代码行数:23,代码来源:ZipFile.java

示例5: initialize

import net.lingala.zip4j.io.ZipInputStream; //导入依赖的package包/类
@Override
public void initialize(URL location, ResourceBundle resources) {
    instance = this;
    Color color = null;
    InterfaceManager.containers.forEach(container -> vertical.getChildren().add(container.getButton()));
    InterfaceManager.containers.forEach(container -> {
        container.getButton().setOnMouseClicked(event -> {
            pane.getChildren().clear();
            pane.getChildren().add(container.getPane());
        });
    });
    try (ZipInputStream skinInputStream = ZipUtils.getInputStream(new File(Util.getBaseDir(), Config.instance.skin), "skin.json")) {
        Reader reader = new InputStreamReader(skinInputStream, "UTF-8");
        Gson json = new GsonBuilder().create();
        GuiColor user = json.fromJson(reader, GuiColor.class);
        java.awt.Color awtColor = ColorTranslated.toColorFromString(user.getColorText());
        color = Color.rgb(awtColor.getRed(),awtColor.getGreen(),awtColor.getBlue(),0.5);
    } catch (IOException e) {
        e.printStackTrace();
    }
    titleText.setFill(color);
    username.setFill(color);
    l1.setStroke(color);
    l2.setStroke(color);
    background.setImage(Skin.getBackground());
    background.setFitHeight(500);
    background.setFitWidth(800);
    title.setOnMousePressed(event -> {
        event.consume();
        xOffset = event.getSceneX();
        yOffset = event.getSceneY();
    });
    title.setOnMouseDragged(event -> {
        event.consume();
        Main.primaryStage.setX(event.getScreenX() - xOffset);
        if (event.getScreenY() - yOffset < 0) {
            Main.primaryStage.setY(0);
        } else {
            Main.primaryStage.setY(event.getScreenY() - yOffset);
        }
    });
}
 
开发者ID:IzzelAliz,项目名称:LCL,代码行数:43,代码来源:FrameController.java

示例6: ExtractSelectFilesWithInputStream

import net.lingala.zip4j.io.ZipInputStream; //导入依赖的package包/类
public ExtractSelectFilesWithInputStream() {
	
	ZipInputStream is = null;
	OutputStream os = null;
	
	try {
		// Initiate the ZipFile
		ZipFile zipFile = new ZipFile("C:\\ZipTest\\ExtractAllFilesWithInputStreams.zip");
		String destinationPath = "c:\\ZipTest";
		
		// If zip file is password protected then set the password
		if (zipFile.isEncrypted()) {
			zipFile.setPassword("password");
		}
		
		//Get the FileHeader of the File you want to extract from the
		//zip file. Input for the below method is the name of the file
		//For example: 123.txt or abc/123.txt if the file 123.txt
		//is inside the directory abc
		FileHeader fileHeader = zipFile.getFileHeader("yourfilename");
		
		if (fileHeader != null) {
			
			//Build the output file
			String outFilePath = destinationPath + System.getProperty("file.separator") + fileHeader.getFileName();
			File outFile = new File(outFilePath);
			
			//Checks if the file is a directory
			if (fileHeader.isDirectory()) {
				//This functionality is up to your requirements
				//For now I create the directory
				outFile.mkdirs();
				return;
			}
			
			//Check if the directories(including parent directories)
			//in the output file path exists
			File parentDir = outFile.getParentFile();
			if (!parentDir.exists()) {
				parentDir.mkdirs(); //If not create those directories
			}
			
			//Get the InputStream from the ZipFile
			is = zipFile.getInputStream(fileHeader);
			//Initialize the output stream
			os = new FileOutputStream(outFile);
			
			int readLen = -1;
			byte[] buff = new byte[BUFF_SIZE];
			
			//Loop until End of File and write the contents to the output stream
			while ((readLen = is.read(buff)) != -1) {
				os.write(buff, 0, readLen);
			}
			
			//Closing inputstream also checks for CRC of the the just extracted file.
			//If CRC check has to be skipped (for ex: to cancel the unzip operation, etc)
			//use method is.close(boolean skipCRCCheck) and set the flag,
			//skipCRCCheck to false
			//NOTE: It is recommended to close outputStream first because Zip4j throws 
			//an exception if CRC check fails
			is.close();
			
			//Close output stream
			os.close();
			
			//To restore File attributes (ex: last modified file time, 
			//read only flag, etc) of the extracted file, a utility class
			//can be used as shown below
			UnzipUtil.applyFileAttributes(fileHeader, outFile);
			
			System.out.println("Done extracting: " + fileHeader.getFileName());
		} else {
			System.err.println("FileHeader does not exist");
		}
	} catch (Exception e) {
		e.printStackTrace();
	}
}
 
开发者ID:joielechong,项目名称:Zip4jAndroid,代码行数:80,代码来源:ExtractSelectFilesWithInputStream.java

示例7: getInputStream

import net.lingala.zip4j.io.ZipInputStream; //导入依赖的package包/类
public ZipInputStream getInputStream(FileHeader fileHeader) throws ZipException {
	UnzipEngine unzipEngine = new UnzipEngine(zipModel, fileHeader);
	return unzipEngine.getInputStream();
}
 
开发者ID:joielechong,项目名称:Zip4jAndroid,代码行数:5,代码来源:Unzip.java


注:本文中的net.lingala.zip4j.io.ZipInputStream类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。