src/share/classes/sun/awt/datatransfer/DataTransferer.java
Print this page
rev 9830 : 8039642: Fix raw and unchecked warnings in sun.awt.*
Reviewed-by: darcy, prr
*** 352,362 ****
!doesSubtypeSupportCharset(flavor))
{
return false;
}
! Class rep_class = flavor.getRepresentationClass();
if (flavor.isRepresentationClassReader() ||
String.class.equals(rep_class) ||
flavor.isRepresentationClassCharBuffer() ||
char[].class.equals(rep_class))
--- 352,362 ----
!doesSubtypeSupportCharset(flavor))
{
return false;
}
! Class<?> rep_class = flavor.getRepresentationClass();
if (flavor.isRepresentationClassReader() ||
String.class.equals(rep_class) ||
flavor.isRepresentationClassCharBuffer() ||
char[].class.equals(rep_class))
*** 724,734 ****
* @param formats the data formats
* @param map the FlavorTable which contains mappings between
* DataFlavors and data formats
* @throws NullPointerException if formats or map is <code>null</code>
*/
! public Set getFlavorsForFormatsAsSet(long[] formats, FlavorTable map) {
Set<DataFlavor> flavorSet = new HashSet<>(formats.length);
for (long format : formats) {
List<DataFlavor> flavors = map.getFlavorsForNative(getNativeForFormat(format));
for (DataFlavor flavor : flavors) {
--- 724,734 ----
* @param formats the data formats
* @param map the FlavorTable which contains mappings between
* DataFlavors and data formats
* @throws NullPointerException if formats or map is <code>null</code>
*/
! public Set<DataFlavor> getFlavorsForFormatsAsSet(long[] formats, FlavorTable map) {
Set<DataFlavor> flavorSet = new HashSet<>(formats.length);
for (long format : formats) {
List<DataFlavor> flavors = map.getFlavorsForNative(getNativeForFormat(format));
for (DataFlavor flavor : flavors) {
*** 1115,1125 ****
if (isFileFormat(format)) {
if (!DataFlavor.javaFileListFlavor.equals(flavor)) {
throw new IOException("data translation failed");
}
! final List list = (List)obj;
final ProtectionDomain userProtectionDomain = getUserProtectionDomain(contents);
final ArrayList<String> fileList = castToFiles(list, userProtectionDomain);
--- 1115,1125 ----
if (isFileFormat(format)) {
if (!DataFlavor.javaFileListFlavor.equals(flavor)) {
throw new IOException("data translation failed");
}
! final List<?> list = (List<?>)obj;
final ProtectionDomain userProtectionDomain = getUserProtectionDomain(contents);
final ArrayList<String> fileList = castToFiles(list, userProtectionDomain);
*** 1143,1153 ****
}
}
if (targetCharset == null) {
targetCharset = "UTF-8";
}
! final List list = (List)obj;
final ProtectionDomain userProtectionDomain = getUserProtectionDomain(contents);
final ArrayList<String> fileList = castToFiles(list, userProtectionDomain);
final ArrayList<String> uriList = new ArrayList<>(fileList.size());
for (String fileObject : fileList) {
final URI uri = new File(fileObject).toURI();
--- 1143,1153 ----
}
}
if (targetCharset == null) {
targetCharset = "UTF-8";
}
! final List<?> list = (List<?>)obj;
final ProtectionDomain userProtectionDomain = getUserProtectionDomain(contents);
final ArrayList<String> fileList = castToFiles(list, userProtectionDomain);
final ArrayList<String> uriList = new ArrayList<>(fileList.size());
for (String fileObject : fileList) {
final URI uri = new File(fileObject).toURI();
*** 1288,1298 ****
} catch (IOException e) {}
return true;
}
! private ArrayList<String> castToFiles(final List files,
final ProtectionDomain userProtectionDomain) throws IOException {
try {
return AccessController.doPrivileged((PrivilegedExceptionAction<ArrayList<String>>) () -> {
ArrayList<String> fileList = new ArrayList<>();
for (Object fileObject : files)
--- 1288,1298 ----
} catch (IOException e) {}
return true;
}
! private ArrayList<String> castToFiles(final List<?> files,
final ProtectionDomain userProtectionDomain) throws IOException {
try {
return AccessController.doPrivileged((PrivilegedExceptionAction<ArrayList<String>>) () -> {
ArrayList<String> fileList = new ArrayList<>();
for (Object fileObject : files)
*** 1666,1696 ****
* We support representations which are exactly of the specified Class,
* and also arbitrary Objects which have a constructor which takes an
* instance of the Class as its sole parameter.
*/
private Object constructFlavoredObject(Object arg, DataFlavor flavor,
! Class clazz)
throws IOException
{
final Class<?> dfrc = flavor.getRepresentationClass();
if (clazz.equals(dfrc)) {
return arg; // simple case
} else {
! Constructor[] constructors;
try {
constructors = AccessController.doPrivileged(
! (PrivilegedAction<Constructor[]>) dfrc::getConstructors);
} catch (SecurityException se) {
throw new IOException(se.getMessage());
}
! Constructor constructor = Stream.of(constructors)
.filter(c -> Modifier.isPublic(c.getModifiers()))
.filter(c -> {
! Class[] ptypes = c.getParameterTypes();
return ptypes != null
&& ptypes.length == 1
&& clazz.equals(ptypes[0]);
})
.findFirst()
--- 1666,1696 ----
* We support representations which are exactly of the specified Class,
* and also arbitrary Objects which have a constructor which takes an
* instance of the Class as its sole parameter.
*/
private Object constructFlavoredObject(Object arg, DataFlavor flavor,
! Class<?> clazz)
throws IOException
{
final Class<?> dfrc = flavor.getRepresentationClass();
if (clazz.equals(dfrc)) {
return arg; // simple case
} else {
! Constructor<?>[] constructors;
try {
constructors = AccessController.doPrivileged(
! (PrivilegedAction<Constructor<?>[]>) dfrc::getConstructors);
} catch (SecurityException se) {
throw new IOException(se.getMessage());
}
! Constructor<?> constructor = Stream.of(constructors)
.filter(c -> Modifier.isPublic(c.getModifiers()))
.filter(c -> {
! Class<?>[] ptypes = c.getParameterTypes();
return ptypes != null
&& ptypes.length == 1
&& clazz.equals(ptypes[0]);
})
.findFirst()
*** 1915,1935 ****
*/
protected Image standardImageBytesToImage(
byte[] bytes, String mimeType) throws IOException
{
! Iterator readerIterator = ImageIO.getImageReadersByMIMEType(mimeType);
if (!readerIterator.hasNext()) {
throw new IOException("No registered service provider can decode " +
" an image from " + mimeType);
}
IOException ioe = null;
while (readerIterator.hasNext()) {
! ImageReader imageReader = (ImageReader)readerIterator.next();
try (ByteArrayInputStream bais = new ByteArrayInputStream(bytes)) {
try (ImageInputStream imageInputStream = ImageIO.createImageInputStream(bais)) {
ImageReadParam param = imageReader.getDefaultReadParam();
imageReader.setInput(imageInputStream, true, true);
BufferedImage bufferedImage = imageReader.read(imageReader.getMinIndex(), param);
--- 1915,1936 ----
*/
protected Image standardImageBytesToImage(
byte[] bytes, String mimeType) throws IOException
{
! Iterator<ImageReader> readerIterator =
! ImageIO.getImageReadersByMIMEType(mimeType);
if (!readerIterator.hasNext()) {
throw new IOException("No registered service provider can decode " +
" an image from " + mimeType);
}
IOException ioe = null;
while (readerIterator.hasNext()) {
! ImageReader imageReader = readerIterator.next();
try (ByteArrayInputStream bais = new ByteArrayInputStream(bytes)) {
try (ImageInputStream imageInputStream = ImageIO.createImageInputStream(bais)) {
ImageReadParam param = imageReader.getDefaultReadParam();
imageReader.setInput(imageInputStream, true, true);
BufferedImage bufferedImage = imageReader.read(imageReader.getMinIndex(), param);
*** 1968,1978 ****
*/
protected byte[] imageToStandardBytes(Image image, String mimeType)
throws IOException {
IOException originalIOE = null;
! Iterator writerIterator = ImageIO.getImageWritersByMIMEType(mimeType);
if (!writerIterator.hasNext()) {
throw new IOException("No registered service provider can encode " +
" an image to " + mimeType);
}
--- 1969,1980 ----
*/
protected byte[] imageToStandardBytes(Image image, String mimeType)
throws IOException {
IOException originalIOE = null;
! Iterator<ImageWriter> writerIterator =
! ImageIO.getImageWritersByMIMEType(mimeType);
if (!writerIterator.hasNext()) {
throw new IOException("No registered service provider can encode " +
" an image to " + mimeType);
}
*** 2027,2046 ****
byte[] imageToStandardBytesImpl(RenderedImage renderedImage,
String mimeType)
throws IOException {
! Iterator writerIterator = ImageIO.getImageWritersByMIMEType(mimeType);
ImageTypeSpecifier typeSpecifier =
new ImageTypeSpecifier(renderedImage);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
IOException ioe = null;
while (writerIterator.hasNext()) {
! ImageWriter imageWriter = (ImageWriter)writerIterator.next();
ImageWriterSpi writerSpi = imageWriter.getOriginatingProvider();
if (!writerSpi.canEncodeImage(typeSpecifier)) {
continue;
}
--- 2029,2049 ----
byte[] imageToStandardBytesImpl(RenderedImage renderedImage,
String mimeType)
throws IOException {
! Iterator<ImageWriter> writerIterator =
! ImageIO.getImageWritersByMIMEType(mimeType);
ImageTypeSpecifier typeSpecifier =
new ImageTypeSpecifier(renderedImage);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
IOException ioe = null;
while (writerIterator.hasNext()) {
! ImageWriter imageWriter = writerIterator.next();
ImageWriterSpi writerSpi = imageWriter.getOriginatingProvider();
if (!writerSpi.canEncodeImage(typeSpecifier)) {
continue;
}
*** 2120,2130 ****
}
public byte[] convertData(final Object source,
final Transferable contents,
final long format,
! final Map formatMap,
final boolean isToolkitThread)
throws IOException
{
byte[] ret = null;
--- 2123,2133 ----
}
public byte[] convertData(final Object source,
final Transferable contents,
final long format,
! final Map<Long, DataFlavor> formatMap,
final boolean isToolkitThread)
throws IOException
{
byte[] ret = null;
*** 2143,2153 ****
if (done) {
return;
}
byte[] data = null;
try {
! DataFlavor flavor = (DataFlavor)formatMap.get(format);
if (flavor != null) {
data = translateTransferable(contents, flavor, format);
}
} catch (Exception e) {
e.printStackTrace();
--- 2146,2156 ----
if (done) {
return;
}
byte[] data = null;
try {
! DataFlavor flavor = formatMap.get(format);
if (flavor != null) {
data = translateTransferable(contents, flavor, format);
}
} catch (Exception e) {
e.printStackTrace();
*** 2184,2194 ****
ret = stack.pop();
} finally {
getToolkitThreadBlockedHandler().unlock();
} else {
! DataFlavor flavor = (DataFlavor)formatMap.get(format);
if (flavor != null) {
ret = translateTransferable(contents, flavor, format);
}
}
--- 2187,2197 ----
ret = stack.pop();
} finally {
getToolkitThreadBlockedHandler().unlock();
} else {
! DataFlavor flavor = formatMap.get(format);
if (flavor != null) {
ret = translateTransferable(contents, flavor, format);
}
}
*** 2233,2243 ****
/**
* Helper function to convert a Set of DataFlavors to a sorted array.
* The array will be sorted according to <code>DataFlavorComparator</code>.
*/
! public static DataFlavor[] setToSortedDataFlavorArray(Set flavorsSet) {
DataFlavor[] flavors = new DataFlavor[flavorsSet.size()];
flavorsSet.toArray(flavors);
final Comparator<DataFlavor> comparator =
new DataFlavorComparator(IndexedComparator.SELECT_WORST);
Arrays.sort(flavors, comparator);
--- 2236,2246 ----
/**
* Helper function to convert a Set of DataFlavors to a sorted array.
* The array will be sorted according to <code>DataFlavorComparator</code>.
*/
! public static DataFlavor[] setToSortedDataFlavorArray(Set<DataFlavor> flavorsSet) {
DataFlavor[] flavors = new DataFlavor[flavorsSet.size()];
flavorsSet.toArray(flavors);
final Comparator<DataFlavor> comparator =
new DataFlavorComparator(IndexedComparator.SELECT_WORST);
Arrays.sort(flavors, comparator);
*** 2596,2611 ****
int comp = 0;
String primaryType1 = flavor1.getPrimaryType();
String subType1 = flavor1.getSubType();
String mimeType1 = primaryType1 + "/" + subType1;
! Class class1 = flavor1.getRepresentationClass();
String primaryType2 = flavor2.getPrimaryType();
String subType2 = flavor2.getSubType();
String mimeType2 = primaryType2 + "/" + subType2;
! Class class2 = flavor2.getRepresentationClass();
if (flavor1.isFlavorTextType() && flavor2.isFlavorTextType()) {
// First, compare MIME types
comp = compareIndices(textTypes, mimeType1, mimeType2,
UNKNOWN_OBJECT_LOSES);
--- 2599,2614 ----
int comp = 0;
String primaryType1 = flavor1.getPrimaryType();
String subType1 = flavor1.getSubType();
String mimeType1 = primaryType1 + "/" + subType1;
! Class<?> class1 = flavor1.getRepresentationClass();
String primaryType2 = flavor2.getPrimaryType();
String subType2 = flavor2.getSubType();
String mimeType2 = primaryType2 + "/" + subType2;
! Class<?> class2 = flavor2.getRepresentationClass();
if (flavor1.isFlavorTextType() && flavor2.isFlavorTextType()) {
// First, compare MIME types
comp = compareIndices(textTypes, mimeType1, mimeType2,
UNKNOWN_OBJECT_LOSES);