Results 1 to 1 of 1
  1. #1
    tim's Avatar
    tim
    tim is offline Senior Member
    Join Date
    Dec 2007
    Posts
    435
    Rep Power
    8

    Default 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:
    Java 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
    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
    Last edited by tim; 07-22-2009 at 11:31 PM.
    Eyes dwelling into the past are blind to what lies in the future. Step carefully.

Similar Threads

  1. Replies: 8
    Last Post: 11-05-2010, 11:26 PM
  2. StreamCorruptedException
    By cristo_haris in forum Advanced Java
    Replies: 11
    Last Post: 04-20-2009, 04:44 PM
  3. StreamCorruptedException and Casting troubles
    By Wassa in forum Networking
    Replies: 2
    Last Post: 02-18-2009, 04:07 PM
  4. java.io.StreamCorruptedException
    By elizabeth in forum Advanced Java
    Replies: 1
    Last Post: 08-06-2007, 07:45 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •