This is an automated email from the ASF dual-hosted git repository.
veithen pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ws-axiom.git
The following commit(s) were added to refs/heads/master by this push:
new 478289546 Optimize TestBlob I/O methods using buffered byte arrays
478289546 is described below
commit 4782895466055ba5d20de697399ab76f91eee4b6
Author: Andreas Veithen-Knowles <[email protected]>
AuthorDate: Sun Feb 1 15:14:08 2026 +0000
Optimize TestBlob I/O methods using buffered byte arrays
- Implement optimized read(byte[], int, int) in getInputStream using
Arrays.fill
- Optimize writeTo to write in 8KB chunks instead of single bytes
- Use Arrays.fill for efficient buffer initialization
---
.../org/apache/axiom/testutils/blob/TestBlob.java | 22 ++++++++++++++++++++--
1 file changed, 20 insertions(+), 2 deletions(-)
diff --git
a/testing/blob-testutils/src/main/java/org/apache/axiom/testutils/blob/TestBlob.java
b/testing/blob-testutils/src/main/java/org/apache/axiom/testutils/blob/TestBlob.java
index ebddf6ebb..a4214e129 100644
---
a/testing/blob-testutils/src/main/java/org/apache/axiom/testutils/blob/TestBlob.java
+++
b/testing/blob-testutils/src/main/java/org/apache/axiom/testutils/blob/TestBlob.java
@@ -22,6 +22,7 @@ package org.apache.axiom.testutils.blob;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
+import java.util.Arrays;
import com.google.common.base.Preconditions;
@@ -62,17 +63,34 @@ public class TestBlob implements Blob {
return value & 0xFF;
}
}
+
+ @Override
+ public int read(byte[] b, int off, int len) throws IOException {
+ long remaining = length - position;
+ if (remaining <= 0) {
+ return -1;
+ }
+ int toRead = (int) Math.min(len, remaining);
+ Arrays.fill(b, off, off + toRead, value);
+ position += toRead;
+ return toRead;
+ }
};
}
@Override
public void writeTo(OutputStream out) throws StreamCopyException {
- for (long i = 0; i < length; i++) {
+ byte[] buf = new byte[(int) Math.min(length, 8192L)];
+ Arrays.fill(buf, value);
+ long remaining = length;
+ while (remaining > 0) {
+ int toWrite = (int) Math.min(remaining, buf.length);
try {
- out.write(value & 0xFF);
+ out.write(buf, 0, toWrite);
} catch (IOException ex) {
throw new StreamCopyException(StreamCopyException.WRITE, ex);
}
+ remaining -= toWrite;
}
}