Fix CapturingOutputStream size accounting 11/104811/2
authorRobert Varga <robert.varga@pantheon.tech>
Thu, 9 Mar 2023 18:02:02 +0000 (19:02 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Thu, 9 Mar 2023 18:54:04 +0000 (19:54 +0100)
Superclass bulk write method is off-loading to the single-byte write
method, leading to us seeing the size as double of what it is.

Rework the class so we forward methods directly, which has the added
benefit of improving performance.

JIRA: YANGTOOLS-745
Change-Id: I725a0771c807228b193eb1cea16abc5725cd70b1
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
plugin/yang-maven-plugin/src/main/java/org/opendaylight/yangtools/yang2sources/plugin/CapturingOutputStream.java

index c66283ddb4212d6195b84464110a24b380a8dc2e..51f773a3cf921e6c07963c1ff2b98972aeea64d2 100644 (file)
@@ -26,13 +26,14 @@ final class CapturingOutputStream extends FilterOutputStream {
     @Override
     @SuppressWarnings("checkstyle:parameterName")
     public void write(final int b) throws IOException {
-        super.write(b);
+        out().write(b);
         size++;
     }
 
     @Override
-    public void write(final byte[] bytes, final int off, final int len) throws IOException {
-        super.write(bytes, off, len);
+    @SuppressWarnings("checkstyle:parameterName")
+    public void write(final byte[] b, final int off, final int len) throws IOException {
+        out().write(b, off, len);
         size += len;
     }
 
@@ -41,6 +42,10 @@ final class CapturingOutputStream extends FilterOutputStream {
     }
 
     int crc32c() {
-        return ((HashingOutputStream) out).hash().asInt();
+        return out().hash().asInt();
+    }
+
+    private HashingOutputStream out() {
+        return (HashingOutputStream) out;
     }
 }