5 Replies Latest reply: Nov 22, 2007 4:56 PM by 807603 RSS

    java.io.StreamCorruptedException: invalid stream header

    807603
      Hello, i am making a file sending program via a network. But when i try to send a linkedlist over the network i always get this error...anyone can help me please. Help is very appreciated!!

      server side
      public LinkedList doSearch(String file) {
           LinkedList results = new LinkedList();
           out.println("<receiveSearch>"+file);
           try {
                oin = new ObjectInputStream(link.getInputStream());
                results=(LinkedList)oin.readObject();
                System.out.println(results);
           } catch (IOException e) {
                e.printStackTrace();
           } catch (ClassNotFoundException e) {
                e.printStackTrace();
           }
           return results;
      }
      client side
      if (input.startsWith("<receiveSearch>"))
           {
                     oout= new ObjectOutputStream(link.getOutputStream());
                  oout.writeObject(ClientController.getInstance().receiveSearch(input.substring(15,input.length())));
           }
      which returns a LinkedList

      java.io.StreamCorruptedException: invalid stream header
           at java.io.ObjectInputStream.readStreamHeader(Unknown Source)
           at java.io.ObjectInputStream.<init>(Unknown Source)
           at Server.IO.Processor.doSearch(Processor.java:159)
           at Server.domein.ServerController.doSearch(ServerController.java:208)
           at Server.domein.ServerFacade.doSearch(ServerFacade.java:96)
           at Server.IO.Processor.run(Processor.java:66)
           at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
           at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
           at java.util.concurrent.FutureTask.run(Unknown Source)
           at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(Unknown Source)
           at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(Unknown Source)
           at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
           at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
           at java.lang.Thread.run(Unknown Source)
        • 1. Re: java.io.StreamCorruptedException: invalid stream header
          DrClap
          You are sending something else besides the serialized LinkedList over that output stream, aren't you? Let's see the part of your code that handles that.
          • 2. Re: java.io.StreamCorruptedException: invalid stream header
            807603
            at the end, in the actual method i got:
            public LinkedList receiveSearch(String file){
                      LinkedList results = new LinkedList();
                      try {
                           file = file.toLowerCase();
                         BufferedReader in = new BufferedReader(new FileReader("C:/filelist.xml"));
                         String str,lowerS;
                         while ((str = in.readLine()) != null) {
                              lowerS = str.toLowerCase();
                              if(lowerS.indexOf("<file name=")!=-1){
                                   lowerS = lowerS.substring(lowerS.indexOf("<file name=")+11, lowerS.indexOf("size=")-1);
                                   if(lowerS.indexOf(file)!=-1){
                                        results.add(str);
                                   }
                              }
                              else if(lowerS.indexOf("<directory")!=-1||lowerS.indexOf("</directory")!=-1){
                                   results.add(str);
                              }       
                         }
                         in.close();
                     } catch (IOException e) {
                          e.printStackTrace();
                     }
                     return results;
                 }
            could it be that the problem is that i add string to the list? i have read something while i was looking for an answer about strings = errors. But how should i send/receive it then because a BufferedReader for input with PrintWriter for output also didn't work?
            • 4. Re: java.io.StreamCorruptedException: invalid stream header
              DrClap
              Okay. So how about answering the question I posed earlier? What you posted there is totally irrelevant to both your question and mine.
              • 5. Re: java.io.StreamCorruptedException: invalid stream header
                807603
                hmm, no i'm not using the object streams anywhere else
                but my problem is solved, i used the bufferedreader / printwriter to send the results as single strings...

                thx ;)