use of java.awt.datatransfer.UnsupportedFlavorException in project ACS by ACS-Community.
the class ClipboardHelper method getClipboardContents.
/**
* Get the String in the clipboard.
*
* @return any text found on the Clipboard; if none found, return an
* empty String.
*/
private String getClipboardContents() {
String result = "";
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
//odd: the Object param of getContents is not currently used
Transferable contents = clipboard.getContents(null);
boolean hasTransferableText = (contents != null) && contents.isDataFlavorSupported(DataFlavor.stringFlavor);
if (hasTransferableText) {
try {
result = (String) contents.getTransferData(DataFlavor.stringFlavor);
} catch (UnsupportedFlavorException ex) {
//highly unlikely since we are using a standard DataFlavor
System.out.println(ex);
} catch (IOException ex) {
System.out.println(ex);
}
}
return result;
}
use of java.awt.datatransfer.UnsupportedFlavorException in project jdk8u_jdk by JetBrains.
the class XDataTransferer method dragQueryURIs.
@Override
protected URI[] dragQueryURIs(InputStream stream, long format, Transferable localeTransferable) throws IOException {
String charset = null;
if (localeTransferable != null && isLocaleDependentTextFormat(format) && localeTransferable.isDataFlavorSupported(javaTextEncodingFlavor)) {
try {
charset = new String((byte[]) localeTransferable.getTransferData(javaTextEncodingFlavor), "UTF-8");
} catch (UnsupportedFlavorException cannotHappen) {
}
} else {
charset = getCharsetForTextFormat(format);
}
if (charset == null) {
// Only happens when we have a custom text type.
charset = getDefaultTextCharset();
}
BufferedReader reader = null;
try {
reader = new BufferedReader(new InputStreamReader(stream, charset));
String line;
ArrayList<URI> uriList = new ArrayList<URI>();
URI uri;
while ((line = reader.readLine()) != null) {
try {
uri = new URI(line);
} catch (URISyntaxException uriSyntaxException) {
throw new IOException(uriSyntaxException);
}
uriList.add(uri);
}
return uriList.toArray(new URI[uriList.size()]);
} finally {
if (reader != null)
reader.close();
}
}
use of java.awt.datatransfer.UnsupportedFlavorException in project jdk8u_jdk by JetBrains.
the class HTMLCodec method translateBytes.
@Override
public Object translateBytes(byte[] bytes, DataFlavor flavor, long format, Transferable localeTransferable) throws IOException {
if (format == CF_FILEGROUPDESCRIPTORA || format == CF_FILEGROUPDESCRIPTORW) {
if (bytes == null || !DataFlavor.javaFileListFlavor.equals(flavor)) {
throw new IOException("data translation failed");
}
String st = new String(bytes, 0, bytes.length, "UTF-16LE");
String[] filenames = st.split("\0");
if (0 == filenames.length) {
return null;
}
// Convert the strings to File objects
File[] files = new File[filenames.length];
for (int i = 0; i < filenames.length; ++i) {
files[i] = new File(filenames[i]);
//They are temp-files from memory Stream, so they have to be removed on exit
files[i].deleteOnExit();
}
// Turn the list of Files into a List and return
return Arrays.asList(files);
}
if (format == CFSTR_INETURL && URL.class.equals(flavor.getRepresentationClass())) {
String charset = getDefaultTextCharset();
if (localeTransferable != null && localeTransferable.isDataFlavorSupported(javaTextEncodingFlavor)) {
try {
charset = new String((byte[]) localeTransferable.getTransferData(javaTextEncodingFlavor), "UTF-8");
} catch (UnsupportedFlavorException cannotHappen) {
}
}
return new URL(new String(bytes, charset));
}
return super.translateBytes(bytes, flavor, format, localeTransferable);
}
use of java.awt.datatransfer.UnsupportedFlavorException in project jdk8u_jdk by JetBrains.
the class TargetPanel method drop.
public void drop(DropTargetDropEvent dtde) {
dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
if (dtde.isDataFlavorSupported(dataFlavor)) {
String result = null;
try {
Transferable t = dtde.getTransferable();
byte[] data = (byte[]) dtde.getTransferable().getTransferData(dataFlavor);
result = new String(data, "UTF-16");
repaint();
} catch (UnsupportedFlavorException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
dtde.dropComplete(true);
if (result != null && result.contains(MyTransferable.TEST_DATA)) {
System.err.println(InterprocessMessages.EXECUTION_IS_SUCCESSFULL);
Timer t = new Timer();
t.schedule(new TimerTask() {
@Override
public void run() {
System.exit(0);
}
}, 2000);
return;
}
}
dtde.rejectDrop();
System.err.println(InterprocessMessages.DATA_IS_CORRUPTED);
System.exit(InterprocessMessages.DATA_IS_CORRUPTED);
}
use of java.awt.datatransfer.UnsupportedFlavorException in project jabref by JabRef.
the class ClipBoardManager method getClipboardContents.
/**
* Get the String residing on the clipboard.
*
* @return any text found on the Clipboard; if none found, return an
* empty String.
*/
public String getClipboardContents() {
String result = "";
//odd: the Object param of getContents is not currently used
Transferable contents = CLIPBOARD.getContents(null);
if ((contents != null) && contents.isDataFlavorSupported(DataFlavor.stringFlavor)) {
try {
result = (String) contents.getTransferData(DataFlavor.stringFlavor);
} catch (UnsupportedFlavorException | IOException e) {
//highly unlikely since we are using a standard DataFlavor
LOGGER.info("problem with getting clipboard contents", e);
}
}
return result;
}
Aggregations