< prev index next >

src/java.desktop/share/classes/sun/awt/datatransfer/DataTransferer.java

Print this page




 700                     }
 701                 }
 702                 if (match) {
 703                     buf[j++] = '\n';
 704                     i += eoln_arr.length;
 705                 } else {
 706                     buf[j++] = buf[i++];
 707                 }
 708             }
 709             converted = new String(buf, 0, j);
 710         }
 711 
 712         return converted;
 713     }
 714 
 715 
 716     /**
 717      * Primary translation function for translating a Transferable into
 718      * a byte array, given a source DataFlavor and target format.
 719      */

 720     public byte[] translateTransferable(Transferable contents,
 721                                         DataFlavor flavor,
 722                                         long format) throws IOException
 723     {
 724         // Obtain the transfer data in the source DataFlavor.
 725         //
 726         // Note that we special case DataFlavor.plainTextFlavor because
 727         // StringSelection supports this flavor incorrectly -- instead of
 728         // returning an InputStream as the DataFlavor representation class
 729         // states, it returns a Reader. Instead of using this broken
 730         // functionality, we request the data in stringFlavor (the other
 731         // DataFlavor which StringSelection supports) and use the String
 732         // translator.
 733         Object obj;
 734         boolean stringSelectionHack;
 735         try {
 736             obj = contents.getTransferData(flavor);
 737             if (obj == null) {
 738                 return null;
 739             }


1261             if (!isImageFormat(format)) {
1262                 throw new IOException("data translation failed");
1263             }
1264 
1265             theObject = platformImageBytesToImage(bytes, format);
1266         }
1267 
1268         if (theObject == null) {
1269             throw new IOException("data translation failed");
1270         }
1271 
1272         return theObject;
1273 
1274     }
1275 
1276     /**
1277      * Primary translation function for translating
1278      * an InputStream into an Object, given a source format and a target
1279      * DataFlavor.
1280      */

1281     public Object translateStream(InputStream str, DataFlavor flavor,
1282                                   long format, Transferable localeTransferable)
1283         throws IOException
1284     {
1285 
1286         Object theObject = null;
1287         // Source data is a URI list. Convert to DataFlavor.javaFileListFlavor
1288         // where possible.
1289         if (isURIListFormat(format)
1290                 && DataFlavor.javaFileListFlavor.equals(flavor))
1291         {
1292 
1293             URI uris[] = dragQueryURIs(str, format, localeTransferable);
1294             if (uris == null) {
1295                 return null;
1296             }
1297             List<File> files = new ArrayList<>();
1298             for (URI uri : uris) {
1299                 try {
1300                     files.add(new File(uri));




 700                     }
 701                 }
 702                 if (match) {
 703                     buf[j++] = '\n';
 704                     i += eoln_arr.length;
 705                 } else {
 706                     buf[j++] = buf[i++];
 707                 }
 708             }
 709             converted = new String(buf, 0, j);
 710         }
 711 
 712         return converted;
 713     }
 714 
 715 
 716     /**
 717      * Primary translation function for translating a Transferable into
 718      * a byte array, given a source DataFlavor and target format.
 719      */
 720     @SuppressWarnings("deprecation")
 721     public byte[] translateTransferable(Transferable contents,
 722                                         DataFlavor flavor,
 723                                         long format) throws IOException
 724     {
 725         // Obtain the transfer data in the source DataFlavor.
 726         //
 727         // Note that we special case DataFlavor.plainTextFlavor because
 728         // StringSelection supports this flavor incorrectly -- instead of
 729         // returning an InputStream as the DataFlavor representation class
 730         // states, it returns a Reader. Instead of using this broken
 731         // functionality, we request the data in stringFlavor (the other
 732         // DataFlavor which StringSelection supports) and use the String
 733         // translator.
 734         Object obj;
 735         boolean stringSelectionHack;
 736         try {
 737             obj = contents.getTransferData(flavor);
 738             if (obj == null) {
 739                 return null;
 740             }


1262             if (!isImageFormat(format)) {
1263                 throw new IOException("data translation failed");
1264             }
1265 
1266             theObject = platformImageBytesToImage(bytes, format);
1267         }
1268 
1269         if (theObject == null) {
1270             throw new IOException("data translation failed");
1271         }
1272 
1273         return theObject;
1274 
1275     }
1276 
1277     /**
1278      * Primary translation function for translating
1279      * an InputStream into an Object, given a source format and a target
1280      * DataFlavor.
1281      */
1282     @SuppressWarnings("deprecation")
1283     public Object translateStream(InputStream str, DataFlavor flavor,
1284                                   long format, Transferable localeTransferable)
1285         throws IOException
1286     {
1287 
1288         Object theObject = null;
1289         // Source data is a URI list. Convert to DataFlavor.javaFileListFlavor
1290         // where possible.
1291         if (isURIListFormat(format)
1292                 && DataFlavor.javaFileListFlavor.equals(flavor))
1293         {
1294 
1295             URI uris[] = dragQueryURIs(str, format, localeTransferable);
1296             if (uris == null) {
1297                 return null;
1298             }
1299             List<File> files = new ArrayList<>();
1300             for (URI uri : uris) {
1301                 try {
1302                     files.add(new File(uri));


< prev index next >