Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Failure in ByteArrayTransfer nativeToJava()
Failure in ByteArrayTransfer nativeToJava() [message #464268] Sat, 19 November 2005 17:55 Go to next message
Paul E. Keyser is currently offline Paul E. KeyserFriend
Messages: 878
Registered: July 2009
Senior Member
R3.1.1

I have subclassed ByteArrayTransfer, for my data-class (of type IQuery), per the code snippets in
the javadocs to ByteArrayTransfer; and I am accessing the Clipboard, per the code snippets in the
javadocs to Clipboard.

Debugging confirms that the Clipboard receives my data without error. But when I try to retrieve the
data from the Clipboard, line 200 of ByteArrayTransfer#nativeToJava() -- if (transferData.result !=
COM.S_OK) return null; -- returns null; the value of transferData.result is -2147024882.

Moreover, when the execution reaches my javaToNative() method -- below --, the type of Object is
*NOT* an array of IQuery, as the code snippets in ByteArrayTransfer lead me to expect, but
apparently a String (the serialised value of my IQuery[]). Cleary that will result in the null
described above.

But why is javaToNative() being called, by ByteArrayTransfer.nativeToJave(), with the wrong
parameter? Here's the call-stack:

Thread [main] (Suspended (breakpoint at line 54 in SemanticQueryTransfer))
SemanticQueryTransfer.javaToNative(Object, TransferData) line: 54
Clipboard.GetData(int, int) line: 579
Clipboard.access$3(Clipboard, int, int) line: 543
Clipboard$1.method3(int[]) line: 498
COMObject.callback3(int[]) line: 90
COM.VtblCall(int, int, FORMATETC, STGMEDIUM) line: not available [native method]
IDataObject.GetData(FORMATETC, STGMEDIUM) line: 25
SemanticQueryTransfer(ByteArrayTransfer).nativeToJava(Transf erData) line: 198
SemanticQueryTransfer.nativeToJava(TransferData) line: 88
Clipboard.getContents(Transfer, int) line: 317
Clipboard.getContents(Transfer) line: 241

thanks,
Paul

Here is the beginning of my nativeToJava() method - he rest is never caled, because of the
null-return from super.nativeToJava()!

if (isSupportedType(transferData)) {
byte[] buffer = (byte[]) super.nativeToJava(transferData);
if (buffer == null) {
return null;
}

Here is my javaToNative() method -- whose implementation also probably doesn't matter, since it is
never called either, due to the failure of the Object to be of the correct type!

protected void javaToNative(final Object object, final TransferData transferData) {
if (object == null || !(object instanceof IQuery[])) {
return;
}

if (isSupportedType(transferData)) {
final IQuery[] queries = (IQuery[]) object;
try {
// write data to a byte array and then ask super to convert
final ByteArrayOutputStream out = new ByteArrayOutputStream();
final DataOutputStream writeOut = new DataOutputStream(out);

for (IQuery query : queries) {
final byte[] buffer = query.toString().getBytes();
writeOut.writeInt(buffer.length);
writeOut.write(buffer);
}
final byte[] buffer = out.toByteArray();
writeOut.close();

super.javaToNative(buffer, transferData);

} catch (IOException ioe) {
ioe.printStackTrace();
; // TODO keyser: handle somehow
}
}
}
Re: Failure in ByteArrayTransfer nativeToJava() -- SOLVED [message #464335 is a reply to message #464268] Mon, 21 November 2005 17:22 Go to previous message
Paul E. Keyser is currently offline Paul E. KeyserFriend
Messages: 878
Registered: July 2009
Senior Member
Doh!

My fault: I took the code-snippets in Clipboard too literally, and serialised my MyData[] into a
String -- rather than passing it in as MyData[] -- and so of course the javaToNative() method was
receiving a String. Just had to sleep on it and work on other code for a few days, so that when I
looked at it again, all became embarassingly clear.

Paul
Previous Topic:Weird Layout Resizing Issue
Next Topic:Moving focus to the next table cell in TableViewer
Goto Forum:
  


Current Time: Fri Apr 26 17:59:26 GMT 2024

Powered by FUDForum. Page generated in 0.03029 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top