bug 52949: fix forbidden apis
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1738499 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
f49047e733
commit
d6252e00b1
@ -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 {
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user