IO utilities
Clipboard manipulation
OneConfig no longer provides in-house utilities for managing the user's clipboard; however, we do include Deftu's Copycat library, which uses native code to bypass any issues brought on by certain operating systems (such as macOS disallowing headless apps from using the AWT clipboard API).
Obtaining a clipboard instance
Clipboard clipboard = Clipboard.getInstance();The default implementation of Clipboard uses the natives provided by Copycat. Calling the getInstance method will automatically load the natives should it need to.
Copying and getting strings
String clipboardString = clipboard.getString();
if (clipboardString == null) {
// If the user does not have anything copied, or the copied content
// is not a string (if, f.ex, it's an image), then the `getString`
// method returns null.
return;
}
String newClipboardString = "Hello, OneConfig!";
clipboard.setString(newClipboardString); // Copies our string to the user's clipboardval clipboardString = clipboard.getString()
if (clipboardString == null) {
// If the user does not have anything copied, or the copied content
// is not a string (if, f.ex, it's an image), then the `getString`
// method returns null.
return
}
val newClipboardString = "Hello, OneConfig!"
clipboard.setString(newClipboardString) // Copies our string to the user's clipboardCopying and getting images
By default, ClipboardImage on it's own is simply two ints for the width x height, and an array of bytes for the raw image data. Thus meaning, that should you want to make use of it in any meaningful way, you'll need to convert it to another type for another library OR handle the raw bytes on your own. Thankfully, Copycat provides a means of converting to and from the Java AWT types for you, which you can find below.
Copying AWT images (BufferedImage)
This works vice-versa too!
File checksums (SHA-256 only)
OneConfig provides a single, ease-to-use method for obtaining the checksum of a file at a given path.
Last updated