You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by fa...@apache.org on 2023/03/25 00:47:16 UTC
svn commit: r1908700 - /poi/trunk/poi/src/main/java/org/apache/poi/util/IOUtils.java
Author: fanningpj
Date: Sat Mar 25 00:47:15 2023
New Revision: 1908700
URL: http://svn.apache.org/viewvc?rev=1908700&view=rev
Log:
don't share the skip bytes buffer
Modified:
poi/trunk/poi/src/main/java/org/apache/poi/util/IOUtils.java
Modified: poi/trunk/poi/src/main/java/org/apache/poi/util/IOUtils.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/util/IOUtils.java?rev=1908700&r1=1908699&r2=1908700&view=diff
==============================================================================
--- poi/trunk/poi/src/main/java/org/apache/poi/util/IOUtils.java (original)
+++ poi/trunk/poi/src/main/java/org/apache/poi/util/IOUtils.java Sat Mar 25 00:47:15 2023
@@ -46,7 +46,6 @@ public final class IOUtils {
* The default buffer size to use for the skip() methods.
*/
private static final int SKIP_BUFFER_SIZE = 2048;
- private static byte[] SKIP_BYTE_BUFFER;
/**
* The current set global allocation limit override,
@@ -520,18 +519,12 @@ public final class IOUtils {
if (toSkip == 0) {
return 0L;
}
- /*
- * N.B. no need to synchronize this because: - we don't care if the buffer is created multiple times (the data
- * is ignored) - we always use the same size buffer, so if it is recreated it will still be OK (if the buffer
- * size were variable, we would need to synch. to ensure some other thread did not create a smaller one)
- */
- if (SKIP_BYTE_BUFFER == null) {
- SKIP_BYTE_BUFFER = new byte[SKIP_BUFFER_SIZE];
- }
+ // use dedicated buffer to avoid having other threads possibly access the bytes in a shared byte array
+ final byte[] skipBuffer = new byte[SKIP_BUFFER_SIZE];
long remain = toSkip;
while (remain > 0) {
// See https://issues.apache.org/jira/browse/IO-203 for why we use read() rather than delegating to skip()
- final long n = input.read(SKIP_BYTE_BUFFER, 0, (int) Math.min(remain, SKIP_BUFFER_SIZE));
+ final long n = input.read(skipBuffer, 0, (int) Math.min(remain, SKIP_BUFFER_SIZE));
if (n < 0) { // EOF
break;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org