]> source.dussan.org Git - poi.git/commitdiff
bug 52949: fix forbidden apis
authorJaven O'Neal <onealj@apache.org>
Mon, 11 Apr 2016 01:26:09 +0000 (01:26 +0000)
committerJaven O'Neal <onealj@apache.org>
Mon, 11 Apr 2016 01:26:09 +0000 (01:26 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1738499 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/poi/util/RLEDecompressingInputStream.java
src/testcases/org/apache/poi/util/TestRLEDecompressingInputStream.java

index b8a858702125687f461bfd0ef44aeba8ab1f49ae..5975bc55d23d1dc99a888dee77ba085b09eb6d7c 100644 (file)
@@ -19,6 +19,7 @@ package org.apache.poi.util;
 
 import java.io.IOException;
 import java.io.InputStream;
+import java.util.Locale;
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 
@@ -74,7 +75,7 @@ public class RLEDecompressingInputStream extends InputStream {
         pos = 0;
         int header = in.read();
         if (header != 0x01) {
-            throw new IllegalArgumentException(String.format("Header byte 0x01 expected, received 0x%02X", header & 0xFF));
+            throw new IllegalArgumentException(String.format(Locale.ROOT, "Header byte 0x01 expected, received 0x%02X", header & 0xFF));
         }
         len = readChunk();
     }
@@ -159,12 +160,12 @@ public class RLEDecompressingInputStream extends InputStream {
         }
         int chunkSize = (w & 0x0FFF) + 1; // plus 3 bytes minus 2 for the length
         if ((w & 0x7000) != 0x3000) {
-            throw new IllegalArgumentException(String.format("Chunksize header A should be 0x3000, received 0x%04X", w & 0xE000));
+            throw new IllegalArgumentException(String.format(Locale.ROOT, "Chunksize header A should be 0x3000, received 0x%04X", w & 0xE000));
         }
         boolean rawChunk = (w & 0x8000) == 0;
         if (rawChunk) {
             if (in.read(buf, 0, chunkSize) < chunkSize) {
-                throw new IllegalStateException(String.format("Not enough bytes read, expected %d", chunkSize));
+                throw new IllegalStateException(String.format(Locale.ROOT, "Not enough bytes read, expected %d", chunkSize));
             }
             return chunkSize;
         } else {
index 6693ab2d47b34b7e91480becbebd20e4bab8e262..ae2a07cc8b4c7dd83d51a8a8438fd16064536c05 100644 (file)
@@ -24,6 +24,8 @@ import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.UnsupportedEncodingException;
+import java.nio.charset.Charset;
 
 import org.junit.Test;
 
@@ -142,7 +144,7 @@ public class TestRLEDecompressingInputStream {
             0x01, 0x03, (byte)0xB0, 0x02, 0x61, 0x45, 0x00
         };
         final byte[] expanded = RLEDecompressingInputStream.decompress(compressed);
-        final byte[] expected = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa".getBytes();
+        final byte[] expected = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa".getBytes(StringUtil.UTF8);
         assertArrayEquals(expected, expanded);
     }
     
@@ -160,7 +162,12 @@ public class TestRLEDecompressingInputStream {
         } catch (final IOException e) {
             throw new RuntimeException(e);
         }
-        
-        assertEquals(expected, out.toString());
+        String expanded;
+        try {
+            expanded = out.toString(StringUtil.UTF8.name());
+        } catch (final UnsupportedEncodingException e) {
+            throw new RuntimeException(e);
+        }
+        assertEquals(expected, expanded);
     }
 }