🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.language
Article #8319

SERIALIZING an object containing a NON serializable object ?

#8319
From: Laurent Souriau
Date: Fri, 30 Mar 2001 13:21
199 lines
5563 bytes
        hi ,


I 've been trying to send an object that contains as a member data
a NON seriazable object (class BufferedReader ).

It keeps me giving an error of type :

"java.io.WriteAbortedException: Writing aborted by exception;"
"java.io.NotSerializableException: java.io.BufferedReader"

Anybody who has an idea would be welcome


Here is my class code :

*************************************
package com.aqsacom.roamingclient;


import *****

public class TableReader implements Serializable
{

private String [] keys;

private BufferedReader data;

private int tableNumber = 0;
private boolean end = false;
private String content;
private int [] breakPoints;

public TableReader(BufferedReader donnee)
{

  try
  {
     data   = donnee;
     initKeys(donnee.readLine(),donnee.readLine());
  }
  catch (IOException e) {e.printStackTrace();}
  skip();
}

// Pour serialization il faut un constructeur sans arguments
public TableReader()
{

}


public TableReader(String fileName) throws java.io.FileNotFoundException
{
   this(new BufferedReader(new FileReader(fileName)));
}


public TableReader(File fichier) throws java.io.FileNotFoundException
{
   this(new BufferedReader(new FileReader(fichier)));
}

public String [] getAllKeys()
{
  return keys;
}

private void makeElement(String line, Hashtable N)
{
   if (line == null) return;
   for (int i=0;i<keys.length;i++)
   {
      if (breakPoints[i+1]>line.length())
 {N.put(keys[i], line.substring(breakPoints[i],line.length()).trim());}
      else{N.put(keys[i],
line.substring(breakPoints[i],breakPoints[i+1]).trim());}
   }
}


private void makeElement(String line, Vector v)
{
   if (line == null) return;
   v.setSize(keys.length);
   for (int i=0;i<keys.length;i++)
   {
        if (breakPoints[i+1]>line.length())
 {v.add(i, line.substring(breakPoints[i],line.length()).trim());}
 else{v.add(i, line.substring(breakPoints[i],breakPoints[i+1]).trim());}
   }
}


private void initKeys(String titleLine, String tiretLine)
{
   Vector v = new Vector();
   int start = 0;
   int end =0;
   while (end>=0)
   {
        v.addElement(new Integer(end));
        start=end;
        end = tiretLine.indexOf(32,start+1);
   }

   breakPoints = new int[v.size()];
   int vSize = v.size();
   for (int i=0;i<vSize;i++)
   {
        breakPoints[i] = ((Integer)v.get(i)).intValue();
   }
   keys = new String [vSize-1];
   for (int j=0;j<breakPoints.length-1;j++)
   {
      keys[j] = titleLine.substring(breakPoints[j],breakPoints[j+1]).trim();
   }
}

public int extractInfo(Hashtable t)
{
   if (content == null) {return 0;}
   String returnV = new String (content);
   content = null;
   makeElement(returnV,t);
   int tableNo = tableNumber;
   skip();
   return tableNo;
}

public int extractInfo(Vector v)
{
   if  ( (content == null) || (end==true) ) {return 0;}
   v.clear();
   String returnV = new String (content);
   content = null;
   makeElement(returnV,v);
   int tableNo = tableNumber;
   skip();
   return tableNo;
}


private String read()
{
   if (content == null) {return null;}
   String returnV = new String (content);
   content = null;
   return returnV;
}


public boolean isEOF()  {return end;}


private void skip()
{
   try
   {
      content = data.readLine();
      if (content==null) {end=true;return;}
      if ( content.equals("") )
      {   tableNumber = tableNumber +1;
         String firstK = data.readLine();
  if (firstK!=null) {initKeys(firstK,data.readLine());skip();}
     else {end=true;
         data.close();
         return;}
      }
    }
    catch(IOException e) {e.printStackTrace();}
}


  private void writeObject(ObjectOutputStream s) throws IOException
 {
    s.defaultWriteObject();
    // customized serialization
    s.writeObject(data);
    s.flush();

 }

 private void readObject(ObjectInputStream s) throws IOException,
ClassNotFoundException
 {
    s.defaultReadObject();
    // customized deserialization code
    //   ...
    // followed by code to update the object, if necessary
 }


}

*************************************************

Laurent
Technical Details
Message-ID: <9a215a$fv4$1@s1.read.news.oleane.net>
Path: arc1-ca.pugleaf.net!supernews.google.com!sn-xit-02!supernews.com!news.gv.tsc.tdk.com!news.iac.net!news-out.cwix.com!newsfeed.cwix.com!news.maxwell.syr.edu!oleane.net!oleane!nnrp.oleane.net!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10a146,fb7796924622c37,start
X-Google-Attributes: gid10a146,public
X-Google-Thread: f74b3,fb7796924622c37,start
X-Google-Attributes: gidf74b3,public
X-Google-Thread: f631b,fb7796924622c37,start
X-Google-Attributes: gidf631b,public
X-Google-ArrivalTime: 2001-03-30 05:23:58 PST
Path: arc1-ca.pugleaf.net!supernews.google.com!sn-xit-02!supernews.com!news.gv.tsc.tdk.com!news.iac.net!news-out.cwix.com!newsfeed.cwix.com!news.maxwell.syr.edu!oleane.net!oleane!nnrp.oleane.net!not-for-mail
From: "Laurent Souriau" <lsouriau@club-internet.fr>
Newsgroups: borland.public.jbuilder.java.language,comp.lang.java.programmer,fr.comp.lang.java
Subject: SERIALIZING an object containing a NON serializable object ?
Date: Fri, 30 Mar 2001 15:21:31 +0200
Organization: Guest of France Telecom Oleane's newsreading service
Lines: 201
Message-ID: <9a215a$fv4$1@s1.read.news.oleane.net>
NNTP-Posting-Host: 194.250.203.22
X-Trace: s1.read.news.oleane.net 985958383 16356 194.250.203.22 (30 Mar 2001 13:19:43 GMT)
X-Complaints-To: abuse@oleane.net
NNTP-Posting-Date: Fri, 30 Mar 2001 13:19:43 +0000 (UTC)
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 5.50.4133.2400
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400