Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: com.apple.eio



On Thursday, March 18, 2004, email@hidden wrote:

So the prefs folder is (int) ('p' << 24) + ('r' << 16) + ('e' << 8) + 'f' ?
or is it the other way round?

That is the correct order, however remember that Java chars
are 16 bit Unicode values, and the Mac OSType values use 8
bit values in the Mac character encoding. You can get the
set of 8-bit values using either:
byte[] data = "pref".getBytes();
or
byte[] data = "pref".getBytes("MacRoman");

(the former uses the default character encoding for the
platform, the later specifically uses the Mac encoding,
and will throw an exception if the encoding is not
available). Another possible 8-bit encoding would be
"US-ASCII", but there are subtle differences in the
extended characters (i.e. those above 0x7F). That will
get you as close as possible on non-Macs. To assemble the
bytes into an int value:
int val = 0;
for (int ix = 0 ; ix < data.length ; ++ix)
val = (val << 8) | (data[ix] & 0x00FF);

Dmitry Markman mentioned that com.apple.mrj.MRJOSType is
still present in the current 1.4.x JVM, however there is no
indication of how much longer it will still be available.
I use a routine I wrote that attempts to use MRJOSType by
reflection, and if that fails it falls back to grabbing
the bytes and assembling the constant itself. Its a PITA,
but it ensures that if Apple removes this class in some
future release, our software won't suddenly break when our
customers run Software Update.

Using reflection also simplifies handling the differences
between pre-1.4.1 findFolder and its post-1.4.1 replacement
(the former takes an MRJOSType parameter, the latter an int).
I use the aforementioned routine to obtain an Object, either
an MRJOSType on 1.3.1 and earlier, or an Integer (possibly
obtained from an MRJOSType) on 1.4.1 and later. I invoke the
findFolder method by reflection, which will auto-magically
convert the Integer to an int for me (using Method.invoke).
This code works on all Macs from MRJ 2.2 through 1.4.2.


Doug Zwick, Software Developer /---------------------------------------------/
http://www.elluminate.com/ / "Thank God we don't get all the Government
email@hidden / we pay for." -- Will Rogers
============================/
_______________________________________________
java-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/java-dev
Do not post admin requests to the list. They will be ignored.




Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.