public static String getClipboardString() {

    final Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
    final Transferable contents = clipboard.getContents(null);

    final boolean hasTransferableText =
        (contents != null) && contents.isDataFlavorSupported(DataFlavor.stringFlavor);
    if (!hasTransferableText) {
      return null;
    }

    try {
      return (String) contents.getTransferData(DataFlavor.stringFlavor);
    } catch (final UnsupportedFlavorException | IOException ex) {
      // Eat, cannot happen as we're checking above
    }

    return null;
  }
Returns the string that is currently stored in the system clipboard.

@return The string from the system clipboard or null if there is no string currently stored in
    the clipboard.
java/zylib/src/main/java/com/google/security/zynamics/zylib/general/ClipboardHelpers.java