-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathS0065_ClipboardWasher.java
45 lines (36 loc) · 1 KB
/
S0065_ClipboardWasher.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import java.awt.*;
import java.awt.datatransfer.*;
import java.io.IOException;
interface App {
static String readClipboard()
throws Exception {
var cb = Toolkit.getDefaultToolkit().getSystemClipboard();
return (String) cb.getData(DataFlavor.stringFlavor);
}
static void writeClipboard(String content) {
var cb = Toolkit.getDefaultToolkit()
.getSystemClipboard();
cb.setContents(new Transferable() {
@Override
public DataFlavor[] getTransferDataFlavors() {
return new DataFlavor[] {
DataFlavor.stringFlavor
};
}
@Override
public boolean isDataFlavorSupported(DataFlavor flavor) {
return true;
}
@Override
public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException {
return content;
}
}, (c, t) -> {
});
}
static void main(String... args)
throws Exception {
var content = readClipboard();
writeClipboard(content);
}
}