Failure in ByteArrayTransfer nativeToJava() [message #464268] |
Sat, 19 November 2005 17:55 |
Paul E. Keyser 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
}
}
}
|
|
|
|
Powered by
FUDForum. Page generated in 0.03029 seconds