Solved

document loading from Mac browser

Posted on 1998-11-19
6
162 Views
Last Modified: 2010-03-30
I've written an applet that reads text from a file on the server.  The file is in the same directory as the applet.  I've verified that it's got the right filename and path.  However, no data is getting read in.  This applet works on win95 and NT in Netscape 3 and 4 and in IE3 and IE4.  It also works on UNIX, both SGI and Solaris.  However, it is currently failing on both Netscape 3 and 4 on the Macintosh.  This applet is running all 1.02 JDK code, and I tried compiling with both a 1.02 and 1.1.x compiler.  

In every case, no data is showing up.  Here's the snippet where I read in the data:

try {
  url = new URL(getCodeBase, "data");
  stream = url.openStream();
 
  is = new DataInputStream(stream);
 
  while (is.available() > 0) {
    v.addElement(is.readLine());
  }

-Tony
0
Comment
Question by:rembo
  • 3
  • 2
6 Comments
 
LVL 5

Expert Comment

by:fontaine
ID: 1227904
Just a remark. The way you are using the readLine() method of DataInputStream does not
seem correct to me. I would personally write the following:

String line = "";

while((line = is.readLine()) != null) {
    v.addElement(line);
}

Could you replace your current code by the one above and have a try?
0
 
LVL 6

Expert Comment

by:gadio
ID: 1227905
Tony, have you tried it on IE for mac? Also, on what stage does that code hanges? after the openStream? After the first readLine? Maybe the EOF is not tested correctly (as fontaine suggests).
0
 
LVL 4

Author Comment

by:rembo
ID: 1227906


Actually, fontaine's feedback fixed my problem.  It's really
strange though because, technically, my code is correct.  I
should be able to use the available() routine to determine
if I can read from the file or not, but it doesn't appear
to work on the Mac.  Fontaine, if you post a null message
as an answer, I'll be happy to give you the points.  

Thanks!

-Tony

0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 5

Accepted Solution

by:
fontaine earned 100 total points
ID: 1227907
:-)
0
 
LVL 6

Expert Comment

by:gadio
ID: 1227908
Tony, I think you might have a mistake there. You can't use the available() routine since its only indicating "the number of bytes that can be read from this input stream without blocking", so there can actually be more bytes to read from the file but not in the OS / VM buffer. You get to see this sort of bugs a lot when you move your code from one OS to another.
0
 
LVL 5

Expert Comment

by:fontaine
ID: 1227909
I agree with Gadio.  What probably happended is that there was nothing "ready to use"
when the loop was reached. Hence, nothing happended. The code I proposed works because readLine() is blocking until an EOL is reached.
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now