 |
 |
java-ASCII-chr-codes with OS X the same like with win???
|
 |
|
 |
|
Junior Member
Join Date: Apr 2001
Status:
Offline
|
|
hi there,
i've a .java-class that reads a file with int x = read(); - this class works in win NT (visual age for java) - i now have tested this class with os x and project builder and it fails to work. my question: are the chr-ascII-codes the same like in windows? or do i have to change the integer-values for slash, whitespace and return, questionmark and < or > (GT LT)?
thx 
granny
|
|
grannysmith
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Apr 2001
Location: brooklyn, ny
Status:
Offline
|
|
Wouldn't it be better to read it in as a byte or a char? what code are you using to see the character?
System.out.println(xxx) or is it being displayed in a text field or something?
are you casting this int to a char or byte and then printing the character out? are you using RandomAccessFile or FileInputStream?
and what exactly fails to work? does it not compile or does it display an incorrect character?
not sure why it would work any different between NT and MacOSX.
|
|
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Apr 2001
Location: brooklyn, ny
Status:
Offline
|
|
To answer your original question though I had the understanding that aschii was the same codes everywhere.
What could be a problem though would be if the file you are reading was created (written) on a pc. Then you might be dealing with little endian/big endian issues. That would defintely cause an int to have the wrong value.
|
|
|
| |
|
|
|
 |
|
 |
|
Junior Member
Join Date: Apr 2001
Status:
Offline
|
|
oh hi - it's you again 
i don't give the text out to display. the text in the file shall be parsed to do s.th. the routine is s.th. like this:
while ((ct & LT) == 0) {
c = read();
ct = c < 256 ? ctype[c] : ALPHA;
}
ALPHA is set to 8, LT is the left bracket of a xml tag. the class tests for the following:
setCharType(WHITESPACE, 32);
setCharType(WHITESPACE, 9);
setCharType(WHITESPACE, 10);
setCharType(WHITESPACE, 13);
setCharType(LT, 60);
setCharType(GT, 62);
setCharType(SINGLEQUOTE, 39);
setCharType(QUOTE, 34);
setCharType(SLASH, 47);
setCharType(EQUALS, 61);
setCharType(QUESTIONMARK,63);
do you know if these are the codes for the char-types as well on the mac? my thought is that the mac uses other codes for these chars.
by the way, do you know in with way the & influences the test on a
while ((ct & WHITESPACE) != 0) statement???
it's not the same as ct && WHITESPACE, right? so what does this single & do?
greets and thx,
granny
|
|
grannysmith
|
| |
|
|
|
 |
|
 |
|
Junior Member
Join Date: Apr 2001
Status:
Offline
|
|
oh i forgot to tell what exactly goes wrong. the parsing of the file from which is to read doesn't stop before the eof. so i think a 'must-find-character' can't be found by the routine.
|
|
grannysmith
|
| |
|
|
|
 |
|
 |
|
Junior Member
Join Date: Apr 2001
Status:
Offline
|
|
the text files were written on a win pc - is there a way to automatically convert to mac? i just opened and saved each of the files with BBEdit - but it doesn't work...
|
|
grannysmith
|
| |
|
|
|
 |
|
 |
|
Dedicated MacNNer
Join Date: Oct 2000
Location: Pasadena, CA, USA
Status:
Offline
|
|
Lower-byte Ascii codes (i.e. less than 128) are the same on every platform - OS 9, OS X, or Windows. High-byte values (generally used for accented characters and such) ARE different, and that may be where you're having problems.
But I think there are other problems with your code. For example, there are easier ways to test if a character is white space - use java.lang.Character.isWhitespace(). And if you're wanting to stop processing when the character you read in, rather than some modified value, as in
> while ( (char)c != '<' )
Finally, if what you're doing is parsing the contents of an XML file, why aren't you using one of the already existing libraries that will do it for you, like IBM's xml4j (available at www.alphaworks.ibm.com)? It looks to me like you're re-inventing the wheel here.
|
|
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Apr 2001
Location: brooklyn, ny
Status:
Offline
|
|
i have to agree with eyadams that there looks like there's easier ways to do what your trying to do. I've never done xml parsing but you might look at one and see if it works for you. And if the file you're reading was written out using a java app on PC then you should be fine (no big/little endian issues).
Regarding your other question:
while ((ct & WHITESPACE) != 0) statement???
it's not the same as ct && WHITESPACE, right? so what does this single & do?
I don't think "ct && WHITESPACE" would be a valid java statement unless ct and WHITESPACE are boolean types and they would have to be integer to test against 0. When doing a logical test "&&" just means if the first operand is false then the second one will not even be evaluated because the overall result will be false regardless "(false && false) = false" and "(false && true)= false".
|
|
|
| |
|
|
|
 |
|
 |
|
Dedicated MacNNer
Join Date: Oct 2000
Location: Pasadena, CA, USA
Status:
Offline
|
|
brooklyn_mac_guy is right : "int && int" is not a valid Java statement, and will result in a compile time error. "&&" is boolean and; "&" is a bitwise and. He is also right that in Java if the left operand in a "&&" test is false the second operand is never evaluated; this makes statements like this work:
> if (foo != null && foo.someMethod())
If both operands were evaluated, and foo was null, this statement would result in a NullPointerException.
So, grannysmith: what are you trying to do?
|
|
|
| |
|
|
|
 |
|
 |
|
Junior Member
Join Date: Apr 2001
Status:
Offline
|
|
hi all
thx for your helping comments on my problems  - the thing is, that i haven't written the code for parsing these xml-alike-text-files. the language which is parsed is a new one called centity markup language and there are no standard libraries one can use to parse these files. (but it's interesting that there are some for parsing real xml - cool). by the way, i've analysed the source code and it seems that in a folder all included files are opened and the app tries to parse them. in my os x folder there are hidden files .DStore or somewhat... i removed this file and it seems to work... it's difficult to say if everything runs well but i've no more error msg's. my question now is the following: the project includes two starting classes - one is the server-application and the other a client. how can i make two different executable files out of my project and how can i create a new MRJApp.properties file which will be used. i tried creating a new target and marked the client (after i've done the server-compilation) class. i added a new file MRJApp2.properties and copied the content of MRJApp.properties to it, changing the main-class and s.th. but at compiling it says 'couldn't open MRJApp.properties' - what can i do here?
2nd thing the '&&' - '&' - it's interesting. how does this bitwise & work?
thx again 
greets,
granny
[This message has been edited by grannysmith (edited 05-31-2001).]
|
|
grannysmith
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Apr 2001
Location: brooklyn, ny
Status:
Offline
|
|
bitwise "&" evaluates bits in integers. If one or both bits are 0 then the result is 0. The result is 1 ONLY if both bits are 1.
1 & 1 = 1
1 & 0 = 0
0 & 1 = 0
0 & 0 = 0
so
(3 & 1)
would be evaluated at the bit level (the bits immediately above and below each other)
00000011 (binary 3)
00000001 & (binary 1)
----------
00000001
so (3 & 1) would = 1. there's also "^" (exclusive or) and "|" (or) which are similiar operators but evaluate differently.
[This message has been edited by brooklyn_mac_guy (edited 05-31-2001).]
[This message has been edited by brooklyn_mac_guy (edited 05-31-2001).]
|
|
|
| |
|
|
|
 |
|
 |
|
Junior Member
Join Date: Apr 2001
Status:
Offline
|
|
hmm - i see. that's a very pretty thing... thx. (more questions will follow in new threads i think *g*)
greets,
granny
|
|
grannysmith
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|