From 5a7766a5a1bdfc71c7d644081c7be83a1a5ca955 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20L=C3=A4ubrich?= Date: Mon, 11 Sep 2023 10:34:01 +0200 Subject: [PATCH] Use a buffered inputstream to read from the socket (#795) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Use a buffered inputstream to read from the socket Currently the read from the socket is not buffered what can slow down reading bytes by byte. This wraps the input stream in the PacketReader in a BufferedInputStream to read larger chuncks of data to improve performance. * Fix codacy warnings Signed-off-by: Jeroen van Erp --------- Signed-off-by: Jeroen van Erp Co-authored-by: Christoph Läubrich Co-authored-by: Jeroen van Erp --- .../java/com/hierynomus/smbj/transport/PacketReader.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/hierynomus/smbj/transport/PacketReader.java b/src/main/java/com/hierynomus/smbj/transport/PacketReader.java index bd2fbe4f..753eb88f 100644 --- a/src/main/java/com/hierynomus/smbj/transport/PacketReader.java +++ b/src/main/java/com/hierynomus/smbj/transport/PacketReader.java @@ -15,6 +15,7 @@ */ package com.hierynomus.smbj.transport; +import java.io.BufferedInputStream; import java.io.InputStream; import java.util.concurrent.atomic.AtomicBoolean; @@ -35,7 +36,11 @@ public abstract class PacketReader> implements Runnable private Thread thread; public PacketReader(String host, InputStream in, PacketReceiver handler) { - this.in = in; + if (in instanceof BufferedInputStream) { + this.in = in; + } else { + this.in = new BufferedInputStream(in); + } this.handler = handler; this.thread = new Thread(this, "Packet Reader for " + host); this.thread.setDaemon(true);