fileList) throws IOException;
@@ -1560,38 +1569,8 @@
long format, Transferable localeTransferable)
throws IOException
{
- return translateBytesOrStream(null, bytes, flavor, format,
- localeTransferable);
- }
-
- public Object translateStream(InputStream str, DataFlavor flavor,
- long format, Transferable localeTransferable)
- throws IOException
- {
- return translateBytesOrStream(str, null, flavor, format,
- localeTransferable);
- }
-
-
- /**
- * Primary translation function for translating either a byte array or
- * an InputStream into an Object, given a source format and a target
- * DataFlavor.
- *
- * One of str/bytes is non-null; the other is null.
- * The conversion from byte[] to InputStream is cheap, so do that
- * immediately if necessary. The opposite conversion is expensive,
- * so avoid it if possible.
- */
- protected Object translateBytesOrStream(InputStream str, byte[] bytes,
- DataFlavor flavor, long format,
- Transferable localeTransferable)
- throws IOException
- {
- if (str == null) {
- str = new ByteArrayInputStream(bytes);
- }
+ Object theObject = null;
// Source data is a file list. Use the dragQueryFile native function to
// do most of the decoding. Then wrap File objects around the String
@@ -1600,12 +1579,8 @@
if (!DataFlavor.javaFileListFlavor.equals(flavor)) {
throw new IOException("data translation failed");
}
- if (bytes == null) {
- bytes = inputStreamToByteArray(str);
- }
String[] filenames = dragQueryFile(bytes);
if (filenames == null) {
- str.close();
return null;
}
@@ -1614,178 +1589,203 @@
for (int i = 0; i < filenames.length; i++) {
files[i] = new File(filenames[i]);
}
- str.close();
// Turn the list of Files into a List and return
- return Arrays.asList(files);
+ theObject = Arrays.asList(files);
- // Source data is a URI list. Convert to DataFlavor.javaFileListFlavor
- // where possible.
- } else if (isURIListFormat(format) && DataFlavor.javaFileListFlavor.equals(flavor)) {
- try {
- URI uris[] = dragQueryURIs(str, bytes, format, localeTransferable);
- if (uris == null) {
- return null;
- }
- ArrayList files = new ArrayList();
- for (URI uri : uris) {
- try {
- files.add(new File(uri));
- } catch (IllegalArgumentException illegalArg) {
- // When converting from URIs to less generic files,
- // common practice (Wine, SWT) seems to be to
- // silently drop the URIs that aren't local files.
- }
- }
- return files;
- } finally {
- str.close();
- }
-
- // Target data is a String. Strip terminating NUL bytes. Decode bytes
- // into characters. Search-and-replace EOLN.
+ // Target data is a String. Strip terminating NUL bytes. Decode bytes
+ // into characters. Search-and-replace EOLN.
} else if (String.class.equals(flavor.getRepresentationClass()) &&
- isFlavorCharsetTextType(flavor) && isTextFormat(format)) {
+ isFlavorCharsetTextType(flavor) && isTextFormat(format)) {
- return translateBytesOrStreamToString(
- str, bytes,
- format, localeTransferable);
-
- // Special hack to maintain backwards-compatibility with the brokenness
- // of StringSelection. Return a StringReader instead of an InputStream.
- // Recur to obtain String and encapsulate.
- } else if (DataFlavor.plainTextFlavor.equals(flavor)) {
- return new StringReader(translateBytesOrStreamToString(
- str, bytes,
- format, localeTransferable));
-
- // Target data is an InputStream. For arbitrary flavors, just return
- // the raw bytes. For text flavors, decode to strip terminators and
- // search-and-replace EOLN, then reencode according to the requested
- // flavor.
- } else if (flavor.isRepresentationClassInputStream()) {
- return translateBytesOrStreamToInputStream(str, flavor, format,
- localeTransferable);
+ theObject = translateBytesToString(bytes, format, localeTransferable);
- // Target data is a Reader. Obtain data in InputStream format, encoded
- // as "Unicode" (utf-16be). Then use an InputStreamReader to decode
- // back to chars on demand.
+ // Target data is a Reader. Obtain data in InputStream format, encoded
+ // as "Unicode" (utf-16be). Then use an InputStreamReader to decode
+ // back to chars on demand.
} else if (flavor.isRepresentationClassReader()) {
- if (!(isFlavorCharsetTextType(flavor) && isTextFormat(format))) {
- throw new IOException
- ("cannot transfer non-text data as Reader");
+ try (ByteArrayInputStream bais = new ByteArrayInputStream(bytes)) {
+ theObject = translateStream(bais,
+ flavor, format, localeTransferable);
}
-
- InputStream is = (InputStream)
- translateBytesOrStreamToInputStream
- (str, DataFlavor.plainTextFlavor, format,
- localeTransferable);
- String unicode =
- DataTransferer.getTextCharset(DataFlavor.plainTextFlavor);
- Reader reader = new InputStreamReader(is, unicode);
-
- return constructFlavoredObject(reader, flavor, Reader.class);
-
- // Target data is a CharBuffer. Recur to obtain String and wrap.
+ // Target data is a CharBuffer. Recur to obtain String and wrap.
} else if (flavor.isRepresentationClassCharBuffer()) {
if (!(isFlavorCharsetTextType(flavor) && isTextFormat(format))) {
throw new IOException
- ("cannot transfer non-text data as CharBuffer");
+ ("cannot transfer non-text data as CharBuffer");
}
- CharBuffer buffer = CharBuffer.wrap(translateBytesOrStreamToString(
- str, bytes,
- format, localeTransferable));
+ CharBuffer buffer = CharBuffer.wrap(
+ translateBytesToString(bytes,format, localeTransferable));
- return constructFlavoredObject(buffer, flavor, CharBuffer.class);
+ theObject = constructFlavoredObject(buffer, flavor, CharBuffer.class);
- // Target data is a char array. Recur to obtain String and convert to
- // char array.
+ // Target data is a char array. Recur to obtain String and convert to
+ // char array.
} else if (charArrayClass.equals(flavor.getRepresentationClass())) {
if (!(isFlavorCharsetTextType(flavor) && isTextFormat(format))) {
throw new IOException
- ("cannot transfer non-text data as char array");
+ ("cannot transfer non-text data as char array");
}
- return translateBytesOrStreamToString(
- str, bytes,
- format, localeTransferable).toCharArray();
-
- // Target data is a ByteBuffer. For arbitrary flavors, just return
- // the raw bytes. For text flavors, convert to a String to strip
- // terminators and search-and-replace EOLN, then reencode according to
- // the requested flavor.
+ theObject = translateBytesToString(
+ bytes, format, localeTransferable).toCharArray();
+
+ // Target data is a ByteBuffer. For arbitrary flavors, just return
+ // the raw bytes. For text flavors, convert to a String to strip
+ // terminators and search-and-replace EOLN, then reencode according to
+ // the requested flavor.
} else if (flavor.isRepresentationClassByteBuffer()) {
if (isFlavorCharsetTextType(flavor) && isTextFormat(format)) {
- bytes = translateBytesOrStreamToString(
- str, bytes,
- format, localeTransferable
- ).getBytes(
- DataTransferer.getTextCharset(flavor)
- );
- } else {
- if (bytes == null) {
- bytes = inputStreamToByteArray(str);
- }
+ bytes = translateBytesToString(
+ bytes, format, localeTransferable).getBytes(
+ DataTransferer.getTextCharset(flavor)
+ );
}
ByteBuffer buffer = ByteBuffer.wrap(bytes);
- return constructFlavoredObject(buffer, flavor, ByteBuffer.class);
+ theObject = constructFlavoredObject(buffer, flavor, ByteBuffer.class);
- // Target data is a byte array. For arbitrary flavors, just return
- // the raw bytes. For text flavors, convert to a String to strip
- // terminators and search-and-replace EOLN, then reencode according to
- // the requested flavor.
+ // Target data is a byte array. For arbitrary flavors, just return
+ // the raw bytes. For text flavors, convert to a String to strip
+ // terminators and search-and-replace EOLN, then reencode according to
+ // the requested flavor.
} else if (byteArrayClass.equals(flavor.getRepresentationClass())) {
if (isFlavorCharsetTextType(flavor) && isTextFormat(format)) {
- return translateBytesOrStreamToString(
- str, bytes,
- format, localeTransferable
- ).getBytes(
- DataTransferer.getTextCharset(flavor)
- );
+ theObject = translateBytesToString(
+ bytes, format, localeTransferable
+ ).getBytes(DataTransferer.getTextCharset(flavor));
} else {
- return (bytes != null) ? bytes : inputStreamToByteArray(str);
+ theObject = bytes;
}
- // Target data is an RMI object
- } else if (flavor.isRepresentationClassRemote()) {
- try {
- byte[] ba = inputStreamToByteArray(str);
- ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(ba));
- Object ret = RMI.getMarshalledObject(ois.readObject());
- ois.close();
- str.close();
- return ret;
- } catch (Exception e) {
- throw new IOException(e.getMessage());
+ // Target data is an InputStream. For arbitrary flavors, just return
+ // the raw bytes. For text flavors, decode to strip terminators and
+ // search-and-replace EOLN, then reencode according to the requested
+ // flavor.
+ } else if (flavor.isRepresentationClassInputStream()) {
+
+ try (ByteArrayInputStream bais = new ByteArrayInputStream(bytes)) {
+ theObject = translateStream(bais, flavor, format, localeTransferable);
}
- // Target data is Serializable
+ // Target data is Serializable
} else if (flavor.isRepresentationClassSerializable()) {
- try {
- byte[] ba = inputStreamToByteArray(str);
- ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(ba));
- Object ret = ois.readObject();
- ois.close();
- str.close();
- return ret;
- } catch (Exception e) {
- throw new IOException(e.getMessage());
+
+ try (ByteArrayInputStream bais = new ByteArrayInputStream(bytes)) {
+ theObject = translateStream(bais, flavor, format, localeTransferable);
}
- // Target data is Image
+ // Target data is Image
} else if (DataFlavor.imageFlavor.equals(flavor)) {
if (!isImageFormat(format)) {
throw new IOException("data translation failed");
}
- Image image = platformImageBytesOrStreamToImage(str, bytes, format);
- str.close();
- return image;
+ theObject = platformImageBytesToImage(bytes, format);
+ }
+
+ if (theObject == null) {
+ throw new IOException("data translation failed");
+ }
+
+ return theObject;
+
+ }
+
+ /**
+ * Primary translation function for translating
+ * an InputStream into an Object, given a source format and a target
+ * DataFlavor.
+ */
+ public Object translateStream(InputStream str, DataFlavor flavor,
+ long format, Transferable localeTransferable)
+ throws IOException
+ {
+
+ Object theObject = null;
+ // Source data is a URI list. Convert to DataFlavor.javaFileListFlavor
+ // where possible.
+ if (isURIListFormat(format)
+ && DataFlavor.javaFileListFlavor.equals(flavor))
+ {
+
+ URI uris[] = dragQueryURIs(str, format, localeTransferable);
+ if (uris == null) {
+ return null;
+ }
+ ArrayList files = new ArrayList();
+ for (URI uri : uris) {
+ try {
+ files.add(new File(uri));
+ } catch (IllegalArgumentException illegalArg) {
+ // When converting from URIs to less generic files,
+ // common practice (Wine, SWT) seems to be to
+ // silently drop the URIs that aren't local files.
+ }
+ }
+ theObject = files;
+
+ // Special hack to maintain backwards-compatibility with the brokenness
+ // of StringSelection. Return a StringReader instead of an InputStream.
+ // Recur to obtain String and encapsulate.
+ } else if (DataFlavor.plainTextFlavor.equals(flavor)) {
+ theObject = new StringReader(translateBytesToString(
+ inputStreamToByteArray(str),
+ format, localeTransferable));
+
+ // Target data is an InputStream. For arbitrary flavors, just return
+ // the raw bytes. For text flavors, decode to strip terminators and
+ // search-and-replace EOLN, then reencode according to the requested
+ // flavor.
+ } else if (flavor.isRepresentationClassInputStream()) {
+ theObject = translateStreamToInputStream(str, flavor, format,
+ localeTransferable);
+
+ // Target data is a Reader. Obtain data in InputStream format, encoded
+ // as "Unicode" (utf-16be). Then use an InputStreamReader to decode
+ // back to chars on demand.
+ } else if (flavor.isRepresentationClassReader()) {
+ if (!(isFlavorCharsetTextType(flavor) && isTextFormat(format))) {
+ throw new IOException
+ ("cannot transfer non-text data as Reader");
+ }
+
+ InputStream is = (InputStream)translateStreamToInputStream(
+ str, DataFlavor.plainTextFlavor,
+ format, localeTransferable);
+
+ String unicode = DataTransferer.getTextCharset(DataFlavor.plainTextFlavor);
+
+ Reader reader = new InputStreamReader(is, unicode);
+
+ theObject = constructFlavoredObject(reader, flavor, Reader.class);
+
+ // Target data is an RMI object
+ } else if (flavor.isRepresentationClassRemote()) {
+
+ try (ObjectInputStream ois =
+ new ObjectInputStream(str))
+ {
+ theObject = RMI.getMarshalledObject(ois.readObject());
+ }catch (Exception e) {
+ throw new IOException(e.getMessage());
+ }
+
+ // Target data is Serializable
+ } else if (flavor.isRepresentationClassSerializable()) {
+ try (ObjectInputStream ois =
+ new ObjectInputStream(str))
+ {
+ theObject = ois.readObject();
+ } catch (Exception e) {
+ throw new IOException(e.getMessage());
+ }
}
- throw new IOException("data translation failed");
+
+ return theObject;
+
}
/**
@@ -1793,7 +1793,7 @@
* ReencodingInputStream will decode and reencode the InputStream on demand
* so that we can strip terminators and search-and-replace EOLN.
*/
- private Object translateBytesOrStreamToInputStream
+ private Object translateStreamToInputStream
(InputStream str, DataFlavor flavor, long format,
Transferable localeTransferable) throws IOException
{
@@ -2049,7 +2049,6 @@
* Decodes URIs from either a byte array or a stream.
*/
protected URI[] dragQueryURIs(InputStream stream,
- byte[] bytes,
long format,
Transferable localeTransferable)
throws IOException
@@ -2062,10 +2061,10 @@
* Translates either a byte array or an input stream which contain
* platform-specific image data in the given format into an Image.
*/
- protected abstract Image platformImageBytesOrStreamToImage(InputStream str,
- byte[] bytes,
- long format)
- throws IOException;
+
+
+ protected abstract Image platformImageBytesToImage(
+ byte[] bytes,long format) throws IOException;
/**
* Translates either a byte array or an input stream which contain
@@ -2073,13 +2072,9 @@
*
* @param mimeType image MIME type, such as: image/png, image/jpeg, image/gif
*/
- protected Image standardImageBytesOrStreamToImage(InputStream inputStream,
- byte[] bytes,
- String mimeType)
- throws IOException {
- if (inputStream == null) {
- inputStream = new ByteArrayInputStream(bytes);
- }
+ protected Image standardImageBytesToImage(
+ byte[] bytes, String mimeType) throws IOException
+ {
Iterator readerIterator = ImageIO.getImageReadersByMIMEType(mimeType);
@@ -2092,9 +2087,9 @@
while (readerIterator.hasNext()) {
ImageReader imageReader = (ImageReader)readerIterator.next();
- try {
+ try (ByteArrayInputStream bais = new ByteArrayInputStream(bytes)) {
ImageInputStream imageInputStream =
- ImageIO.createImageInputStream(inputStream);
+ ImageIO.createImageInputStream(bais);
try {
ImageReadParam param = imageReader.getDefaultReadParam();
@@ -2424,15 +2419,16 @@
protected static byte[] inputStreamToByteArray(InputStream str)
throws IOException
{
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- int len = 0;
- byte[] buf = new byte[8192];
+ try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
+ int len = 0;
+ byte[] buf = new byte[8192];
- while ((len = str.read(buf)) != -1) {
- baos.write(buf, 0, len);
- }
+ while ((len = str.read(buf)) != -1) {
+ baos.write(buf, 0, len);
+ }
- return baos.toByteArray();
+ return baos.toByteArray();
+ }
}
/**
--- old/src/share/classes/sun/awt/dnd/SunDropTargetContextPeer.java 2014-12-12 18:00:43.368297600 +0400
+++ new/src/share/classes/sun/awt/dnd/SunDropTargetContextPeer.java 2014-12-12 18:00:42.534249900 +0400
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -57,7 +57,6 @@
import sun.awt.SunToolkit;
import sun.awt.datatransfer.DataTransferer;
import sun.awt.datatransfer.ToolkitThreadBlockedHandler;
-import sun.security.util.SecurityConstants;
/**
*
@@ -239,13 +238,6 @@
if (localTransferable != null) {
return localTransferable.getTransferData(df);
- } else if (df.isMimeTypeEqual(DataFlavor.javaJVMLocalObjectMimeType)) {
- // Workaround to JDK-8024061: Exception thrown when drag and drop
- // between two components is executed quickly.
- // It is expected localTransferable is not null if javaJVMLocalObjectMimeType
- // is used. Executing further results in ClassCastException, so null is
- // returned here as no transfer data is available in this case.
- return null;
}
if (dropStatus != STATUS_ACCEPT || dropComplete) {
@@ -267,6 +259,7 @@
}
final long format = lFormat.longValue();
+
Object ret = getNativeData(format);
if (ret instanceof byte[]) {
@@ -277,11 +270,14 @@
throw new InvalidDnDOperationException(e.getMessage());
}
} else if (ret instanceof InputStream) {
+ InputStream inputStream = (InputStream)ret;
try {
return DataTransferer.getInstance().
- translateStream((InputStream)ret, df, format, this);
+ translateStream(inputStream, df, format, this);
} catch (IOException e) {
throw new InvalidDnDOperationException(e.getMessage());
+ } finally {
+ inputStream.close();
}
} else {
throw new IOException("no native data was transfered");
--- old/src/solaris/classes/sun/awt/X11/XDataTransferer.java 2014-12-12 18:00:48.865612000 +0400
+++ new/src/solaris/classes/sun/awt/X11/XDataTransferer.java 2014-12-12 18:00:47.786550300 +0400
@@ -212,10 +212,9 @@
* Translates either a byte array or an input stream which contain
* platform-specific image data in the given format into an Image.
*/
- protected Image platformImageBytesOrStreamToImage(InputStream inputStream,
- byte[] bytes,
- long format)
- throws IOException {
+ protected Image platformImageBytesToImage(
+ byte[] bytes, long format) throws IOException
+ {
String mimeType = null;
if (format == PNG_ATOM.getAtom()) {
mimeType = "image/png";
@@ -235,7 +234,7 @@
}
}
if (mimeType != null) {
- return standardImageBytesOrStreamToImage(inputStream, bytes, mimeType);
+ return standardImageBytesToImage(bytes, mimeType);
} else {
String nativeFormat = getNativeForFormat(format);
throw new IOException("Translation from " + nativeFormat +
@@ -330,8 +329,8 @@
* a valid MIME and return a list of flavors to which the data in this MIME
* type can be translated by the Data Transfer subsystem.
*/
- public List getPlatformMappingsForNative(String nat) {
- List flavors = new ArrayList();
+ public List getPlatformMappingsForNative(String nat) {
+ List flavors = new ArrayList();
if (nat == null) {
return flavors;
@@ -346,16 +345,14 @@
return flavors;
}
- Object value = df;
+ DataFlavor value = df;
final String primaryType = df.getPrimaryType();
final String baseType = primaryType + "/" + df.getSubType();
// For text formats we map natives to MIME strings instead of data
// flavors to enable dynamic text native-to-flavor mapping generation.
// See SystemFlavorMap.getFlavorsForNative() for details.
- if ("text".equals(primaryType)) {
- value = primaryType + "/" + df.getSubType();
- } else if ("image".equals(primaryType)) {
+ if ("image".equals(primaryType)) {
Iterator readers = ImageIO.getImageReadersByMIMEType(baseType);
if (readers.hasNext()) {
flavors.add(DataFlavor.imageFlavor);
@@ -438,16 +435,13 @@
}
}
} else if (DataTransferer.isFlavorCharsetTextType(df)) {
- final Iterator iter = DataTransferer.standardEncodings();
-
// stringFlavor is semantically equivalent to the standard
// "text/plain" MIME type.
if (DataFlavor.stringFlavor.equals(df)) {
baseType = "text/plain";
}
- while (iter.hasNext()) {
- String encoding = (String)iter.next();
+ for (String encoding : DataTransferer.standardEncodings()) {
if (!encoding.equals(charset)) {
natives.add(baseType + ";charset=" + encoding);
}
--- old/src/windows/classes/sun/awt/windows/WDataTransferer.java 2014-12-12 18:00:54.228918800 +0400
+++ new/src/windows/classes/sun/awt/windows/WDataTransferer.java 2014-12-12 18:00:53.305866000 +0400
@@ -186,32 +186,56 @@
DataFlavor flavor,
long format) throws IOException
{
- byte[] bytes = super.translateTransferable(contents, flavor, format);
-
+ byte[] bytes = null;
if (format == CF_HTML) {
- bytes = HTMLCodec.convertToHTMLFormat(bytes);
+ if (contents.isDataFlavorSupported(DataFlavor.selectionHtmlFlavor)) {
+ // if a user provides data represented by
+ // DataFlavor.selectionHtmlFlavor format, we use this
+ // type to store the data in the native clipboard
+ bytes = super.translateTransferable(contents,
+ DataFlavor.selectionHtmlFlavor,
+ format);
+ } else if (contents.isDataFlavorSupported(DataFlavor.allHtmlFlavor)) {
+ // if we cannot get data represented by the
+ // DataFlavor.selectionHtmlFlavor format
+ // but the DataFlavor.allHtmlFlavor format is avialable
+ // we belive that the user knows how to represent
+ // the data and how to mark up selection in a
+ // system specific manner. Therefor, we use this data
+ bytes = super.translateTransferable(contents,
+ DataFlavor.allHtmlFlavor,
+ format);
+ } else {
+ // handle other html flavor types, including custom and
+ // fragment ones
+ bytes = HTMLCodec.convertToHTMLFormat(super.translateTransferable(contents, flavor, format));
+ }
+ } else {
+ // we handle non-html types basing on their
+ // flavors
+ bytes = super.translateTransferable(contents, flavor, format);
}
return bytes;
}
- protected Object translateBytesOrStream(InputStream str, byte[] bytes,
- DataFlavor flavor, long format,
- Transferable localeTransferable)
- throws IOException
- {
+ // The stream is closed as a closable object
+ public Object translateStream(InputStream str,
+ DataFlavor flavor, long format,
+ Transferable localeTransferable)
+ throws IOException {
if (format == CF_HTML && flavor.isFlavorTextType()) {
- if (str == null) {
- str = new ByteArrayInputStream(bytes);
- bytes = null;
- }
+ str = new HTMLCodec(str,
+ EHTMLReadMode.getEHTMLReadMode(flavor));
- str = new HTMLCodec(str, EHTMLReadMode.HTML_READ_ALL);
}
+ return super.translateStream(str, flavor, format,
+ localeTransferable);
+ }
+
+ public Object translateBytes(byte[] bytes, DataFlavor flavor, long format,
+ Transferable localeTransferable) throws IOException {
if (format == CF_FILEGROUPDESCRIPTORA || format == CF_FILEGROUPDESCRIPTORW) {
- if (null != str ) {
- str.close();
- }
if (bytes == null || !DataFlavor.javaFileListFlavor.equals(flavor)) {
throw new IOException("data translation failed");
}
@@ -233,28 +257,23 @@
}
if (format == CFSTR_INETURL &&
- URL.class.equals(flavor.getRepresentationClass()))
+ URL.class.equals(flavor.getRepresentationClass()))
{
- if (bytes == null) {
- bytes = inputStreamToByteArray(str);
- str = null;
- }
String charset = getDefaultTextCharset();
- if (localeTransferable != null && localeTransferable.
- isDataFlavorSupported(javaTextEncodingFlavor))
+ if (localeTransferable != null && localeTransferable.isDataFlavorSupported(javaTextEncodingFlavor))
{
try {
charset = new String((byte[])localeTransferable.
- getTransferData(javaTextEncodingFlavor),
- "UTF-8");
+ getTransferData(javaTextEncodingFlavor), "UTF-8");
} catch (UnsupportedFlavorException cannotHappen) {
}
}
return new URL(new String(bytes, charset));
}
- return super.translateBytesOrStream(str, bytes, flavor, format,
- localeTransferable);
+ return super.translateBytes(bytes , flavor, format,
+ localeTransferable);
+
}
public boolean isLocaleDependentTextFormat(long format) {
@@ -275,18 +294,18 @@
protected String getNativeForFormat(long format) {
return (format < predefinedClipboardNames.length)
- ? predefinedClipboardNames[(int)format]
- : getClipboardFormatName(format);
+ ? predefinedClipboardNames[(int)format]
+ : getClipboardFormatName(format);
}
private final ToolkitThreadBlockedHandler handler =
- new WToolkitThreadBlockedHandler();
+ new WToolkitThreadBlockedHandler();
public ToolkitThreadBlockedHandler getToolkitThreadBlockedHandler() {
return handler;
}
- /**
+ /**
* Calls the Win32 RegisterClipboardFormat function to register
* a non-standard format.
*/
@@ -300,12 +319,12 @@
public boolean isImageFormat(long format) {
return format == CF_DIB || format == CF_ENHMETAFILE ||
- format == CF_METAFILEPICT || format == CF_PNG ||
- format == CF_JFIF;
+ format == CF_METAFILEPICT || format == CF_PNG ||
+ format == CF_JFIF;
}
protected byte[] imageToPlatformBytes(Image image, long format)
- throws IOException {
+ throws IOException {
String mimeType = null;
if (format == CF_PNG) {
mimeType = "image/png";
@@ -347,11 +366,11 @@
int[] nBits = {8, 8, 8};
int[] bOffs = {2, 1, 0};
ColorModel colorModel =
- new ComponentColorModel(cs, nBits, false, false,
- Transparency.OPAQUE, DataBuffer.TYPE_BYTE);
+ new ComponentColorModel(cs, nBits, false, false,
+ Transparency.OPAQUE, DataBuffer.TYPE_BYTE);
WritableRaster raster =
- Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE, width, height,
- width * 3 + pad, 3, bOffs, null);
+ Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE, width, height,
+ width * 3 + pad, 3, bOffs, null);
BufferedImage bimage = new BufferedImage(colorModel, raster, false, null);
@@ -359,7 +378,7 @@
// top-down DIBs.
// So we flip the image vertically and create a bottom-up DIB.
AffineTransform imageFlipTransform =
- new AffineTransform(1, 0, 0, -1, 0, height);
+ new AffineTransform(1, 0, 0, -1, 0, height);
Graphics2D g2d = bimage.createGraphics();
@@ -378,7 +397,7 @@
private static final byte [] UNICODE_NULL_TERMINATOR = new byte [] {0,0};
protected ByteArrayOutputStream convertFileListToBytes(ArrayList fileList)
- throws IOException
+ throws IOException
{
ByteArrayOutputStream bos = new ByteArrayOutputStream();
@@ -402,10 +421,10 @@
return bos;
}
- /**
- * Returns a byte array which contains data special for the given format
- * and for the given image data.
- */
+ /**
+ * Returns a byte array which contains data special for the given format
+ * and for the given image data.
+ */
private native byte[] imageDataToPlatformImageBytes(byte[] imageData,
int width, int height,
long format);
@@ -414,10 +433,8 @@
* Translates either a byte array or an input stream which contain
* platform-specific image data in the given format into an Image.
*/
- protected Image platformImageBytesOrStreamToImage(InputStream str,
- byte[] bytes,
- long format)
- throws IOException {
+ protected Image platformImageBytesToImage(byte[] bytes, long format)
+ throws IOException {
String mimeType = null;
if (format == CF_PNG) {
mimeType = "image/png";
@@ -425,11 +442,7 @@
mimeType = "image/jpeg";
}
if (mimeType != null) {
- return standardImageBytesOrStreamToImage(str, bytes, mimeType);
- }
-
- if (bytes == null) {
- bytes = inputStreamToByteArray(str);
+ return standardImageBytesToImage(bytes, mimeType);
}
int[] imageData = platformImageBytesToImageData(bytes, format);
@@ -443,8 +456,8 @@
DataBufferInt buffer = new DataBufferInt(imageData, len);
WritableRaster raster = Raster.createPackedRaster(buffer, width,
- height, width,
- bandmasks, null);
+ height, width,
+ bandmasks, null);
return new BufferedImage(directColorModel, raster, false, null);
}
@@ -457,13 +470,13 @@
*/
private native int[] platformImageBytesToImageData(byte[] bytes,
long format)
- throws IOException;
+ throws IOException;
protected native String[] dragQueryFile(byte[] bytes);
}
final class WToolkitThreadBlockedHandler extends Mutex
- implements ToolkitThreadBlockedHandler {
+ implements ToolkitThreadBlockedHandler {
public void enter() {
if (!isOwned()) {
@@ -487,7 +500,22 @@
enum EHTMLReadMode {
HTML_READ_ALL,
HTML_READ_FRAGMENT,
- HTML_READ_SELECTION
+ HTML_READ_SELECTION;
+
+ public static EHTMLReadMode getEHTMLReadMode (DataFlavor df) {
+
+ EHTMLReadMode mode = HTML_READ_SELECTION;
+
+ String parameter = df.getParameter("document");
+
+ if ("all".equals(parameter)) {
+ mode = HTML_READ_ALL;
+ } else if ("fragment".equals(parameter)) {
+ mode = HTML_READ_FRAGMENT;
+ }
+
+ return mode;
+ }
}
/**
@@ -576,26 +604,24 @@
htmlSuffix = "