Article View: comp.lang.java.api
Article #13Strange I/O behavior
From: Michael Tobin
Date: Thu, 07 Dec 2000 04:18
Date: Thu, 07 Dec 2000 04:18
84 lines
4402 bytes
4402 bytes
I've been trying to get a java program to run on my Mac. It is a
microprogramming simulator (for use with "Structured Computer
Organization" by Andrew Tanenbaum). The package comes with an assembly
language assembler and a microprogram assembler. The problem is that it
runs perfectly well on Windows and Unix systems, but for some reason, it
will not work on my Mac. After much effort and debugging, I have found
the culprit (the variable 'in' is of type BufferedInputStream):
private String readLine()
{
int ctemp;
String s = new String();
try
{
int ch = 0;
while (((char)ch) != '\n' && ch > -1)
{
ch = in.read();
if (ch == -1 && s.length() == 0)
{
return null;
}
if (ch == '/')
{
ctemp = in.read();
if ((char)ctemp == '/')
{
ch = in.read();
/***********************************************************************/
/* This loop right HERE!
while (((char)ch) != '\n' && ch > -1)
{
ch = in.read();
}
/**********************************************************************/
lineno++;
return s + " ";
}
else if (ch != 13)
{
s = s + ((char)ch) +
Character.toLowerCase((char)ctemp);
}
}
if (ch != '\n' && ch > -1 && ch != 13)
{
if ((char)ch == '\'')
{
ctemp = in.read();
s = s + (char)ch + (char)ctemp;
}
else
{
s = s + Character.toLowerCase((char)ch);
}
}
}
lineno++;
return s;
}
catch (Exception e)
{
e.printStackTrace();
}
return s;
}
For some reason, this has to do with the Macintosh style line breaks
because if I resave my files with Unix line breaks everything compiles
just fine. But for some reason it will not work on a Macintosh. Most
of my test programs start out with a bunch of commented lines (in the
assembly language comments are delimited with the // marker just like in
Java or C++). It works just fine until it reaches the statement
'ch=in.read()' in the area I marked off. Then it seems that the read
method won't return (when I try stepping through the code line by line)
or just returns -1 which indicates it has reached the end of the stream.
however, I've inspected the input buffer and see that there are is an
entire list of valid input data to be read. Does anyone have any idea
what could possibly be going on here? I know it's rather
complicated--at least it seems to me--but any help on why it works with
Unix line breaks but not Mac ones would be greatly appreciated. Thanks!
Mike Tobin
Technical Details
Message-ID:
<mtobin-99A222.22175206122000@news.earthlink.net>Path:
arc1-ca.pugleaf.net!supernews.google.com!sn-xit-02!sn-xit-01!supernews.com!newsfeed.stanford.edu!xfer10.netnews.com!netnews.com!newsfeed2.earthlink.net!newsfeed.earthlink.net!newsmaster1.prod.itd.earthlink.net!newsread2.prod.itd.earthlink.net.POSTED!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10bcce,139b3b33219ebf5,start X-Google-Attributes: gid10bcce,public X-Google-Thread: fecd1,139b3b33219ebf5,start X-Google-Attributes: gidfecd1,public X-Google-Thread: f635e,139b3b33219ebf5,start X-Google-Attributes: gidf635e,public X-Google-ArrivalTime: 2000-12-06 20:18:06 PST Path: arc1-ca.pugleaf.net!supernews.google.com!sn-xit-02!sn-xit-01!supernews.com!newsfeed.stanford.edu!xfer10.netnews.com!netnews.com!newsfeed2.earthlink.net!newsfeed.earthlink.net!newsmaster1.prod.itd.earthlink.net!newsread2.prod.itd.earthlink.net.POSTED!not-for-mail From: Michael Tobin <mtobin@macalester.edu> Newsgroups: comp.lang.java.api,comp.sys.mac.programmer.codewarrior,codewarrior.mac Subject: Strange I/O behavior User-Agent: MT-NewsWatcher/3.0 (PPC) Message-ID: <mtobin-99A222.22175206122000@news.earthlink.net> Lines: 84 Date: Thu, 07 Dec 2000 04:18:06 GMT NNTP-Posting-Host: 141.140.103.128 X-Complaints-To: abuse@earthlink.net X-Trace: newsread2.prod.itd.earthlink.net 976162686 141.140.103.128 (Wed, 06 Dec 2000 20:18:06 PST) NNTP-Posting-Date: Wed, 06 Dec 2000 20:18:06 PST Organization: EarthLink Inc. -- http://www.EarthLink.net