You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by gg...@apache.org on 2024/08/18 20:40:31 UTC

(httpcomponents-client) branch master updated: Reimplement LoggingInputStream as a FilterInputStream

This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/httpcomponents-client.git


The following commit(s) were added to refs/heads/master by this push:
     new 66a355c99 Reimplement LoggingInputStream as a FilterInputStream
66a355c99 is described below

commit 66a355c991203bb7c29b744edf72de93d0764d75
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sat Aug 17 15:03:57 2024 -0400

    Reimplement LoggingInputStream as a FilterInputStream
    
    - No need to track delegate, it's in super
    - Constructor shouldn't be public since the class is package-private
    - Normalize message in available() to match other methods
    - Inherit mark/reset behavior which we don't use anyway
    - skip() uses "in" like other methods for consistency
---
 .../client5/http/impl/io/LoggingInputStream.java   | 31 +++++++---------------
 1 file changed, 9 insertions(+), 22 deletions(-)

diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/LoggingInputStream.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/LoggingInputStream.java
index 69aded2bb..34af67a02 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/LoggingInputStream.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/LoggingInputStream.java
@@ -27,19 +27,21 @@
 
 package org.apache.hc.client5.http.impl.io;
 
+import java.io.FilterInputStream;
 import java.io.IOException;
 import java.io.InputStream;
 
 import org.apache.hc.client5.http.impl.Wire;
 
-class LoggingInputStream extends InputStream {
+/**
+ * Delegates {@link InputStream} calls and logs to a {@link Wire}.
+ */
+class LoggingInputStream extends FilterInputStream {
 
-    private final InputStream in;
     private final Wire wire;
 
-    public LoggingInputStream(final InputStream in, final Wire wire) {
-        super();
-        this.in = in;
+    LoggingInputStream(final InputStream in, final Wire wire) {
+        super(in);
         this.wire = wire;
     }
 
@@ -94,7 +96,7 @@ class LoggingInputStream extends InputStream {
     @Override
     public long skip(final long n) throws IOException {
         try {
-            return super.skip(n);
+            return in.skip(n);
         } catch (final IOException ex) {
             wire.input("[skip] I/O error: " + ex.getMessage());
             throw ex;
@@ -106,26 +108,11 @@ class LoggingInputStream extends InputStream {
         try {
             return in.available();
         } catch (final IOException ex) {
-            wire.input("[available] I/O error : " + ex.getMessage());
+            wire.input("[available] I/O error: " + ex.getMessage());
             throw ex;
         }
     }
 
-    @Override
-    public void mark(final int readlimit) {
-        super.mark(readlimit);
-    }
-
-    @Override
-    public void reset() throws IOException {
-        super.reset();
-    }
-
-    @Override
-    public boolean markSupported() {
-        return false;
-    }
-
     @Override
     public void close() throws IOException {
         try {