poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kiwiwi...@apache.org
Subject svn commit: r1769363 [2/2] - in /poi/trunk/src: examples/src/org/apache/poi/crypt/examples/ examples/src/org/apache/poi/examples/util/ examples/src/org/apache/poi/xssf/eventusermodel/examples/ examples/src/org/apache/poi/xssf/streaming/examples/ exampl...
Date Fri, 11 Nov 2016 23:22:43 GMT
Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/streaming/TestSXSSFWorkbookWithCustomZipEntrySource.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/streaming/TestSXSSFWorkbookWithCustomZipEntrySource.java?rev=1769363&r1=1769362&r2=1769363&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/streaming/TestSXSSFWorkbookWithCustomZipEntrySource.java
(original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/streaming/TestSXSSFWorkbookWithCustomZipEntrySource.java
Fri Nov 11 23:22:43 2016
@@ -27,31 +27,19 @@ import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.FileInputStream;
-import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
-import java.io.OutputStream;
 import java.nio.charset.Charset;
 import java.security.GeneralSecurityException;
-import java.security.SecureRandom;
 import java.util.List;
 
-import javax.crypto.Cipher;
-import javax.crypto.CipherInputStream;
-import javax.crypto.CipherOutputStream;
-import javax.crypto.spec.SecretKeySpec;
-
 import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
 import org.apache.poi.openxml4j.opc.OPCPackage;
 import org.apache.poi.openxml4j.util.ZipEntrySource;
-import org.apache.poi.poifs.crypt.AesZipFileZipEntrySource;
-import org.apache.poi.poifs.crypt.ChainingMode;
-import org.apache.poi.poifs.crypt.CipherAlgorithm;
-import org.apache.poi.poifs.crypt.CryptoFunctions;
+import org.apache.poi.poifs.crypt.temp.AesZipFileZipEntrySource;
+import org.apache.poi.poifs.crypt.temp.EncryptedTempData;
+import org.apache.poi.poifs.crypt.temp.SXSSFWorkbookWithCustomZipEntrySource;
 import org.apache.poi.util.IOUtils;
-import org.apache.poi.util.POILogFactory;
-import org.apache.poi.util.POILogger;
-import org.apache.poi.util.TempFile;
 import org.apache.poi.xssf.usermodel.XSSFCell;
 import org.apache.poi.xssf.usermodel.XSSFRow;
 import org.apache.poi.xssf.usermodel.XSSFSheet;
@@ -145,104 +133,4 @@ public final class TestSXSSFWorkbookWith
         workbook.dispose();
         assertFalse("tempFile deleted after dispose?", tempFile.exists());
     }
