Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » calling all dnd experts...
calling all dnd experts... [message #437865] Fri, 11 June 2004 15:32 Go to next message
Matthew Hatem is currently offline Matthew HatemFriend
Messages: 47
Registered: July 2009
Member
I'm trying build support for dragging attachments out of an email client
into my Eclipe RCP application.

I've extended ByteArrayTransfer and nativeToJava am basically going over
all the bytes as needed and writing them to a temp file. This all works
well and good, only problem is I'm having difficulty a) getting
file/attachment count and b) getting the file name.

a) When I get to the bytes that represent the file count, basically just
a DWORD, the bytes look like a copy of the raw memory and readInt()
doesn't handle the byte/word swapping. Is there a utiltiy method I can
use to help me out here?

b) When I get to the collection of bytes that represent the file name,
the bytes were literally changed into chars... UNICODE chars to be
precise... 2 bytes per character. "ASCII" characters are their character
code with a 0 as the 2nd byte. Is there some MultiByteToXXX utility
function I can call to help me here?
Re: calling all dnd experts... [message #437873 is a reply to message #437865] Fri, 11 June 2004 16:32 Go to previous messageGo to next message
Simone Gianni is currently offline Simone GianniFriend
Messages: 29
Registered: July 2009
Junior Member
Matthew Hatem wrote:
> I'm trying build support for dragging attachments out of an email client
> into my Eclipe RCP application.
>
> I've extended ByteArrayTransfer and nativeToJava am basically going over
> all the bytes as needed and writing them to a temp file. This all works
> well and good, only problem is I'm having difficulty a) getting
> file/attachment count and b) getting the file name.
>
> a) When I get to the bytes that represent the file count, basically just
> a DWORD, the bytes look like a copy of the raw memory and readInt()
> doesn't handle the byte/word swapping. Is there a utiltiy method I can
> use to help me out here?

Not in java itself AFAIK. But you should be able to do it with a few
"<<" and ">>" (shift left and shift right) operations.

>
> b) When I get to the collection of bytes that represent the file name,
> the bytes were literally changed into chars... UNICODE chars to be
> precise... 2 bytes per character. "ASCII" characters are their character
> code with a 0 as the 2nd byte. Is there some MultiByteToXXX utility
> function I can call to help me here?

byte[] namebytes = ....
String name = new String(namebytes, "UTF-16");

Hope this helps,
Ciao,

Simone Gianni
Re: calling all dnd experts... [message #437898 is a reply to message #437873] Fri, 11 June 2004 16:54 Go to previous messageGo to next message
Matthew Hatem is currently offline Matthew HatemFriend
Messages: 47
Registered: July 2009
Member
Thanks for the help. Actually for the name I had to do the following.

byte[] bytes = new byte[size];
byte[] finalBytes = new byte[size+2];
finalBytes[0] = (byte)0xFF; finalBytes[1] = (byte)0xFE;
readIn.read(bytes);
System.arraycopy(bytes, 0, finalBytes, 2, bytes.length);
datum.sFileName = new String(finalBytes, "UTF-16");

Seems I needed the 0xFF and 0xFE headers.

Simone Gianni wrote:

> Matthew Hatem wrote:
>
>> I'm trying build support for dragging attachments out of an email
>> client into my Eclipe RCP application.
>>
>> I've extended ByteArrayTransfer and nativeToJava am basically going
>> over all the bytes as needed and writing them to a temp file. This
>> all works well and good, only problem is I'm having difficulty a)
>> getting file/attachment count and b) getting the file name.
>>
>> a) When I get to the bytes that represent the file count, basically
>> just a DWORD, the bytes look like a copy of the raw memory and
>> readInt() doesn't handle the byte/word swapping. Is there a utiltiy
>> method I can use to help me out here?
>
>
> Not in java itself AFAIK. But you should be able to do it with a few
> "<<" and ">>" (shift left and shift right) operations.
>
>>
>> b) When I get to the collection of bytes that represent the file name,
>> the bytes were literally changed into chars... UNICODE chars to be
>> precise... 2 bytes per character. "ASCII" characters are their
>> character code with a 0 as the 2nd byte. Is there some MultiByteToXXX
>> utility function I can call to help me here?
>
>
> byte[] namebytes = ....
> String name = new String(namebytes, "UTF-16");
>
> Hope this helps,
> Ciao,
>
> Simone Gianni
Re: calling all dnd experts... [message #437899 is a reply to message #437873] Fri, 11 June 2004 17:32 Go to previous message
Matthew Hatem is currently offline Matthew HatemFriend
Messages: 47
Registered: July 2009
Member
To handle a) <<>> wouldn't work as I would lose information unless Java
has support for circular shifts. So I did the following:

byte[] countBytes = new byte[4];
for (int i=3; i>=0; i--) {
countBytes[i] = readIn.readByte();
}
ByteArrayInputStream countIn = new ByteArrayInputStream(countBytes);
DataInputStream countReadIn = new DataInputStream(countIn);
int count = countReadIn.readInt();



Simone Gianni wrote:

> Matthew Hatem wrote:
>
>> I'm trying build support for dragging attachments out of an email
>> client into my Eclipe RCP application.
>>
>> I've extended ByteArrayTransfer and nativeToJava am basically going
>> over all the bytes as needed and writing them to a temp file. This
>> all works well and good, only problem is I'm having difficulty a)
>> getting file/attachment count and b) getting the file name.
>>
>> a) When I get to the bytes that represent the file count, basically
>> just a DWORD, the bytes look like a copy of the raw memory and
>> readInt() doesn't handle the byte/word swapping. Is there a utiltiy
>> method I can use to help me out here?
>
>
> Not in java itself AFAIK. But you should be able to do it with a few
> "<<" and ">>" (shift left and shift right) operations.
>
>>
>> b) When I get to the collection of bytes that represent the file name,
>> the bytes were literally changed into chars... UNICODE chars to be
>> precise... 2 bytes per character. "ASCII" characters are their
>> character code with a 0 as the 2nd byte. Is there some MultiByteToXXX
>> utility function I can call to help me here?
>
>
> byte[] namebytes = ....
> String name = new String(namebytes, "UTF-16");
>
> Hope this helps,
> Ciao,
>
> Simone Gianni
Previous Topic:Spinner Control
Next Topic:table cell editing inconsistent across platforms
Goto Forum:
  


Current Time: Thu Mar 28 14:14:59 GMT 2024

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

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

Back to the top