Brian Bohnet wrote:
>
> Heres the code snippet of reading/writing the file:
>
> FileInputStream fis = new FileInputStream(dataFile);
> dt.run();
>
> public void run() {
> int count = totalsize / BLKSIZE;
> int datasize = totalsize / count;
> for ( int i = 0; i<count; i++ ) {
> datasize = fis.read();
> byte[] dataArray = new byte[ datasize ];
> out.write( dataArray );
> }
> }
>
This code can't be working at all like you expect.
First, you appear to be trying to start a new thread,
but are using Thread.run() instead of Thread.start().
That means you're just calling the run() method directly
in the same thread, not spawning a new thread[1]. But
that's good, because if you had succeeded in spawning a
new thread the container would have flushed and closed
the response output stream out from under you, as per
the servlet spec[2]
Second, the code in run() is very wrong. It may be that
it's just typed into the email incorrectly, but as it
stands it doesn't make any sense at all. It will write
gibberish to the output stream. Plus, reading one byte
at a time from a file is very evil.
I understand that the code in the message might just
be a quick pseudo-code summary of what's really going
on. But if it's at all accurate, there are some serious
problems with the implementation.
If you want to post the actual code that was giving
you problems, I'm sure there are any number of people
here (and on the perhaps-more-on-topic servlet-interest
list) who can help nail down exactly what's really
happening, and find a solid solution.
[1] Check out the javadocs for the java.lang.Thread class,
or read through the relevant sections of the Java Tutorial:
http://java.sun.com/docs/books/tutorial/essential/threads/
[2] Section SRV.5.6 says "Each response object is valid
only within the scpoe of a servlet's service method". The
servlet spec (unlike most) is easy to read and informative
for users as well as spec-implementors. You can download
the spec for yourself at:
http://java.sun.com/products/servlet/download.html
[3] Check the javadocs for java.io.FileInputStream, esp
the read() method. It returns the byte just read, not a
length:
http://java.sun.com/j2se/1.3/docs/
--
Christopher St. John [EMAIL PROTECTED]
DistribuTopia http://www.distributopia.com
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:
http://archives.java.sun.com/jsp-interest.html
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.jsp
http://www.jguru.com/faq/index.jsp
http://www.jspinsider.com