Skip to content

Commit

Permalink
Merge pull request #5 from Edmondi-Kacaj/fix_large_files
Browse files Browse the repository at this point in the history
Allow to scan large files
  • Loading branch information
mirjan-hoffmann authored Jan 12, 2024
2 parents 5baee4c + 1ebfb73 commit 0436638
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.InetSocketAddress;
import java.io.InputStream;
import java.net.Socket;
import java.net.SocketException;

Expand All @@ -40,7 +41,7 @@ public final class InStreamScan implements VirusScanMode {

private final Logger logger = Logger.getLogger(InStreamScan.class);

private byte[] data;
private InputStream data;
private int chunkSize = 4096;
private int port;
private String host;
Expand Down Expand Up @@ -111,8 +112,9 @@ public int scan(NodeRef nodeRef) {
*/
@Override
public int scan() throws IOException {
int i = 0;
int bytesRead;
int result = 0;
byte[] buffer = new byte[chunkSize];

/*
* create socket
Expand Down Expand Up @@ -143,16 +145,12 @@ public int scan() throws IOException {
dataOutputStream.writeBytes("zINSTREAM\0");

if (logger.isDebugEnabled()) {
logger.debug(getClass().getName() + "Send stream for " + data.length + " bytes");
logger.debug(getClass().getName() + "Send stream for " + data.available() + " bytes");
}

while (i < data.length) {
if (i + chunkSize >= data.length) {
chunkSize = data.length - i;
}
dataOutputStream.writeInt(chunkSize);
dataOutputStream.write(data, i, chunkSize);
i += chunkSize;
while ((bytesRead = data.read(buffer)) != -1) {
dataOutputStream.writeInt(bytesRead);
dataOutputStream.write(buffer, 0, bytesRead);
}

dataOutputStream.writeInt(0);
Expand All @@ -177,6 +175,9 @@ public int scan() throws IOException {

if (socket != null)
socket.close();

if (data != null)
data.close();
}

/*
Expand Down Expand Up @@ -251,7 +252,7 @@ public void setNodeRef(NodeRef nodeRef) {
/**
* @param data
*/
public void setData(byte[] data) {
public void setData(InputStream data) {
this.data = data;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ else if (mode.toUpperCase().equals(VirusScanMode.ScanModeInStream)) {
inStreamScan.setHost(inStreamHost);
inStreamScan.setPort(inStreamPort);
inStreamScan.setTimeout(inStreamTimeout);
inStreamScan.setData(contentReader.getContentString().getBytes());
inStreamScan.setData(contentReader.getContentInputStream());
res = inStreamScan.scan(nodeRef);
}

Expand Down

0 comments on commit 0436638

Please sign in to comment.