1 10 11 import java.io.*; 12 import javax.activation.*; 13 import java.awt.datatransfer.*; 14 15 public class DCHTest { 16 private FileDataSource fds = null; 17 private DataHandler dh = null; 18 private DataContentHandlerFactory dchf = null; 19 22 public static void main(String args[]) { 23 DCHTest test = new DCHTest(); 24 25 if(args.length == 0) { 26 System.out.println("usage: DCHTest file.txt"); 27 System.exit(1); 28 } 29 30 32 test.setFile(args[0]); 33 34 test.doit(); 35 } 36 37 private void doit() { 38 DataFlavor xfer_flavors[]; 39 Object content = null; 40 41 dh = new DataHandler(fds); 43 System.out.println("DCHTest: DataHandler created"); 44 45 dchf = new SimpleDCF("text/plain:PlainDCH\n"); 47 System.out.println("DCHTest: Simple dchf created"); 48 49 dh.setDataContentHandlerFactory(dchf); 51 System.out.println("DCHTest: DataContentHandlerFactory set in DataHandler"); 52 53 xfer_flavors = dh.getTransferDataFlavors(); 55 System.out.println("DCHTest: dh.getTransferDF returned " + 56 xfer_flavors.length + " data flavors."); 57 58 try { 60 content = dh.getContent(); 61 } catch (Exception e) { e.printStackTrace(); } 62 63 if(content == null) 64 System.out.println("DCHTest: no content to be had!!!"); 65 else 66 System.out.println("DCHTest: got content of the following type: " + 67 content.getClass().getName()); 68 69 } 70 71 74 public void setFile(String filename) { 75 fds = new FileDataSource(filename); 76 System.out.println("DCHTest: FileDataSource created"); 77 if(!fds.getContentType().equals("text/plain")) { 78 System.out.println("Type must be text/plain"); 79 System.exit(1); 80 } 81 } 82 83 } 84 85 86 | Popular Tags |