Apache POI定期打开zip文件,因为Microsoft Excel/Word/...文件是较新格式的zip文件.为了防止某些类型的拒绝服务攻击,它在打开Zip文件时不具有扩展大量扩展的文件的功能,因此可以通过提供一个小的恶意文件来淹没主内存未压缩到内存中.Apache POI称这种zip-bomb保护.
在Java 9之前,它可以通过反射使用一些解决方法将计数InputStream注入ZipFile/ZipEntry以检测扩展数据中的爆炸,这样就可以防止压缩炸弹.
但是在Java 10中,这是不可能的,因为ZipFile的实现以一种阻止这种方式的方式改变了(在ZipFile中硬编译为ZipFile $ ZipFileInputStream).
因此,我们正在寻找一种不同的方法来计算提取期间提取的字节数,以便在压缩率达到某个限制时能够立即停止.
有没有办法在不诉诸反射的情况下以不同的方式进行拉链炸弹检测?
我遇到了阅读.xlsx文件的问题.每当我使用WorkbookFactory.create(inputStream);时,都会在/ tmp/poifiles目录下创建一些具有随机名称的临时文件.该目录是使用第一个用户的RW-RR-权限创建的.所以当试图访问这些文件时,同一台机器上的另一个用户,他不能.
请以任何方式建议我
1)如何在/ tmp目录下创建这些临时文件,而不是总是在/ tmp/poifiles中创建(我使用的是RHEL V5.0)
2)以及如何配置POI,例如更改其读取临时文件的位置?
不再需要帮助解决我的问题,即不同的用户通过POI访问相同的.xlsx文件是非常需要的.
我正在使用jGit克隆远程现有仓库,遵循指南:
我正在使用CFML作为我的例子:
Git = createObject( 'java', 'org.eclipse.jgit.api.Git' );
localPath = createObject( 'java', 'java.io.File' ).init( expandPath( 'temp' ) );
result = Git.cloneRepository()
.setURI( 'https://github.com/github/testrepo.git' )
.setDirectory( localPath )
.call();
result.close();
Run Code Online (Sandbox Code Playgroud)
克隆工作得很好,但在temp\.git\objects\pack我停止Java进程之前,文件锁不会在"pack"文件中发布.
然后我也注意到API文档对于结果.close()方法的行为似乎有些过于谨慎:http:
//download.eclipse.org/jgit/site/4.0.1.201506240215-r/apidocs/org/eclipse/jgit/ LIB/Repository.html#close()方法
减少使用次数,并可能关闭资源.
也许?那是什么意思?为了"放弃任何底层资源",我需要做什么,如AutoCloseable该.close()方法帮助实现的接口中指定的那样?
在SO上有几个类似的问题,但没有一个涉及使用静态方法org.eclipse.jgit.api.Git来克隆新的repo.
想出如何在屏幕右上方显示其中一条小通知气泡消息,请在下面回答.
目前我使用Commons Email发送电子邮件,但我找不到在发送的电子邮件之间共享smtp连接的方法.我有以下代码:
Email email = new SimpleEmail();
email.setFrom("example@example.com");
email.addTo("example@example.com");
email.setSubject("Hello Example");
email.setMsg("Hello Example");
email.setSmtpPort(25);
email.setHostName("localhost");
email.send();
Run Code Online (Sandbox Code Playgroud)
这是非常易读的,但是当我执行大量消息时速度很慢,我认为这是重新连接每条消息的开销.因此,我使用以下代码对其进行了分析,并发现使用重新使用Transport会使事情快三倍.
Properties props = new Properties();
props.setProperty("mail.transport.protocol", "smtp");
Session mailSession = Session.getDefaultInstance(props, null);
Transport transport = mailSession.getTransport("smtp");
transport.connect("localhost", 25, null, null);
MimeMessage message = new MimeMessage(mailSession);
message.setFrom(new InternetAddress("example@example.com"));
message.addRecipient(Message.RecipientType.TO, new InternetAddress("example@example.com"));
message.setSubject("Hello Example");
message.setContent("Hello Example", "text/html; charset=ISO-8859-1");
transport.sendMessage(message, message.getAllRecipients());
Run Code Online (Sandbox Code Playgroud)
所以我想知道是否有办法让Commons Email重用多个电子邮件发送的SMTP连接?我更喜欢Commons Email API,但性能有点痛苦.
谢谢,赎金
使用Apache Commons Compress提取tar文件时,如何找出每个TarArchiveEntry的文件权限(读,写,可执行)?
我想从我的RestEasy webservice创建/返回一个excel文件,但是在使用它时遇到了一些麻烦.当我运行下面的代码(伪代码)时,我收到以下错误:
org.jboss.resteasy.core.NoMessageBodyWriterFoundFailure:无法找到类型的响应对象的MessageBodyWriter:媒体类型的java.io.FileOutputStream:application/vnd.ms-excel
这是一些代码
@POST
@Path("/exportMyData")
@Produces("application/vnd.ms-excel")
public Response getMyData(@FormParam("id") String id) {
HSSFWorkbook hwb = new HSSFWorkbook();
ResponseBuilder response = null;
try{
List<Alert> alertList= service.getAlerts(id);
HSSFSheet sheet = hwb.createSheet("new sheet");
HSSFRow rowhead= sheet.createRow((short)0);
rowhead.createCell((int) 0).setCellValue("ID");
rowhead.createCell((int) 1).setCellValue("Name");
rowhead.createCell((int) 2).setCellValue("Age");
for(Alert alert : alertList){
HSSFRow row= sheet.createRow((short)1);
row.createCell((int) 0).setCellValue(alert.getId());
row.createCell((int) 1).setCellValue(alert.getName());
row.createCell((int) 2).setCellValue(alert.getAge());
}
FileOutputStream fos = new FileOutputStream("mystream.xls");
hwb.write(fos);
response = Response.ok(fos);
response.header("Content-disposition","attachment; filename=export.xls");
}catch(Exception e){
}
return response.build();
}
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?在此先感谢/埃里克
我广泛使用 Apache Commons 包,尤其是 StringUtils、BooleanUtils、ObjectUtils、MapUtils 类,发现它们非常有用。我想知道是否有诸如 IntegerUtils、DoubleUtils 之类的类为其各自的包装类提供了类似的功能(我在 Apache Commons 包中找不到此类类)。
谢谢,
文卡特
我正在尝试解决GRADLE-2293中描述的问题,其中生成的文件总是更新,因为时间戳.settings由Gradle插件写入目录中的Eclipse文件,该插件生成Eclipse项目文件.
这些文件包含这样的标题,我想删除它
#
#Fri Mar 27 10:26:55 CET 2015
Run Code Online (Sandbox Code Playgroud)
目前我正在使用Exec任务来使用外部应用程序sed来剪切以"#"开头的行:
task adjustEclipseSettingsFile(type: Exec) {
executable 'sed'
args '-i','-e','s/^#.*//g','.settings/org.eclipse.jdt.core.prefs'
}
eclipseJdt.finalizedBy adjustEclipseSettingsFile
Run Code Online (Sandbox Code Playgroud)
但是这会增加对我想避免的操作系统二进制文件的依赖.
如何在不调用外部工具的情况下在Gradle任务中简单地删除以"#"开头的行?
我正在尝试将我的Ubuntu PPA中的ktorrent升级到最新的上游版本.它还需要更新的libktorrent包.似乎libktorrent以不兼容的方式被更改,因此导致新的包libktorrent5而不是以前可用的libktorrent4.
但是,当我尝试在PPA上构建包时,我会收到有关不同符号的错误.我尝试了一些方法来修复它,但每次都输出不同.
是否有一些指南如何正确生成符号文件?
完整构建和构建日志在这里
dh_strip debug symbol extraction: disabling for PPA build dh_strip debug symbol extraction: not doing anything since NO_PKG_MANGLE is given dh_makeshlibs -Xusr/lib/kde4/ -a -O--parallel -O--
-O--dbg-package=libktorrent-dbg dpkg-gensymbols: warning: some new symbols appeared in the symbols file: see diff output below dpkg-gensymbols: warning: some symbols or patterns disappeared in the symbols file: see diff output below dpkg-gensymbols: warning: debian/libktorrent5/DEBIAN/symbols doesn't match completely debian/libktorrent5.symbols
--- debian/libktorrent5.symbols (libktorrent5_1.3.0-0ubuntu0~ppa4_amd64)
+++ dpkg-gensymbolsNTCQU9 2012-09-30 02:21:19.000000000 +0000 @@ -2912,13 +2912,20 @@ _ZTVN3utp9UTPServer7PrivateE@Base …Run Code Online (Sandbox Code Playgroud)