package ajmas74.experiments; import java.awt.*; import java.awt.datatransfer.*; import java.io.*; import java.io.IOException; /** * @author Andre-John Mas - http://www.geocities.com/ajmas * * A program I quickly threw together to see what the clipboard * contains. */ public class ClipboardViewer { public static void main(String[] args) { Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); Transferable transfer = clipboard.getContents(null); DataFlavor[] flavours = transfer.getTransferDataFlavors(); for ( int i=0; i -1 ) { fOut.write(buffer,0,len); } fOut.close(); } catch ( Exception ex ) { ex.printStackTrace(); } } else if ( flavours[i].getMimeType().startsWith("application/x-pdf") ) { try { data = transfer.getTransferData(flavours[i]); System.out.println("writing"); FileOutputStream fOut = new FileOutputStream("/out.pdf"); InputStream in = (InputStream) data; byte[] buffer = new byte[1024]; int len = -1; while ( (len = in.read(buffer)) > -1 ) { fOut.write(buffer,0,len); } fOut.close(); } catch ( Exception ex ) { ex.printStackTrace(); } } } } }