code: public byte[] scan(InputStream is) throws IOException {
      try (Socket s = new Socket(hostName,port); OutputStream outs = new BufferedOutputStream(s.getOutputStream())) {
        s.setSoTimeout(timeout); 
        
        // handshake
        outs.write(asBytes("zINSTREAM\0"));
        outs.flush();
        byte[] chunk = new byte[CHUNK_SIZE];
  
        try (InputStream clamIs = s.getInputStream()) {
          // send data
          int read = is.read(chunk);
          while (read >= 0) {
            // The format of the chunk is: '<length><data>' where <length> is the size of the following data in bytes expressed as a 4 byte unsigned
            // integer in network byte order and <data> is the actual chunk. Streaming is terminated by sending a zero-length chunk.
            byte[] chunkSize = ByteBuffer.allocate(4).putInt(read).array();
  
            outs.write(chunkSize);
            outs.write(chunk, 0, read);
            if (clamIs.available() > 0) {
              // reply from server before scan command has been terminated. 
              byte[] reply = assertSizeLimit(readAll(clamIs));
              throw new IOException("Scan aborted. Reply from server: " + new String(reply, StandardCharsets.US_ASCII));
            }
            read = is.read(chunk);
          }
  
          // terminate scan
          outs.write(new byte[]{0,0,0,0});
          outs.flush();
          // read reply
          return assertSizeLimit(readAll(clamIs));
        }
      } 
    }
docs: 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.
  Since the parameter InputStream is not reset, you can not use the stream afterwards, as it will be left in a EOF-state.
  If your goal is to scan some data, and then pass that data further, consider using {@link #scan(byte[]) scan(byte[] in)}.
  <p>
  Opens a socket and reads the reply. Parameter input stream is NOT closed.
  
  @param is data to scan. Not closed by this method!
  @return server reply