diff --git a/src/java/org/apache/poi/util/RLEDecompressingInputStream.java b/src/java/org/apache/poi/util/RLEDecompressingInputStream.java index b8a858702..5975bc55d 100644 --- a/src/java/org/apache/poi/util/RLEDecompressingInputStream.java +++ b/src/java/org/apache/poi/util/RLEDecompressingInputStream.java @@ -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 { diff --git a/src/testcases/org/apache/poi/util/TestRLEDecompressingInputStream.java b/src/testcases/org/apache/poi/util/TestRLEDecompressingInputStream.java index 6693ab2d4..ae2a07cc8 100644 --- a/src/testcases/org/apache/poi/util/TestRLEDecompressingInputStream.java +++ b/src/testcases/org/apache/poi/util/TestRLEDecompressingInputStream.java @@ -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); } }