如何检查生成的zip文件是否已损坏?

我们有一段代码在我们的系统上生成一个zip文件。 一切都很好,但有时这个由FilZip或WinZip打开的zip文件被认为已损坏。 所以这是我的问题:如果生成的zip文件已损坏,我们如何以编程方式检查? 以下是我们用于生成zip文件的代码: try { ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(tmpFile)); byte[] buffer = new byte[16384]; int contador = -1; for (DigitalFile digitalFile : document.getDigitalFiles().getContent()) { ZipEntry entry = new ZipEntry(digitalFile.getName()); FileInputStream fis = new FileInputStream(digitalFile.getFile()); try { zos.putNextEntry(entry); while ((counter = fis.read(buffer)) != -1) { zos.write(buffer, 0, counter); } fis.close(); zos.closeEntry(); } catch […]

是什么导致org.hibernate.PropertyAccessException:setter中发生exception

是什么导致这个例外,我无法找到答案。 Request processing failed; nested exception is javax.persistence.PersistenceException: org.hibernate.PropertyAccessException: Exception occurred inside setter of my.Class 根本原因: javax.persistence.PersistenceException: org.hibernate.PropertyAccessException: Exception occurred inside setter of my.Class 码: @ManyToMany(fetch = FetchType.EAGER) public void setTags(Set tags) { this.tags.clear(); for (Tag tag : tags) { addTag(tag); } } public boolean addTag(final Tag tag) { if (tags.contains(tag)) { return false; } […]

如何在JSR 310中处理大写或小写?

如果一个月是UPPER或小写,即不是Title情况,则DateTimeFormatter无法解析日期。 有没有一种简单的方法可以将日期转换为标题案例,还是一种使格式化程序更宽松的方法? for (String date : “15-JAN-12, 15-Jan-12, 15-jan-12, 15-01-12”.split(“, “)) { try { System.out.println(date + ” => ” + LocalDate.parse(date, DateTimeFormatter.ofPattern(“yy-MMM-dd”))); } catch (Exception e) { System.out.println(date + ” => ” + e); } } 版画 15-JAN-12 => java.time.format.DateTimeParseException: Text ’15-JAN-12′ could not be parsed at index 3 15-Jan-12 => 2015-01-12 15-01-12 => java.time.format.DateTimeParseException: […]

在解析之前确定String是否是有效日期

我有这种情况,我正在阅读包含存储为字符串字段的日期的130K记录。 有些记录包含空格(nulls),有些包含这样的字符串:’dd-MMM-yy’,有些包含’dd / MM / yyyy’。 我写了一个像这样的方法: public Date parsedate(String date){ if(date !== null){ try{ 1. create a SimpleDateFormat object using ‘dd-MMM-yy’ as the pattern 2. parse the date 3. return the parsed date }catch(ParseException e){ try{ 1. create a SimpleDateFormat object using ‘dd/MM/yyy’ as the pattern 2. parse the date 3. return parsed date […]

使用Java和readLine()回车和换行

我使用以下代码建立HTTP连接并读取数据: con = (HttpURLConnection) new URL(“http://stream.twitter.com/1/statuses/sample.json”).openConnection(); … con.connect(); while (line = rd.readLine()) { if (line.contains(“\r\n”)) { System.out.println(“Carriage return + new line”); } } 但是,似乎“\ r \ n”不是字符串( line )的一部分,尽管服务器确实返回它们。 如何读取数据并检测“\ r \ n”? 谢谢, 乔尔

如何通过java在sqlite中插入日期

我想创建一个将在其中保存日期的数据库(SQLite)。 现在首先要问的是声明日期列的正确语法是什么。 第二个我想知道的是如何在此之后插入日期。 我想知道的第三件事是如何在两者之间选择日期,例如选择包含01/05/2010和05/06/2010之间日期的所有行。 谢谢

Java:使用nio Files.copy移动目录

我是nio类的新手,无法将文件目录移动到新创建的目录中。 我先创建2个目录: File sourceDir = new File(sourceDirStr); //this directory already exists File destDir = new File(destDirectoryStr); //this is a new directory 然后我尝试将现有文件复制到新目录中,使用: Path destPath = destDir.toPath(); for (int i = 0; i < sourceSize; i++) { Path sourcePath = sourceDir.listFiles()[i].toPath(); Files.copy(sourcePath, destPath.resolve(sourcePath.getFileName())); } 这会引发以下错误: Exception in thread “main” java.nio.file.FileSystemException: destDir/Experiment.log: Not a directory 我知道destDir/Experiment.log不是现有目录; 它应该是Files.copy操作的结果的新文件。 […]

将.class转换为.java

我有一些.class文件,我需要转换为.java所以我做了: javap -c ClassName.class 而且我一直有同样的错误 错误:找不到ClassName.class 你们有什么可能的原因吗? 我做了man javap,据我所知,语法是正确的。 如果有另一种方法将其转换为.java文件,我非常愿意尝试。 非常感谢任何想法?

没有默认构造函数的jackson第三方类

我正在尝试使用Jackson来读取/写入我的POJO来自Json。 截至目前,除了第三方课程外,我已经为我的课程配置并工作了。 当试图读入Json我得到错误: org.codehaus.jackson.map.JsonMappingException: No suitable constructor found for type 经过一些快速谷歌搜索后,我的类似乎需要一个默认构造函数或覆盖带注释的默认构造函数 。 不幸的是,失败的类来自第三方库,并且该类没有默认构造函数,我显然无法覆盖代码。 所以我的问题是,我能做些什么或者我运气不好吗? 谢谢。

如何在String中获取jsch shell命令输出

我使用JSCH -SSH库在“shell”通道中执行命令,但无法找到办法做两件事: – 1)如何查找命令是否在远程unix盒上完全执行? 2)如何捕获String中的命令输出,而不是在System.out控制台上打印它? 下面是我的代码片段,可以在system.out上显示shell命令输出 注意:我不想使用“exec”通道,因为它为每个命令启动一个新进程,并且不记得导出的“会话”变量。 我必须使用“shell”频道。 下面是我的代码片段。 任何帮助表示赞赏。谢谢你的时间。 try{ String commandToRun = “ls /tmp/*.log \n”; if(channel.isClosed()) channel=session.openChannel(“shell”); byte[] bytes = commandToRun.getBytes(); ByteArrayInputStream bais=new ByteArrayInputStream(bytes); channel.setInputStream(bais); InputStream ins=channel.getInputStream(); channel.connect(); channel.setOutputStream(System.out);//This prints on console. Need 2 capture in String somehow? //in-efficient way to allow command to execute completely on remote Unix machine //DO NOT know […]