code: public long copyIn(final String sql, InputStream from, int bufferSize)
        throws SQLException, IOException {
      byte[] buf = new byte[bufferSize];
      int len;
      CopyIn cp = copyIn(sql);
      try {
        while ((len = from.read(buf)) >= 0) {
          if (len > 0) {
            cp.writeToCopy(buf, 0, len);
          }
        }
        return cp.endCopy();
      } finally { // see to it that we do not leave the connection locked
        if (cp.isActive()) {
          cp.cancelCopy();
        }
      }
    }
docs: Use COPY FROM STDIN for very fast copying from an InputStream into a database table.
  
  @param sql COPY FROM STDIN statement
  @param from a CSV file or such
  @param bufferSize number of bytes to buffer and push over network to server at once
  @return number of rows updated for server 8.2 or newer; -1 for older
  @throws SQLException on database usage issues
  @throws IOException upon input stream or database connection failure