本文整理汇总了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;
}
}
示例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);
}
}
}
示例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;
}
示例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);
}
示例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);
}
});
}
示例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();
}
}
示例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();
}