Trouble resolving a StreamCorruptedException
Hey guys. ;)
I'm having trouble resolving a java.io.StreamCorruptedException exception. I'm working on a system that supports file management over a network connection. So, I've built my own file service and other things. The strange thing is, it works most of the time. I'm testing it for "large" files, say 5MB each, not really large. But anyway, when I transmit about 15 MB or more it pops this exception. But for 11 files each about 800 KB, there's no problem. Also, if I transmit 10 MB, reset the server's services and then transmit the other 5 MB there's no problem. Bazaar. The server I wrote gave me this log printout:
Code:
database service started
server control service started
file service started
Server started, IP Address 192.168.1.101
Node connected: 192.168.1.101
Exception caught: [COLOR="RoyalBlue"]java.io.StreamCorruptedException[/COLOR]: invalid type code: 00
Stack Trace:
1
Method: readObject0
Class: java.io.ObjectInputStream
Line: 1356
2
Method: readObject
Class: java.io.ObjectInputStream
Line: 351
3
Method: run
Class: jnet.core.[COLOR="RoyalBlue"]JNetDownStream[/COLOR]
Line: 57
4
Method: run
Class: java.lang.Thread
Line: 619
Node disconnected: 192.168.1.101
Exception caught: java.lang.Exception: JNet file transfer timed out
Stack Trace:
1
Method: run
Class: jnet.file.JNetFileReciever
Line: 77
2
Method: run
Class: java.lang.Thread
Line: 619
So it looks like the downstream class is causing the trouble. Don't know why, because it works perfectly except for this.
jnet.core.JNetDownStream.java
Code:
package jnet.core;
import java.util.*;
import java.net.*;
import java.io.*;
public class JNetDownStream implements Runnable {
protected boolean running = true;
protected boolean reading = false;
protected Vector<JObjectListener> objectListeners;
protected Thread thread;
protected InputStream inputStream;
protected BufferedInputStream buffer;
protected ObjectInputStream objectInputStream;
protected JDisconnectable disconnectable;
public JNetDownStream(InputStream inputStream, JDisconnectable disconnectable) {
try {
this.disconnectable = disconnectable;
this.inputStream = inputStream;
buffer = new BufferedInputStream(this.inputStream);
objectInputStream = new ObjectInputStream(buffer);
objectListeners = new Vector<JObjectListener>();
thread = new Thread(this);
thread.start();
} catch (Exception e) {
JNetException.notifyExceptionThrown(e);
abort();
}
}
protected void abort() {
disconnectable.abort();
stop();
}
protected void notifyObjectListeners(Object object) {
for (JObjectListener objectListener : objectListeners)
objectListener.objectRead(object);
}
public void addObjectListener(JObjectListener objectListener) {
objectListeners.add(objectListener);
}
public void removeObjectListener(JObjectListener objectListener) {
objectListeners.remove(objectListener);
}
public void run() {
while (running) {
try {
Thread.sleep(20);
reading = true;
Object next = objectInputStream.readObject();
reading = false;
notifyObjectListeners(next);
} catch (EOFException f) {
// ignore
} catch (SocketTimeoutException t) {
// ignore
} catch (Exception e) {
reading = false;
JNetException.notifyExceptionThrown(e);
abort();
} finally {
reading = false;
}
}
}
public void stop() {
running = false;
try {
while (reading) {
Thread.sleep(100);
}
} catch (Exception e) {
// ignore
}
}
}
Please note that I have a lot of related classes. 25 in the network component alone. I think this problem could be a Java bug. I've got the latest JRE (6) installed.
I've spent a lot of time on Google on this. Maybe someone can help.
Thank you. ;)
Tim