Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id E8770200C17 for ; Fri, 6 Jan 2017 00:40:59 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id E74A4160B42; Thu, 5 Jan 2017 23:40:59 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 1D2F6160B33 for ; Fri, 6 Jan 2017 00:40:58 +0100 (CET) Received: (qmail 74225 invoked by uid 500); 5 Jan 2017 23:40:58 -0000 Mailing-List: contact commits-help@poi.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@poi.apache.org Delivered-To: mailing list commits@poi.apache.org Received: (qmail 74215 invoked by uid 99); 5 Jan 2017 23:40:58 -0000 Received: from Unknown (HELO svn01-us-west.apache.org) (209.188.14.144) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 05 Jan 2017 23:40:58 +0000 Received: from svn01-us-west.apache.org (localhost [127.0.0.1]) by svn01-us-west.apache.org (ASF Mail Server at svn01-us-west.apache.org) with ESMTP id CCE7A3A03A7 for ; Thu, 5 Jan 2017 23:40:57 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1777526 - in /poi/trunk/src: examples/src/org/apache/poi/hssf/usermodel/examples/EmbeddedObjects.java java/org/apache/poi/poifs/crypt/cryptoapi/CryptoAPIDecryptor.java ooxml/java/org/apache/poi/openxml4j/opc/ZipPackage.java Date: Thu, 05 Jan 2017 23:40:57 -0000 To: commits@poi.apache.org From: kiwiwings@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20170105234057.CCE7A3A03A7@svn01-us-west.apache.org> archived-at: Thu, 05 Jan 2017 23:41:00 -0000 Author: kiwiwings Date: Thu Jan 5 23:40:57 2017 New Revision: 1777526 URL: http://svn.apache.org/viewvc?rev=1777526&view=rev Log: SonarQube fixes Modified: poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/EmbeddedObjects.java poi/trunk/src/java/org/apache/poi/poifs/crypt/cryptoapi/CryptoAPIDecryptor.java poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/ZipPackage.java Modified: poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/EmbeddedObjects.java URL: http://svn.apache.org/viewvc/poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/EmbeddedObjects.java?rev=1777526&r1=1777525&r2=1777526&view=diff ============================================================================== --- poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/EmbeddedObjects.java (original) +++ poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/EmbeddedObjects.java Thu Jan 5 23:40:57 2017 @@ -16,11 +16,10 @@ ==================================================================== */ package org.apache.poi.hssf.usermodel.examples; +import java.io.Closeable; import java.io.FileInputStream; -import java.util.Iterator; import org.apache.poi.hslf.usermodel.HSLFSlideShow; -import org.apache.poi.hslf.usermodel.HSLFSlideShowImpl; import org.apache.poi.hssf.usermodel.HSSFObjectData; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.hwpf.HWPFDocument; @@ -39,26 +38,19 @@ public class EmbeddedObjects { for (HSSFObjectData obj : workbook.getAllEmbeddedObjects()) { //the OLE2 Class Name of the object String oleName = obj.getOLE2ClassName(); + DirectoryNode dn = (obj.hasDirectoryEntry()) ? (DirectoryNode) obj.getDirectory() : null; + Closeable document = null; if (oleName.equals("Worksheet")) { - DirectoryNode dn = (DirectoryNode) obj.getDirectory(); - HSSFWorkbook embeddedWorkbook = new HSSFWorkbook(dn, fs, false); - //System.out.println(entry.getName() + ": " + embeddedWorkbook.getNumberOfSheets()); - embeddedWorkbook.close(); + document = new HSSFWorkbook(dn, fs, false); } else if (oleName.equals("Document")) { - DirectoryNode dn = (DirectoryNode) obj.getDirectory(); - HWPFDocument embeddedWordDocument = new HWPFDocument(dn); - //System.out.println(entry.getName() + ": " + embeddedWordDocument.getRange().text()); + document = new HWPFDocument(dn); } else if (oleName.equals("Presentation")) { - DirectoryNode dn = (DirectoryNode) obj.getDirectory(); - HSLFSlideShow embeddedPowerPointDocument = new HSLFSlideShow(new HSLFSlideShowImpl(dn)); - //System.out.println(entry.getName() + ": " + embeddedPowerPointDocument.getSlides().length); + document = new HSLFSlideShow(dn); } else { - if(obj.hasDirectoryEntry()){ + if(dn != null){ // The DirectoryEntry is a DocumentNode. Examine its entries to find out what it is - DirectoryNode dn = (DirectoryNode) obj.getDirectory(); - for (Iterator entries = dn.getEntries(); entries.hasNext();) { - Entry entry = entries.next(); - //System.out.println(oleName + "." + entry.getName()); + for (Entry entry : dn) { + String name = entry.getName(); } } else { // There is no DirectoryEntry @@ -66,6 +58,9 @@ public class EmbeddedObjects { byte[] objectData = obj.getObjectData(); } } + if (document != null) { + document.close(); + } } workbook.close(); } Modified: poi/trunk/src/java/org/apache/poi/poifs/crypt/cryptoapi/CryptoAPIDecryptor.java URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/poifs/crypt/cryptoapi/CryptoAPIDecryptor.java?rev=1777526&r1=1777525&r2=1777526&view=diff ============================================================================== --- poi/trunk/src/java/org/apache/poi/poifs/crypt/cryptoapi/CryptoAPIDecryptor.java (original) +++ poi/trunk/src/java/org/apache/poi/poifs/crypt/cryptoapi/CryptoAPIDecryptor.java Thu Jan 5 23:40:57 2017 @@ -53,10 +53,10 @@ public class CryptoAPIDecryptor extends private long length = -1L; private int chunkSize = -1; - + static class StreamDescriptorEntry { static BitField flagStream = BitFieldFactory.getInstance(1); - + int streamOffset; int streamSize; int block; @@ -149,17 +149,16 @@ public class CryptoAPIDecryptor extends throws IOException, GeneralSecurityException { return new CryptoAPICipherInputStream(stream, size, initialPos); } - + /** * Decrypt the Document-/SummaryInformation and other optionally streams. * Opposed to other crypto modes, cryptoapi is record based and can't be used * to stream-decrypt a whole file - * + * * @see 2.3.5.4 RC4 CryptoAPI Encrypted Summary Stream */ public POIFSFileSystem getSummaryEntries(DirectoryNode root, String encryptedStream) throws IOException, GeneralSecurityException { - POIFSFileSystem fsOut = new POIFSFileSystem(); // HSLF: encryptedStream // HSSF: encryption DocumentNode es = (DocumentNode) root.getEntry(encryptedStream); @@ -169,6 +168,7 @@ public class CryptoAPIDecryptor extends dis.close(); CryptoAPIDocumentInputStream sbis = new CryptoAPIDocumentInputStream(this, bos.toByteArray()); LittleEndianInputStream leis = new LittleEndianInputStream(sbis); + POIFSFileSystem fsOut = null; try { int streamDescriptorArrayOffset = (int) leis.readUInt(); /* int streamDescriptorArraySize = (int) */ leis.readUInt(); @@ -193,7 +193,8 @@ public class CryptoAPIDecryptor extends leis.readShort(); assert(entry.streamName.length() == nameSize); } - + + fsOut = new POIFSFileSystem(); for (StreamDescriptorEntry entry : entries) { sbis.seek(entry.streamOffset); sbis.setBlock(entry.block); @@ -201,11 +202,19 @@ public class CryptoAPIDecryptor extends fsOut.createDocument(is, entry.streamName); is.close(); } + } catch (Exception e) { + IOUtils.closeQuietly(fsOut); + if (e instanceof GeneralSecurityException) { + throw (GeneralSecurityException)e; + } else if (e instanceof IOException) { + throw (IOException)e; + } else { + throw new IOException("summary entries can't be read", e); + } } finally { IOUtils.closeQuietly(leis); IOUtils.closeQuietly(sbis); } - sbis = null; return fsOut; } @@ -220,10 +229,11 @@ public class CryptoAPIDecryptor extends return length; } + @Override public void setChunkSize(int chunkSize) { this.chunkSize = chunkSize; } - + @Override public CryptoAPIDecryptor clone() throws CloneNotSupportedException { return (CryptoAPIDecryptor)super.clone(); @@ -240,6 +250,6 @@ public class CryptoAPIDecryptor extends public CryptoAPICipherInputStream(InputStream stream, long size, int initialPos) throws GeneralSecurityException { super(stream, size, chunkSize, initialPos); - } + } } } Modified: poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/ZipPackage.java URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/ZipPackage.java?rev=1777526&r1=1777525&r2=1777526&view=diff ============================================================================== --- poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/ZipPackage.java (original) +++ poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/ZipPackage.java Thu Jan 5 23:40:57 2017 @@ -131,7 +131,7 @@ public final class ZipPackage extends OP ZipEntrySource ze; try { - final ZipFile zipFile = ZipHelper.openZipFile(file); + final ZipFile zipFile = ZipHelper.openZipFile(file); // NOSONAR ze = new ZipFileZipEntrySource(zipFile); } catch (IOException e) { // probably not happening with write access - not sure how to handle the default read-write access ... @@ -149,7 +149,7 @@ public final class ZipPackage extends OP // Acquire a resource that is needed to read the next level of openZipEntrySourceStream try { // open the file input stream - fis = new FileInputStream(file); + fis = new FileInputStream(file); // NOSONAR } catch (final FileNotFoundException e) { // If the source cannot be acquired, abort (no resources to free at this level) throw new InvalidOperationException("Can't open the specified file input stream from file: '" + file + "'", e); @@ -175,7 +175,7 @@ public final class ZipPackage extends OP // Acquire a resource that is needed to read the next level of openZipEntrySourceStream try { // open the zip input stream - zis = ZipHelper.openZipStream(fis); + zis = ZipHelper.openZipStream(fis); // NOSONAR } catch (final IOException e) { // If the source cannot be acquired, abort (no resources to free at this level) throw new InvalidOperationException("Could not open the file input stream", e); --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org For additional commands, e-mail: commits-help@poi.apache.org