Problem in Serializing Object[]??

Hi,
I have a JTable and I am tring to write the TableHeader and TableData which are in the form of Object[] and Object[][].
For writing it into file I am using Following method
public int SaveObject(File file, int[] selectedCases, MainFrame ownedFrom, int prevInd) {
  try {
   os = new FileOutputStream(file);
   s = new ObjectOutputStream(os);
   JTablePanel panel = ownedFrom.getMyTabbedPane ().getMyMainPanel(prevInd).getTopRightComponent().getResultPanel();
   JTableModelExtended model=(JTableModelExtended)(((JTableScrollPane) panel.getTablePanels().get(0)).getHeaderTable().getModel());
         System.out.println ("Writing to File");
   s.writeObject("Writing Object To File");
   s.writeObject((Object[])model.getColumnNames());
   s.writeObject((Object[][])model.getData());
//   s.writeObject (ownedFrom.getMyTabbedPane().getMyMainPanel(prevInd).getHostSplitPane());
//   s.writeObject(ownedFrom.getMyTabbedPane().getMyMainPanel(prevInd).getRightSplitPane());
//   s.writeObject(ownedFrom.getMyTabbedPane().getMyMainPanel(prevInd).getLeftSplitPane());
  } catch (FileNotFoundException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
   return 0;
  }catch (Exception e) {
   // TODO Auto-generated catch block
   e.printStackTrace ();
   return 0;
  }finally{
   try {
    //s.flush();
    //s.close();
    os.close();
   } catch (Exception e) {
    return 0;
  return 1;
}Now for retriving I am using the following snippnet of code
String str = null;
   Object[] col = null;
   Object[][] data = null;
  int ret_obj= save.SaveObject(fileObj,selectedCase,ownedFrom,prevInd);
  System.out.println("Writing to file"+ret_obj);
  File fileObj2 = new File(fileName+".Obj");
  FileInputStream f = null;
  ObjectInput s = null;
  try {
   f = new FileInputStream(fileObj2);
   s = new ObjectInputStream(f);
  } catch ( Exception e ) {
   System.out.println("Unable to open stream as an object stream");
  try {
   str=(String)s.readObject();// This is coming perfectly
   col = (Object[])s.readObject();// This is coming as null
   data = (Object[][])s.readObject();// This is coming as null
  } catch (ClassNotFoundException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  } catch (IOException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  try {
   f.close();
  } catch (Exception e) {
   // TODO: handle exception
  }I am new to seralizing technique.Please help me .Are I doing anything wrong
Thnx
Neel

Where is your read object method ??He's calling it. Look more closely.
If you're saying he needs to implement it, then you're wrong.
Why did you handle the exception which makes your
code messy ? Throw it away.Bad idea. It should be either handled or thrown, and it should also be logged.
Do this something like that;No, don't.

Similar Messages

  • Problem with serialized objects and JWS

    My JWS launched application fails when loading a serialized object that has been instatiated from a class not contained in the signed jar-file. Does anyone know why this happens and if there is some workaround for the problem?

    Where is the class contained then?

  • Applet/Servlet/serialized objects/HTTPS/Intranet problem

    We've got a Webapplication with[b] applets on the client and servlets on the server side.The Applet send serialized Objects over HTTPS (SSL) to the servlet. The servlet does some business logic and send the answer the same way back.
    In all our tests and in the most cases the application works without any problems.
    But in some Intranet environments we get occasionally (not definitely reproducable) the following error:
    <Oct 1, 2004 8:26:00 AM>  [AnmeldenService] {Service-readThreadAks-AnmeldenServiceThread}
    java.io.EOFException: Expecting code
    at java.io.ObjectInputStream.peekCode(Unknown Source)
    at java.io.ObjectInputStream.readObject(Unknown Source)
    at java.io.ObjectInputStream.readObject(Unknown Source)
    at com.dsh.egb.aks.betrieb.rclt.service.ServiceThread$2.run(ServiceThread.java:222)
    at java.lang.Thread.run(Unknown Source)Has anybody an idea how to further analyse this problem?
    Thanks,
    Mark
    We use JRE/JDK 1.3.1_10.

    Here some more Information about our environment:
    Server: Apache 1.3.26 / Openssl 0.9.6d /WinNT 4.0 /HTTP Redirect to Tomcat 4.0.1/ JDK1.3.1_10/ WinNT 4.0
    Client: Plugin 1.3.1_10/Internet Explorer 6.0 (SSL)/Win NT 4.0

  • FileUpload problem: InputStream does not contain a serialized object

    Hi All,
    I'm using the FileUpload component in a JSPDynPage and the htmlb component seems to work fine but I cannot read the file (InputStream). I get the following error(IOException): "InputStream does not contain a serialized object".
    Please let me know what is wrong with my code. This is a part of the code I used:
    public FileInputStream sourceFileInput;
    public ObjectInputStream input;
    FileUpload fu;
    fu = (FileUpload) this.getComponentByName("myFileUpload");
    IFileParam fileParam = ((FileUpload) getComponentByName("myFileUpload")).getFile();
    File f       = fileParam.getFile();
    file         = fu.getFile().getFile();
    absolutepath = fu.getFile().getFile().getAbsolutePath();
    this.sourceFileInput = new FileInputStream(file);
    input = new ObjectInputStream(sourceFileInput);
    The last line of code seems to generate te error.

    Hi,
    I have found the answers, thank you both.
    (I included the examle code. Perhaps of some use to someone.)
    FileUpload fu;
    fu = null;
    fu = (FileUpload) this.getComponentByName("myFileUpload");
    //       this is the temporary file
    if (fu != null) {
         IFileParam fileParam = ((FileUpload) getComponentByName("myFileUpload")).getFile();
         if (fileParam != null) {
              // get info about this file and create a FileInputStream
              File f = fileParam.getFile();
              if (f != null) {
                   try {
                        fis = new FileInputStream(f);
                   // process exceptions opening files
                   catch (FileNotFoundException ex) {
                        myBean.setMessage(
                             "1" + f + ex.getLocalizedMessage());
                   isr = new InputStreamReader(fis);
                   br = new BufferedReader(isr);
    String textLine = "";
    do {
         try {
              textLine = (String) br.readLine();
         } catch (IOException e) {
              myBean.setMessage(
                   "1" + e.getLocalizedMessage());
         // Jco append table & put data into the record
         // (I_FILE is the table with txt data that is sent to the RFC)
         I_FILE.appendRow();     
         I_FILE.setValue(textLine, "REC");                              
    } while (textLine != null);

  • Understanding problem: serialized objects

    We had a discussion here and now I wanted to ask the java pros about a small paragraph in the API:
    From time to time I'm reading this in the API which I don't completely understand. Does it mean that if I will use this class my programs won't run with further java virtual machines (after 1.5??) or does it just mean that I won't be able to compile the code with the latest java interpreter? ...or won't be able to mix it up with classes written for newer java versions/classes - I have some probs to understand what is meant by "serialized"?
    Warning:  Serialized objects of this class will not be compatible with future Swing releases. The current serialization support is appropriate for short term storage or RMI between applications running the same version of Swing. As of 1.4, support for long term storage of all JavaBeansTM  has been added to the java.beans package. Please see XMLEncoder.

    Here is my understanding of that paragraph (I could be wrong):
    Let's say you serialize an object of one of those classes and save it to a file today. If you tomorrow or next week want to recreate that object by deserializing it from the same file you will be fine. But if you two years from now, using a newer version of Java, try to deserialize the object from the file you saved today, there are no guarantees it will succeed.

  • StreamCorruptedException: does not contain a serialized object?

    Can someone tell me why am I getting this exception:
    C:\javapr>java FetchObject
    Couldn't retrieve binary data: java.io.StreamCorruptedException: InputStream
    does not contain a serialized object
    java.io.StreamCorruptedException: InputStream does
    not contain a serialized object
    at java.io.ObjectInputStream.readStreamHeader
    (ObjectInputStream.java:849)
    at java.io.ObjectInputStream.<init>
    (ObjectInputStream.java:168)
    at FetchObject.main(FetchObject.java:23)
    import java.sql.*;
    import java.util.*;
    import java.io.*;
    class FetchObject implements Serializable {
        public static void main (String[] args) {
            try {
                String driver = "oracle.jdbc.driver.OracleDriver";
                Class.forName(driver);
                String url = "jdbc:oracle:thin:@mymachine:1521:homedeva";
                Connection conn = DriverManager.getConnection(url,"cnn","cnn");
                FetchObject i = new FetchObject();
                    // Select related
                    try
                         byte[] recdBlob = i.selectBlob( 1 , conn ); 
                         ByteArrayInputStream bytes = new ByteArrayInputStream(recdBlob);
                         ObjectInputStream deserialize = new ObjectInputStream( bytes );
              Employee x = (Employee)deserialize.readObject();
                    catch( Exception ex )
                  System.err.println("Couldn't retrieve binary data: " + ex);
                  ex.printStackTrace();
         catch( Exception ex )
              ex.printStackTrace();
        public byte[] selectBlob( int id, Connection conn )
         byte[] returndata = null;
         try
              Statement stmt = conn.createStatement();
              String sql = "SELECT id, rowdata FROM blobs WHERE id = " + id;
              ResultSet rs = stmt.executeQuery(sql);
              if ( rs.next() )
                           try
                               ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
                               BufferedInputStream bis = new BufferedInputStream( rs.getBinaryStream("rowdata") );
                             byte[] bindata = new byte[4096];
                               int bytesread = 0;
                               if ( !rs.wasNull() )
                                       if ( (bytesread = bis.read(bindata,0,bindata.length)) != -1 )
                                          baos.write(bindata,0,bytesread);
                                returndata = baos.toByteArray();
                             baos.flush();
                                bis.close();
                       catch ( Exception ex )
                            System.err.println("Problem retrieving binary data: " + ex);
                        rs.close();
                         stmt.close();  
               catch ( Exception ex )
                    System.err.println("Couldn't retrieve binary data: " + ex);
            return returndata;
    import java.io.*;
    class Employee implements Serializable
         private String lastName;
         private String firstName;
         public Employee(String lastName, String firstName)
              this.lastName = lastName; 
              this.firstName = firstName;
    }

    To clarify I have stored an Employee Object as a Blob in the Oracle database and am attempting to retreive the
    Employee Object from this Blob.
    Thanks

  • Creating a converter for old serialized objects

    Hi,
    I have an application, which writes class objects to file, and then reads the class objects from file when the application is started up.
    Now the problem is, that if i create/modify/etc fields in the class, then all my data is lost (i.e., i cant read the data in when the application starts)....
    Now the docs state that a field can be added, and an old serialized object will still be recoverable...well for some reason this only works when it wants....i have tried several times, and its not a guarenteed thing....
    So i was wondering, is there any way to create an application, which can grab an old serialized version of an object (i.e. class), have a copy of the old class, and the new class, and somehow cast the old to the new...or something of that sort?
    thanks a lot!

    This might be of some help:
    http://www.onjava.com/pub/a/onjava/excerpt/JavaRMI_10/?page=5

  • OID and binding java serialized object

    Hi there,
    How are you doing? I am trying to bind a serialized java object to a name in Oracle Internet Diectory (oid) using JNDI.
    it gives me an errror.
    "OperationNotSupported LDAPA error 53: Unwilling to perform:
    I have directory manager 2.1.1 and JNDI 1.2.1
    I arrpeciate any clue and/or help
    Thanks
    null

    Hello:
    Although OID supports calls from JNDI, the JNDI schema for storing JAVA serialized objects is not yet a standard part of the OID schema. This is easy to remedy. Go to javasoft.sun.com and download the JNDI schema for java serialized objects and load the attributes and objectclasses into OID from the ldif files provided at this web site. . Make sure the attributes are loaded before the objectclasses.
    Once this schema is loaded this problem should go away
    Use the ldapmodify command line tool to add the schema items from the ldif file.
    Let me know if you need further assistance setting this up. A future version of OID will contain these schema items standard.
    Thanks,
    Jay
    null

  • A General serialized object

    Hi!
    I'm trying to create some server software that will allow any number of applets to connect to the server and communicate with each other. Presumably, only applets of the same type would talk together, though applets could send general string messages. I've created a general serialized object, Packet, which all applets would send to the server, and which the server would then pass on to the destination applet(s).
    The problem is that Packet has a field "data" of type Object. When data is something the server knows about, such as a String or a Vector, it does ok. But if the code for the applets creates a new class, say AppletPacket (which is serializable), and sets somePacket.data to an object of type AppletPacket, the server throws errors when it is reading the somePacket from its objectinputstream, saying it can't typecast something of type AppletPacket. But I'm not typecasting anywhere! The server doesn't have to know anything about what data represents, it just needs to send it on, and presumably the destination applets will know what to do with it.
    Can anyone suggest a work around, or tell me what I have to do so that applets can send a general Object that may represent a class the server doesn't know about and not have the server throw an error?
    Thanx
    Jim D.

    Just to clairify: The server doesn't have to do anything with the content of "data" apart from holding on to it, and pass it to another applet?
    If that's the case substitute the Object in the "data" field for an array of bytes obtained by having the applet run the "Object" through ObjectOutputStream.
    What's happening is that the server is deserializing the Packet when it arrives in the JVM of the server, when it comes across the "data" field it looks to see what class the instance really is, and fails as you dscribe if it doesn't have the class definition.

  • Serializing objects with the NIO API

    I try to use the new IO API to implement a non-blocking multi-threaded server that communicates with client applications by exchanging serialized objects. I started from the code in the JavaWorld article at http://www.javaworld.com/javaworld/jw-09-2001/jw-0907-merlin.html .
    With the new features of J2SDK 1.4.0, you don't have to create a separate thread per connected client. That is a big improvement.
    But when I read an object with ObjectInputStream, I get a java.nio.channels.IllegalBlockingModeException.
    Has anybody successfully implemented such a server since the release of the new io API?
    Thanks.
    Jean-Robert

    The ObjectStream code is basically incompatible with non blockin I/O since you must block on the stream until a whole Object is available. You could roll something like this yourself, by reading bytes until there are enough available to build the next object and then getting that Object from the buffer and shipping it to your client thread. All of this is far more trouble than just using the Stream oriented I/O.
    NIO and mutilple threads are a nightmare, the whole idea of non-blocking I/O is to avoid needing multiple threads. If you do use multiple threads you will need queues between them. See the Taming the NIO Circus topic for lots of discussion of NIO and its problems. The system seems more stable in JDK 1.5, but most people haven't even started using 1.4 for production yet.
    Personally I avoid ObjectStreams. They are only useful between Java applications, if I want that I just use RMI and let Java do ALL the hard work. When I write a Socket based app, its probably because the other end is a mainframe of a C program. For that reason I send data as bytes, packaged up in packets, and encode as XML or ASN.1 so the other end can interpret it.

  • Saving and loading serialized objects (StreamCorruptedException)

    Hello,
    I am relatively new to Serialization (coming to that, a bit new to Java too) and I am having a problem with the following:
    I am saving a number of serialized objects (all of the same class) in a file using the following way (the method is called multiple times to save a list of TeamMember objects):
    Note: TeamMember is a custom class.
    public void addTeamMember(TeamMember p) {
                outputStream = new ObjectOutputStream( new FileOutputStream( "team.dat", true ) );
                outputStream.writeObject( p );
                outputStream.flush();
                outputStream.close();
                outputStream = null;
    }Then I'm trying to retrieve the objects from the file and display them. The method used is the following (it will loop through the file until found or it throws an EOFException. Is using the EOFException good practice to search through the entire file?):
    public TeamMember getTeamMember(String id) {
            TeamMember currentMember = null;
            try {
                boolean found = false;           
                inputStream = new ObjectInputStream( new FileInputStream( "team.dat" ) );
                while ( !found ) {
                    currentMember = (TeamMember)inputStream.readObject();
                    if ( currentMember.getId().equals( id ) )
                        found = true;
                } // end while
                closeInputFile();
                return currentMember;
            } // end try
            catch ( EOFException e ) { // end of file reached
                closeInputFile();           
                return null;
            } // end catch
            catch ( IOException e ) {
                closeInputFile();
                System.err.println( e.getMessage() );
                return null;
            } // end catch
        }Now as a test, I am adding 3 members with IDs 1, 2 and 3 respectively. Then I am calling getTeamMember three times with the different IDs. With ID "1", it works fine. When I give it ID 2, it gives an IOException with message "StreamCorruptedException: invalid type code: AC".
    While tracing the program, I've seen that it always gives me that error when reading past the first object saved in the file.
    Am I saving the objects in a wrong way, or reading them is done incorrectly?
    Any help is much appreciated.
    I hope I was clear enough, and that I posted in the correct forum.
    Thanks in advance.
    Andrew.

    If that is so, might you hint me for a work around?
    I want to append objects in a single file, then be able to find and read an object from the file.
    Thanks again.
    Andrew

  • What is the Error (de-)serializing object

    Hi all
    I have 2 EJB's one Stateful(Bean1) and Statless (Bean2). Bean1 lookup on Bean2 and get the remote object of Bean2 (Bean2Remote) and but it in a class that implements java.io.Serializable but when we return that class that holds the Bean2 remote the server throws
    com.evermind.server.rmi.OrionRemoteException: Error (de-)serializing object: NamingException: Bean2Remote not found
    Where the serializable class has the reomte and home interfaces of Bean2 with it
    Can any one help in that thanks in advance

    Having the same problem as many others here. I keep getting error message "0xFFFE7958". I have tried about 25 times over several days with 2 different computers using both tiger and panther and I still cant get the file to download. The episode that is giving me trouble is "Orientation" in second season of Lost. I have noticed that other peeps have had trouble with the same file. I don't think it's me!! I won't be downloading any itunes content until this gets fixed.

  • Opening files with serialized objects even if class definition has changed.

    Dear all,
    We are deploying an application wich saves serialized objects. But when changing something in the code and especially in the serialized classes we are not able to open files which have been saved with the old 'outfit' of the class.
    I think, that this is probably a common problem and therefore I am interested whether there exists also a common or practical solution.
    What is the direction I have to look in? XML, Serializable or is it something else?
    Thanks for a short answer,
    Axel

    If you add, remove or change a classes variables, then it will be serialized differently.
    Any fields which you do not need to be serialized, may be marked as transient, so you can add and remove them at will.
    In the longer term, you can override the readObject() / writeObject() methods and explicitely load/save what fields you want. This will also allow you to set intelligent defaults, if for example, you added a new field, but your old serialised classes do not have this field. You can also precede all serialised data with version numbers... might help a bit.
    So code ( psuedocode ) might look like this...
    private void readObject(java.io.ObjectInputStream in)
         throws IOException, ClassNotFoundException;
        int ver = in.readInt();
         classfield1 = in.readLong();
        if ( ver >= 2 )
            classfield2 = in.readLong();
        if ( ver >= 3 )
             classfield3 = in.readLong();
    }regards,
    Owen

  • KVInputFormat corrupting serialized objects

    Hello,
    I am using Oracle NoSQL database for some research project and I have hit an issue I am unsure how to solve. When using the KVInputFormat to pass data from the db into Hadoop the infrastructural corrupts my byte array. As I understand the problem boils down to the infrastructure uses the toString function as per documentation. Unfortunately I am storing serialized object in the db which can contain negative numbers. A String in essence distills down to a char array which only accepts values [0 - 65535] hence all negative number are not handled. Below is a byte array I have retried from the NoSQL database directly and through KVInputFormat
    Original -84 -19 0 5 117 114 0 2 91 74 120 32 4 -75 18 -79 117 -109 2 0 0 120 112
    KVInputFormat: -17 -65 -67 -17 -65 -67 0 5 117 114 0 2 91 74 120 32 4 -17 -65 -67 18 -17 -65 -67 117 -17 -65 -67 2 0 0 120 112
    Is there any solution for this issue (other than writing my own KVInputFormat), or am I just doing something really stupid (its a distinct possibility it has happened in the past).
    Greatly appreciate any assistance
    Alex

    http://java.sun.com/docs/books/tutorial/essential/io/serialization.html
    http://www.churchillobjects.com/c/11009.html
    http://www.acm.org/crossroads/xrds4-2/serial.html

  • Serializing objects

    I have two questions:
    1. I am writing a serialized object(SecurityConstraintList) to a socket, everything should be working fine, but I have one problem: the object I am writing has two instance variables that are arrays of SecurityConstraint objects. SecurityConstraint is actually an interface, which is implemented for different constraints.
    So I have:
    SecurityConstraint[] con1 = {a, b, c}
    SecurityConstraint[] con2 = {x, y, z}
    SecurityConstraintList list = new SecurityConstraintList(con1,con2);
    It seems that I can't write the list to the socket unless con1 and con2 are Serializable; but how can I express that the SecurityConstraint interface is Serializable?? I tried to make all the implementing classes Serializable but that doesn't seem to work?
    2. When I want to write serialized objects to a file, with the file being c:\\myProject\file.txt , how can I call the file?
    File file = new File("c:\\myProject\file.txt") doesn't work.
    Thankx

    Who or what is telling you that "system doesn't find the file"?
    "File myFile = new File("c:\\myProject\\file.txt");" doesn't create any physical file. If you call myFile.exists() the result will be "false". (If it hadn't been there before)
    Use "myFile.createNewFile();" and it wil be created.
    If you are using "FileOutputStream fos = new FileOutputStream(myFile);" this should create a file for you. (If it hadn't been there before).
    In this case you get a FileNotFoundException is you dont have the permission to create or open this file.
    So what really happens? I don't know your code.
    By the way: Use slash "/" instead of back slash "\" (The unix style).
    Then there is no need for doubling it. "/" instead of "\\" "//" instead of "\\\\". Java will translate it for you on win systems.

Maybe you are looking for

  • How can I find where a specific font is used in a Pages document

    I have a Pages document that always shows a font missing error when opened. Is there any way to find where that font is supposedly used? Alternatively, if I install the font, the message doesn't appear - I assume that means that the font was found. I

  • Can't print from Windows laptop to HP printer on extreme base station

    I have an IMAC Power PC as a Home computer. I use a an airport extreme as my wireless router. I have an HP Deskjet1220 C connected via USB to the Base station. I can print from the IMAC but can't from my windows based laptop. I have downloaded bonjou

  • How do I burn an iMovie to a CD without iDVD or Final Cut Pro?

    iMovie Problems I have iMovie for my iPad.  Recently, I made a three minute or so long video, but when I attempt to copy it to iTunes, it does not show up in Home Sharing.  This is really frustrating me because everyone is saying I need iDVD or Final

  • Can we convert standard video files in to flv file run time ?

    hi all, We have a one project of Flash media server. In this project our client requiring function like whatever standard video file he upload, our flash media server should be play it. to achive this requirment we need to convet that video file in t

  • Displaying Images in EBS

    Hi, Does anybody know if it is possible to use the URL link against an invoice to display an image via UNC path (Oracle 11i)? I know it's possible to do this using a URL link through to a browser application but wondering if it's possible to just use