src/solaris/classes/sun/awt/X11/XDataTransferer.java

Print this page

        

@@ -27,11 +27,10 @@
 
 import java.awt.Image;
 
 import java.awt.datatransfer.DataFlavor;
 import java.awt.datatransfer.Transferable;
-import java.awt.datatransfer.UnsupportedFlavorException;
 
 import java.awt.image.BufferedImage;
 import java.awt.image.ColorModel;
 import java.awt.image.WritableRaster;
 

@@ -44,23 +43,22 @@
 import java.net.URISyntaxException;
 
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.LinkedHashSet;
-import java.util.List;
 
 import javax.imageio.ImageIO;
 import javax.imageio.ImageReader;
 import javax.imageio.ImageTypeSpecifier;
 import javax.imageio.ImageWriter;
 import javax.imageio.spi.ImageWriterSpi;
 
+import sun.datatransfer.DataFlavorUtil;
 import sun.awt.datatransfer.DataTransferer;
 import sun.awt.datatransfer.ToolkitThreadBlockedHandler;
 
 import java.io.ByteArrayOutputStream;
-import java.util.stream.Stream;
 
 /**
  * Platform-specific support for the data transfer subsystem.
  */
 public class XDataTransferer extends DataTransferer {

@@ -85,41 +83,45 @@
             transferer = new XDataTransferer();
         }
         return transferer;
     }
 
+    @Override
     public String getDefaultUnicodeEncoding() {
         return "iso-10646-ucs-2";
     }
 
+    @Override
     public boolean isLocaleDependentTextFormat(long format) {
         return false;
     }
 
+    @Override
     public boolean isTextFormat(long format) {
         return super.isTextFormat(format)
             || isMimeFormat(format, "text");
     }
 
+    @Override
     protected String getCharsetForTextFormat(Long lFormat) {
-        long format = lFormat.longValue();
-        if (isMimeFormat(format, "text")) {
-            String nat = getNativeForFormat(format);
+        if (isMimeFormat(lFormat, "text")) {
+            String nat = getNativeForFormat(lFormat);
             DataFlavor df = new DataFlavor(nat, null);
             // Ignore the charset parameter of the MIME type if the subtype
             // doesn't support charset.
-            if (!DataTransferer.doesSubtypeSupportCharset(df)) {
+            if (!DataFlavorUtil.doesSubtypeSupportCharset(df)) {
                 return null;
             }
             String charset = df.getParameter("charset");
             if (charset != null) {
                 return charset;
             }
         }
         return super.getCharsetForTextFormat(lFormat);
     }
 
+    @Override
     protected boolean isURIListFormat(long format) {
         String nat = getNativeForFormat(format);
         if (nat == null) {
             return false;
         }

@@ -132,28 +134,31 @@
             // Not a MIME format.
         }
         return false;
     }
 
+    @Override
     public boolean isFileFormat(long format) {
         return format == FILE_NAME_ATOM.getAtom() ||
             format == DT_NET_FILE_ATOM.getAtom();
     }
 
+    @Override
     public boolean isImageFormat(long format) {
         return format == PNG_ATOM.getAtom() ||
             format == JFIF_ATOM.getAtom() ||
             isMimeFormat(format, "image");
     }
 
+    @Override
     protected Long getFormatForNativeAsLong(String str) {
         // Just get the atom. If it has already been retrived
         // once, we'll get a copy so this should be very fast.
-        long atom = XAtom.get(str).getAtom();
-        return Long.valueOf(atom);
+        return XAtom.get(str).getAtom();
     }
 
+    @Override
     protected String getNativeForFormat(long format) {
         return getTargetNameForAtom(format);
     }
 
     public ToolkitThreadBlockedHandler getToolkitThreadBlockedHandler() {

@@ -165,10 +170,11 @@
      */
     private String getTargetNameForAtom(long atom) {
         return XAtom.get(atom).getName();
     }
 
+    @Override
     protected byte[] imageToPlatformBytes(Image image, long format)
       throws IOException {
         String mimeType = null;
         if (format == PNG_ATOM.getAtom()) {
             mimeType = "image/png";

@@ -194,10 +200,11 @@
             throw new IOException("Translation to " + nativeFormat +
                                   " is not supported.");
         }
     }
 
+    @Override
     protected ByteArrayOutputStream convertFileListToBytes(ArrayList<String> fileList)
         throws IOException
     {
         ByteArrayOutputStream bos = new ByteArrayOutputStream();
         for (int i = 0; i < fileList.size(); i++)

@@ -211,10 +218,11 @@
 
     /**
      * Translates either a byte array or an input stream which contain
      * platform-specific image data in the given format into an Image.
      */
+    @Override
     protected Image platformImageBytesToImage(
         byte[] bytes, long format) throws IOException
     {
         String mimeType = null;
         if (format == PNG_ATOM.getAtom()) {

@@ -315,12 +323,11 @@
 
         if (nat == null) {
             return flavors;
         }
 
-        DataFlavor df = null;
-
+        DataFlavor df;
         try {
             df = new DataFlavor(nat);
         } catch (Exception e) {
             // The string doesn't constitute a valid MIME type.
             return flavors;

@@ -381,11 +388,11 @@
 
         String charset = df.getParameter("charset");
         String baseType = df.getPrimaryType() + "/" + df.getSubType();
         String mimeType = baseType;
 
-        if (charset != null && DataTransferer.isFlavorCharsetTextType(df)) {
+        if (charset != null && DataFlavorUtil.isFlavorCharsetTextType(df)) {
             mimeType += ";charset=" + charset;
         }
 
         // Add a mapping to the MIME native whenever the representation class
         // doesn't require translation.

@@ -411,18 +418,18 @@
                             break;
                         }
                     }
                 }
             }
-        } else if (DataTransferer.isFlavorCharsetTextType(df)) {
+        } else if (DataFlavorUtil.isFlavorCharsetTextType(df)) {
             // stringFlavor is semantically equivalent to the standard
             // "text/plain" MIME type.
             if (DataFlavor.stringFlavor.equals(df)) {
                 baseType = "text/plain";
             }
 
-            for (String encoding : DataTransferer.standardEncodings()) {
+            for (String encoding : DataFlavorUtil.standardEncodings()) {
                 if (!encoding.equals(charset)) {
                     natives.add(baseType + ";charset=" + encoding);
                 }
             }