This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
Re: [PATCH] Fix for 'paste'
Tom Tromey wrote:
I looked here:
http://java.sun.com/j2se/1.4.2/docs/api/java/awt/datatransfer/StringSelection.html#getTransferData(java.awt.datatransfer.DataFlavor)
That's where the bit about Reader and the inconsistency with the
definition of plainTextFlavor comes from.
Thanks. Now I see the inconsistency. What a big spec screw-up.
If the test suite works ok, though, then perhaps the URL above is
incorrect and Sun really does return an InputStream. In which case
the patch is fine, thanks. It might be helpful to have a comment
explaining the situation, up to you.
Sorry Tom, the test I was fixing was for a stringFlavor.
I was able to verify that the Sun SDK indeed returns a java.io.StringReader,
not a java.io.StringBufferInputStream.
You said: "I forgot to mention: the best thing in a case like this, where the
docs are confusing, is to try it out on the Sun JDK and see what
happens."
This seem to imply that we should, in these cases, do as Sun does, right? I've
made the change to return StringReader.
Here is the patch that I am checking in. I've added a comment like you suggested.
Thanks for spotting this.
Regards,
Fernando
Index: java/awt/datatransfer/StringSelection.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/awt/datatransfer/StringSelection.java,v
retrieving revision 1.2
diff -c -p -u -r1.2 StringSelection.java
--- java/awt/datatransfer/StringSelection.java 24 Jun 2003 10:50:21 -0000 1.2
+++ java/awt/datatransfer/StringSelection.java 8 Dec 2003 23:52:01 -0000
@@ -38,7 +38,7 @@ exception statement from your version. *
package java.awt.datatransfer;
-import java.io.StringBufferInputStream;
+import java.io.StringReader;
import java.io.IOException;
/**
@@ -140,7 +140,15 @@ getTransferData(DataFlavor flavor) throw
if (!isDataFlavorSupported(flavor))
throw new UnsupportedFlavorException(flavor);
- return(new StringBufferInputStream(data));
+ if (DataFlavor.plainTextFlavor == flavor)
+ /* The behavior of this method for DataFlavor.plainTextFlavor and
+ equivalent DataFlavors is inconsistent with the definition of
+ DataFlavor.plainTextFlavor. We choose to do like Sun's implementation
+ and return a Reader instead of an InputString. */
+ /* return(new StringBufferInputStream(data)); */
+ return(new StringReader(data));
+ else // DataFlavor.stringFlavor
+ return data;
}
/*************************************************************************/