-    
-    static class SXSSFWorkbookWithCustomZipEntrySource extends SXSSFWorkbook {
-
-        private static final POILogger logger = POILogFactory.getLogger(SXSSFWorkbookWithCustomZipEntrySource.class);
-
-        @Override
-        public void write(OutputStream stream) throws IOException {
-            flushSheets();
-            EncryptedTempData tempData = new EncryptedTempData();
-            OutputStream os = tempData.getOutputStream();
-            getXSSFWorkbook().write(os);
-            os.close();
-            ZipEntrySource source = null;
-            try {
-                // provide ZipEntrySource to poi which decrypts on the fly
-                source = AesZipFileZipEntrySource.createZipEntrySource(tempData.getInputStream());
-                injectData(source, stream);
-            } catch (GeneralSecurityException e) {
-                throw new IOException(e);
-            } finally {
-                tempData.dispose();
-                IOUtils.closeQuietly(source);
-            }
-        }
-
-        @Override
-        protected SheetDataWriter createSheetDataWriter() throws IOException {
-            //log values to ensure these values are accessible to subclasses
-            logger.log(POILogger.INFO, "isCompressTempFiles: " + isCompressTempFiles());
-            logger.log(POILogger.INFO, "SharedStringSource: " + getSharedStringSource());
-            return new SheetDataWriterWithDecorator();
-        }
-    }
-    
-    static class SheetDataWriterWithDecorator extends SheetDataWriter {
-        final static CipherAlgorithm cipherAlgorithm = CipherAlgorithm.aes128;
-        SecretKeySpec skeySpec;
-        byte[] ivBytes;
-
-        public SheetDataWriterWithDecorator() throws IOException {
-            super();
-        }
-
-        void init() {
-            if(skeySpec == null) {
-                SecureRandom sr = new SecureRandom();
-                ivBytes = new byte[16];
-                byte[] keyBytes = new byte[16];
-                sr.nextBytes(ivBytes);
-                sr.nextBytes(keyBytes);
-                skeySpec = new SecretKeySpec(keyBytes, cipherAlgorithm.jceId);
-            }
-        }
-        
-        @Override
-        protected OutputStream decorateOutputStream(FileOutputStream fos) {
-            init();
-            Cipher ciEnc = CryptoFunctions.getCipher(skeySpec, cipherAlgorithm, ChainingMode.cbc,
ivBytes, Cipher.ENCRYPT_MODE, "PKCS5Padding");
-            return new CipherOutputStream(fos, ciEnc);
-        }
-
-        @Override
-        protected InputStream decorateInputStream(FileInputStream fis) {
-            Cipher ciDec = CryptoFunctions.getCipher(skeySpec, cipherAlgorithm, ChainingMode.cbc,
ivBytes, Cipher.DECRYPT_MODE, "PKCS5Padding");
-            return new CipherInputStream(fis, ciDec);
-        }
-    }
-    
-    // a class to save and read an AES-encrypted workbook
-    static class EncryptedTempData {
-        final static CipherAlgorithm cipherAlgorithm = CipherAlgorithm.aes128;
-        final SecretKeySpec skeySpec;
-        final byte[] ivBytes;
-        final File tempFile;
-        
-        EncryptedTempData() throws IOException {
-            SecureRandom sr = new SecureRandom();
-            ivBytes = new byte[16];
-            byte[] keyBytes = new byte[16];
-            sr.nextBytes(ivBytes);
-            sr.nextBytes(keyBytes);
-            skeySpec = new SecretKeySpec(keyBytes, cipherAlgorithm.jceId);
-            tempFile = TempFile.createTempFile("poi-temp-data", ".tmp");
-        }
-
-        OutputStream getOutputStream() throws IOException {
-            Cipher ciEnc = CryptoFunctions.getCipher(skeySpec, cipherAlgorithm, ChainingMode.cbc,
ivBytes, Cipher.ENCRYPT_MODE, null);
-            return new CipherOutputStream(new FileOutputStream(tempFile), ciEnc);
-        }
-
-        InputStream getInputStream() throws IOException {
-            Cipher ciDec = CryptoFunctions.getCipher(skeySpec, cipherAlgorithm, ChainingMode.cbc,
ivBytes, Cipher.DECRYPT_MODE, null);
-            return new CipherInputStream(new FileInputStream(tempFile), ciDec);
-        }
-        
-        void dispose() {
-            assertTrue("Could not delete tempfile " + tempFile + ": " + tempFile.exists(),
-                    !tempFile.exists() || tempFile.delete());
-        }
-    }
-}
+}
\ No newline at end of file

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hdgf/pointers/PointerV5.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hdgf/pointers/PointerV5.java?rev=1769363&r1=1769362&r2=1769363&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hdgf/pointers/PointerV5.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hdgf/pointers/PointerV5.java Fri Nov 11 23:22:43
2016
@@ -28,14 +28,24 @@ public final class PointerV5 extends Poi
         return (0x40 <= format && format < 0x50);
     }
     public boolean destinationHasPointers() {
-        if(type == 20) return true;
-        if(type == 22) return false;
-        if(format == 0x1d || format == 0x1e) return true;
+        if(type == 20) {
+            return true;
+        }
+        if(type == 22) {
+            return false;
+        }
+        if(format == 0x1d || format == 0x1e) {
+            return true;
+        }
         return (0x50 <= format && format < 0x60);
     }
     public boolean destinationHasChunks() {
-        if (type == 21) return true;
-        if (type == 24) return true;
+        if (type == 21) {
+            return true;
+        }
+        if (type == 24) {
+            return true;
+        }
         return (0xd0 <= format && format < 0xdf);
     }
 

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/blip/PICT.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/blip/PICT.java?rev=1769363&r1=1769362&r2=1769363&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/blip/PICT.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/blip/PICT.java Fri Nov 11 23:22:43 2016
@@ -33,7 +33,7 @@ import org.apache.poi.util.Units;
  * Represents Macintosh PICT picture data.
  */
 public final class PICT extends Metafile {
-    private static POILogger LOG = POILogFactory.getLogger(PICT.class);
+    private static final POILogger LOG = POILogFactory.getLogger(PICT.class);
     
     public static class NativeHeader {
         /**

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFFreeformShape.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFFreeformShape.java?rev=1769363&r1=1769362&r2=1769363&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFFreeformShape.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFFreeformShape.java Fri
Nov 11 23:22:43 2016
@@ -346,7 +346,9 @@ public final class HSLFFreeformShape ext
     }
     
     private void fillPoint(byte xyMaster[], double xyPoints[]) {
-        if (xyMaster == null || xyPoints == null || (xyMaster.length != 4 && xyMaster.length
!= 8) || xyPoints.length != 2) {
+        int masterCnt = (xyMaster == null) ? 0 : xyMaster.length;
+        int pointCnt = (xyPoints == null) ? 0 : xyPoints.length;
+        if ((masterCnt != 4 && masterCnt != 8) || pointCnt != 2) {
             logger.log(POILogger.WARN, "Invalid number of master bytes for a single point
- ignore point");
             return;
         }



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org


Mime
View raw message