Skip to content

Commit

Permalink
Use a buffered inputstream to read from the socket (#795)
Browse files Browse the repository at this point in the history
* 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 <jeroen@hierynomus.com>

---------

Signed-off-by: Jeroen van Erp <jeroen@hierynomus.com>
Co-authored-by: Christoph Läubrich <christoph@laeubi-soft.de>
Co-authored-by: Jeroen van Erp <jeroen@hierynomus.com>
  • Loading branch information
3 people committed Sep 11, 2023
1 parent c9ab3d8 commit 5a7766a
Showing 1 changed file with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package com.hierynomus.smbj.transport;

import java.io.BufferedInputStream;
import java.io.InputStream;
import java.util.concurrent.atomic.AtomicBoolean;

Expand All @@ -35,7 +36,11 @@ public abstract class PacketReader<D extends PacketData<?>> implements Runnable
private Thread thread;

public PacketReader(String host, InputStream in, PacketReceiver<D> 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);
Expand Down

0 comments on commit 5a7766a

Please sign in to comment.