Java代码中的(解压7z加密版)
maven:需要加上这个下载这两个包
<dependency>
<groupId>net.sf.sevenzipjbinding</groupId>
<artifactId>sevenzipjbinding</artifactId>
<version>9.20-2.00beta</version>
</dependency>
<dependency>
<groupId>net.sf.sevenzipjbinding</groupId>
<artifactId>sevenzipjbinding-all-platforms</artifactId>
<version>9.20-2.00beta</version>
</dependency>
普通的架构:需要自己下载
sevenzipjbinding-9.20-2.00beta.jar
sevenzipjbinding-all-platforms-9.20-2.00beta.jar
/**
*
* @Description (解压7z)
* @param file7zPath(7z文件路径)
* @param outPutPath(解压路径)
* @param passWord(文件密码.没有可随便写,或空)
* @return
* @throws Exception
*/
public static int un7z(String file7zPath, final String outPutPath, String passWord) throws Exception {
IInArchive archive;
RandomAccessFile randomAccessFile;
randomAccessFile = new RandomAccessFile(file7zPath, "r");
archive = SevenZip.openInArchive(null, new RandomAccessFileInStream(randomAccessFile), passWord);
int numberOfItems = archive.getNumberOfItems();
ISimpleInArchive simpleInArchive = archive.getSimpleInterface();
for (final ISimpleInArchiveItem item : simpleInArchive.getArchiveItems()) {
final int[] hash = new int[] { 0 };
if (!item.isFolder()) {
ExtractOperationResult result;
final long[] sizeArray = new long[1];
result = item.extractSlow(new ISequentialOutStream() {
public int write(byte[] data) throws SevenZipException {
try {
IOUtils.write(data, new FileOutputStream(new File(outPutPath + File.separator + item.getPath()),true));
} catch (Exception e) {
e.printStackTrace();
}
hash[0] ^= Arrays.hashCode(data); // Consume data
sizeArray[0] += data.length;
return data.length; // Return amount of consumed
}
},passWord);
if (result == ExtractOperationResult.OK) {
logger.error("解压成功...." +String.format("%9X | %10s | %s", hash[0], sizeArray[0], item.getPath()));
// LogUtil.getLog().debug(String.format("%9X | %10s | %s", hash[0], sizeArray[0], item.getPath()));
} else {
logger.error("解压失败:密码错误或者其他错误...." +result);
// LogUtil.getLog().debug("Error extracting item: " + result);
}
}
}
archive.close();
randomAccessFile.close();
return numberOfItems;
}
/**
*不含加密,普通解压
**/
// 解压.Z文件 如:D:/test/test.Z D:/test/test.txt
public static void unZFile(String inFileName, String outFileName) {
InputStream inputStream = null;
OutputStream outputStream = null;
try {
inputStream = new FileInputStream(inFileName);
inputStream = new UncompressInputStream(inputStream);
File file = new File(outFileName);
outputStream = new FileOutputStream(file);
int bytesRead = 0;
byte[] buffer = new byte[100000];
while ((bytesRead = inputStream.read(buffer, 0, 100000)) != -1) {
outputStream.write(buffer, 0, bytesRead);
}
} catch (Exception e) {
e.printStackTrace();
logger.error("unZFile Exception " + e.getMessage());
} finally {
if(outputStream != null){
try {
outputStream.close();
} catch (IOException e) {
e.printStackTrace();
logger.error("outputStream Close Exception " + e.getMessage());
}
}
if(inputStream != null){
try {
inputStream.close();
} catch (IOException e) {
e.printStackTrace();
logger.error("inputStream Close Exception "+ e.getMessage());
}
}
}
}
Java代码中的(解压7z加密版)的更多相关文章
- java 代码解压7z(带密码)转载请注明出处,谢谢
<sevenzipjbinding.version>9.20-2.00beta</sevenzipjbinding.version> <dependency> &l ...
- 解决ubuntu中zip解压的中文乱码问题
转自解决ubuntu中zip解压的中文乱码问题 在我的ubuntu12.10中,发现显示中文基本都是正常的,只有在解压windows传过来的zip文件时,才会出现乱码.所以,我用另一个方法解决中文乱码 ...
- java zip 压缩与解压
java zip 压缩与解压 import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java. ...
- 记一次uboot中gunzip解压速度慢的问题排查
背景 在项目中需要用到解压功能,之前还记录了下,将uboot解压代码移植到另外的bootloader中时,碰到的效率问题.最终查明是cache的配置导致的. https://www.cnblogs.c ...
- Spring MVC框架下在java代码中访问applicationContext.xml文件中配置的文件(可以用于读取配置文件内容)
<bean id="propertyConfigurer" class="com.****.framework.core.SpringPropertiesUtil& ...
- 使用mongo-java-driver3.0.2.jar和mongodb3.0在java代码中的用户验证4
以下是使用mongo-java-driver3.0.2.jar和mongodb3.0.4在java代码中的用户验证: ServerAddress sa = new ServerAddress(host ...
- Android color(颜色) 在XML文件和java代码中
Android color(颜色) 在XML文件和java代码中,有需要的朋友可以参考下. 1.使用Color类的常量,如: int color = Color.BLUE;//创建一个蓝色 是使用An ...
- 关于在Java代码中写Sql语句需要注意的问题
最近做程序,时不时需要自己去手动将sql语句直接写入到Java代码中,写入sql语句时,需要注意几个小问题. 先看我之前写的几句简单的sql语句,自以为没有问题,但是编译直接报错. String st ...
- java代码中获取进程process id(转)
另一方面,线程ID=进程ID+内部线程对象ID并不成立, 参考: blog.csdn.net/heyetina/article/details/6633901 如何在java代码中获取进 ...
随机推荐
- jetty jndi数据源
applicationContext.xml <?xml version="1.0" encoding="utf-8"?> <beans de ...
- Exploring refit, an automatic type-safe REST library for .NET Standard
自动类型安全的.NET标准REST库refit 在SCOTT HANSELMAN 博客上看到一个好东西<Exploring refit, an automatic type-safe RES ...
- openstack修改增加网卡及更改ip
1.neutron更改及mysql数据库更改网卡及ip: neutron port-update ae22c84b-22a9-4618-b046-1eb61379bcea --all ...
- Azkaban2.5安装部署(系统时区设置 + 安装和配置mysql + Azkaban Web Server 安装 + Azkaban Executor Server安装 + Azkaban web server插件安装 + Azkaban Executor Server 插件安装)(博主推荐)(五)
Azkaban是什么?(一) Azkaban的功能特点(二) Azkaban的架构(三) Hadoop工作流引擎之Azkaban与Oozie对比(四) 不多说,直接上干货! http://www.cn ...
- Linux学习笔记——如何使用echo指令向文件写入内容
0.前言 本文总结如何使用echo命令向文件中写入内容,例如使用echo指令覆盖文件内容,使用echo指令向文件追加内容,使用echo指令往文件中追加制表符. echo向文件中输出内容 ...
- C#字符串变量使用
string由于是引用类型,所以,声明的字符串变量会存储到堆上,而且该变量是不可变的,一旦初始化了该变量,该内存区域中存储的内容将不能更改.在对字符串操作时,是在堆上创建了一个新的字符串变量,并将新的 ...
- When you want to give up, remember why you started.
When you want to give up, remember why you started.当你想要放弃的时候,请记住当初你为何而开始.
- iOS开发 - Protocol协议及委托代理(Delegate)
因为Object-C是不支持多继承的,所以很多时候都是用Protocol(协议)来代替.Protocol(协议)只能定义公用的一套接口,但不能提供具体的实现方法.也就是说,它只告诉你要做什么,但具体怎 ...
- linux配置tomcat已service方式启动
1. 在/etc/init.d目录下新建文件,命名为tomcat2. 对tomcat文件进行编辑,执行 # cd /etc/init.d/ # vi tomcat 将下面代码粘上去 注意:下面代码ja ...
- ABAP vs Java, 蛙泳 vs 自由泳
去年7月定下的一年之内学会自由泳的目标终于实现了,特来还愿. ABAP和Java, 蛙泳和自由泳.前面的组合是Jerry用来挣钱养家的技术,后者是Jerry花了大量业余时间和金钱苦练的技能.或许有的朋 ...