Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions src/main/java/fi/solita/clamav/ClamAVClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public class ClamAVClient {
private static final int CHUNK_SIZE = 2048;
private static final int DEFAULT_TIMEOUT = 500;
private static final int PONG_REPLY_LEN = 4;
private static final int VERSION_REPLY_LEN = 256;

/**
* @param hostName The hostname of the server running clamav-daemon
Expand Down Expand Up @@ -66,6 +67,28 @@ public boolean ping() throws IOException {
}
}

/**
* Run VERSION command to clamd.
*
* @return Version string that the server responded with.
*/
public boolean version() throws IOException {
try (Socket s = new Socket(hostName,port); OutputStream outs = s.getOutputStream()) {
s.setSoTimeout(timeout);
outs.write(asBytes("zVERSION\0"));
outs.flush();
byte[] b = new byte[VERSION_REPLY_LEN];
InputStream inputStream = s.getInputStream();
int copyIndex = 0;
int readResult;
do {
readResult = inputStream.read(b, copyIndex, Math.max(b.length - copyIndex, 0));
copyIndex += readResult;
} while (readResult > 0);
return new String(b, StandardCharsets.UTF_8);
}
}

/**
* Streams the given data to the server in chunks. The whole data is not kept in memory.
* This method is preferred if you don't want to keep the data in memory, for instance by scanning a file on disk.
Expand Down