1 /*
2 * Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
1135 if (filenames == null) {
1136 return null;
1137 }
1138
1139 // Convert the strings to File objects
1140 File[] files = new File[filenames.length];
1141 for (int i = 0; i < filenames.length; i++) {
1142 files[i] = new File(filenames[i]);
1143 }
1144
1145 // Turn the list of Files into a List and return
1146 theObject = Arrays.asList(files);
1147
1148 // Source data is a URI list. Convert to DataFlavor.javaFileListFlavor
1149 // where possible.
1150 } else if (isURIListFormat(format)
1151 && DataFlavor.javaFileListFlavor.equals(flavor)) {
1152
1153 try (ByteArrayInputStream str = new ByteArrayInputStream(bytes)) {
1154
1155 URI uris[] = dragQueryURIs(str, format, localeTransferable);
1156 if (uris == null) {
1157 return null;
1158 }
1159 List<File> files = new ArrayList<>();
1160 for (URI uri : uris) {
1161 try {
1162 files.add(new File(uri));
1163 } catch (IllegalArgumentException illegalArg) {
1164 // When converting from URIs to less generic files,
1165 // common practice (Wine, SWT) seems to be to
1166 // silently drop the URIs that aren't local files.
1167 }
1168 }
1169 theObject = files;
1170 }
1171
1172 // Target data is a String. Strip terminating NUL bytes. Decode bytes
1173 // into characters. Search-and-replace EOLN.
1174 } else if (String.class.equals(flavor.getRepresentationClass()) &&
1175 DataFlavorUtil.isFlavorCharsetTextType(flavor) && isTextFormat(format)) {
1278 }
1279
1280 /**
1281 * Primary translation function for translating
1282 * an InputStream into an Object, given a source format and a target
1283 * DataFlavor.
1284 */
1285 @SuppressWarnings("deprecation")
1286 public Object translateStream(InputStream str, DataFlavor flavor,
1287 long format, Transferable localeTransferable)
1288 throws IOException
1289 {
1290
1291 Object theObject = null;
1292 // Source data is a URI list. Convert to DataFlavor.javaFileListFlavor
1293 // where possible.
1294 if (isURIListFormat(format)
1295 && DataFlavor.javaFileListFlavor.equals(flavor))
1296 {
1297
1298 URI uris[] = dragQueryURIs(str, format, localeTransferable);
1299 if (uris == null) {
1300 return null;
1301 }
1302 List<File> files = new ArrayList<>();
1303 for (URI uri : uris) {
1304 try {
1305 files.add(new File(uri));
1306 } catch (IllegalArgumentException illegalArg) {
1307 // When converting from URIs to less generic files,
1308 // common practice (Wine, SWT) seems to be to
1309 // silently drop the URIs that aren't local files.
1310 }
1311 }
1312 theObject = files;
1313
1314 // Target data is a String. Strip terminating NUL bytes. Decode bytes
1315 // into characters. Search-and-replace EOLN.
1316 } else if (String.class.equals(flavor.getRepresentationClass()) &&
1317 DataFlavorUtil.isFlavorCharsetTextType(flavor) && isTextFormat(format)) {
1318
|
1 /*
2 * Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
1135 if (filenames == null) {
1136 return null;
1137 }
1138
1139 // Convert the strings to File objects
1140 File[] files = new File[filenames.length];
1141 for (int i = 0; i < filenames.length; i++) {
1142 files[i] = new File(filenames[i]);
1143 }
1144
1145 // Turn the list of Files into a List and return
1146 theObject = Arrays.asList(files);
1147
1148 // Source data is a URI list. Convert to DataFlavor.javaFileListFlavor
1149 // where possible.
1150 } else if (isURIListFormat(format)
1151 && DataFlavor.javaFileListFlavor.equals(flavor)) {
1152
1153 try (ByteArrayInputStream str = new ByteArrayInputStream(bytes)) {
1154
1155 URI[] uris = dragQueryURIs(str, format, localeTransferable);
1156 if (uris == null) {
1157 return null;
1158 }
1159 List<File> files = new ArrayList<>();
1160 for (URI uri : uris) {
1161 try {
1162 files.add(new File(uri));
1163 } catch (IllegalArgumentException illegalArg) {
1164 // When converting from URIs to less generic files,
1165 // common practice (Wine, SWT) seems to be to
1166 // silently drop the URIs that aren't local files.
1167 }
1168 }
1169 theObject = files;
1170 }
1171
1172 // Target data is a String. Strip terminating NUL bytes. Decode bytes
1173 // into characters. Search-and-replace EOLN.
1174 } else if (String.class.equals(flavor.getRepresentationClass()) &&
1175 DataFlavorUtil.isFlavorCharsetTextType(flavor) && isTextFormat(format)) {
1278 }
1279
1280 /**
1281 * Primary translation function for translating
1282 * an InputStream into an Object, given a source format and a target
1283 * DataFlavor.
1284 */
1285 @SuppressWarnings("deprecation")
1286 public Object translateStream(InputStream str, DataFlavor flavor,
1287 long format, Transferable localeTransferable)
1288 throws IOException
1289 {
1290
1291 Object theObject = null;
1292 // Source data is a URI list. Convert to DataFlavor.javaFileListFlavor
1293 // where possible.
1294 if (isURIListFormat(format)
1295 && DataFlavor.javaFileListFlavor.equals(flavor))
1296 {
1297
1298 URI[] uris = dragQueryURIs(str, format, localeTransferable);
1299 if (uris == null) {
1300 return null;
1301 }
1302 List<File> files = new ArrayList<>();
1303 for (URI uri : uris) {
1304 try {
1305 files.add(new File(uri));
1306 } catch (IllegalArgumentException illegalArg) {
1307 // When converting from URIs to less generic files,
1308 // common practice (Wine, SWT) seems to be to
1309 // silently drop the URIs that aren't local files.
1310 }
1311 }
1312 theObject = files;
1313
1314 // Target data is a String. Strip terminating NUL bytes. Decode bytes
1315 // into characters. Search-and-replace EOLN.
1316 } else if (String.class.equals(flavor.getRepresentationClass()) &&
1317 DataFlavorUtil.isFlavorCharsetTextType(flavor) && isTextFormat(format)) {
1318
|