akb 4
New Member
can i write multiple object states of a serializable in a single file?
if i can then how can i read back those states?
i have no problem with writing multiple object states in a file.
but i can't read back the all object states what i saved so far.
only after reading back the first state then StreamCorrupted Exception exception thrown.
i know it is due to data inconsistency in the file.
so plz help me.
Regards.
11 2512
can i write multiple object states of a serializable in a single file?
if i can then how can i read back those states?
i have no problem with writing multiple object states in a file.
but i can't read back the all object states what i saved so far.
only after reading back the first state then StreamCorrupted Exception exception thrown.
i know it is due to data inconsistency in the file.
so plz help me.
Regards.
Can we see the codes.
JosAH 11,448
Recognized Expert MVP
can i write multiple object states of a serializable in a single file?
if i can then how can i read back those states?
i have no problem with writing multiple object states in a file.
but i can't read back the all object states what i saved so far.
only after reading back the first state then StreamCorrupted Exception exception thrown.
i know it is due to data inconsistency in the file.
so plz help me.
Regards.
Unless you reset the ObjectOutputStr eam or writeUnshared() every object is
written to such a stream only once. Every following attempt to write the object
only a reference to a previously serialized incarnation is written to the stream.
kind regards,
Jos
actually this Q. is sent by me on behalf of AKB. so i send u the source code.
as per as ro35198x requirements concern ...
my code is something like this .....
//this is my SERIALIZABLE class which is to be serialized.
class s implements Serailizable
{
private int a ,b;
public s(int A,int B){a=A;b=B;}
public void display(){
System.out.prin tln("DMJ: " + a + "\t" + b);
}
}
//this is my main class
class m
{
public static void main(String args[])
{
FileOutputStrea m o = new FileOutputStrea m(file_name,tru e);
//the file opened in append mode
ObjectOutputStr eam out = new ObjectOutputStr eam(o);
out.writeObject (new s(100,200));
out.writeObject (new s(300,400));
FileInputStream i = new FileInputStream (file_name);
ObjectInputStre am in = new ObjectInputStre am(i);
((s)in.readObje ct()).display() ; //this is OK ... it shows the first state i saved.
((s)in.readObje ct()).display() ;
//the second call is throwing StreamCorrupted Exception.
}
}
plz help.
kind regards.
JosAH 11,448
Recognized Expert MVP
An ObjectOutputStr eam writes header information to the wrapped stream when
you open/create it. Your file contains the following information:
HHHOOOOO ... OOO
where HHH represents the header information and OOO ... OOO represents
the data for the serialized object itself. When you reopen your file in append
mode again and open an ObjectOutputStr eam again, the header will also be
written again. After writing another object the file contents look like this:
HHHOOOOO ... OOOHHHOOOOO ... OOO
When you want to read objects from this file you can read the first one but
unexpectedly another header is read when you want to read the second object.
kind regards,
Jos
akb 4
New Member
now the full clearity comes up....
thanx for ur reply...
then what is the solution ... to accomplish this.
Plz help.
Kind regards.
JosAH 11,448
Recognized Expert MVP
now the full clearity comes up....
thanx for ur reply...
then what is the solution ... to accomplish this.
Plz help.
Kind regards.
Open the ObjectOutputStr eam once and write all your objects. At the end
close the stream. You can read all your objects later by opening the file,
wrap it in an ObjectInputStre am and read all the objects.
That way the header will only be written once.
kind regards,
Jos
ok we got the solution ....
lot of thanxxxx .....
@JosAH
What did you mean here ? will you please say in details ?
JosAH 11,448
Recognized Expert MVP @dmjpro
Exactly as I wrote: if you do e.g. something like this: -
BigObject bo= new BigObject();
-
ObjectOutputStream oos= ...;
-
-
oos.write(bo);
-
bo.changeState();
-
oos.write(bo);
-
bo.changeState();
-
oos.write(bo);
-
oos.close();
-
The content of that oos will be:
<header><BigObj ect content><ref><r ef>
Where the <header> part is important to an ObjectInputStre am only, <BigObject content> is the content of your object before the two changeState() calls and the <ref> parts are references to that first BigObject content.
kind regards,
Jos
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: vbvjain |
last post by:
Hi
Thanks for your suggestion, i even tried that but now the error that is
generated is "There was an error generating XML". If i declare the input
parameter of my web service method as object and pass a collection, it
adds a web reference in client project but it gave me same error of
generating XML in that also.
I m specifially using collections because the data it contains is very
complex, actually it is a collection of objects of...
|
by: deepak |
last post by:
i have set multiple selection property in bith listboxes(html control) to
true. i have taken 2 buttons(html control) say Button1,Button2.now i want to
add mutiple selected items to another listbox after clicking button1, and
similray remvoing the mutiple selected ite,s from, another after clicking
button2 ,, how can i do this ,, my script is given belo...
|
by: saravana |
last post by:
I have to display the mutiple xml filename path in treeview control using c#.
net
some thing like this
In treeview control.......
=========
=C:\\a.xml=
|
by: RobH |
last post by:
Hi..
I have a table of Products and StateID. The products with a field for which states they are availble using the codes from the StateID table
tbl-Products
ProductID Description Available
1 "Blue Coffee Table" "1,2,3,5"
2 "Red Coffee Table" "2,3,4"
|
by: poucedeleon |
last post by:
I am building a database for logging in Officers into our building. It uses a continuous form. I have added a command button labeled "Multiple Bookings. OnClick it opens a form that has two comboboxes (Select Agency: fills in "AgencyName" on Main Form.) (Officer Name: fills "Officers Name" on MainForm.) and text field (Amount: states how many records to create) Each day we have groups of bookings arrive (Chain, Co-op, Comittments & DOC) These...
| |
by: shanmugamit |
last post by:
hi,
var len=document.form.check.length
flag=false;
for(i=0;i<len;i++)
{
if(document.form.check.checked==true)
{
flag=true;
break;
|
by: shanmugamit |
last post by:
hi,
i using mutiple check box but i didn't get all value...
as
$res=mysql_query("select * from cie where des='Resource Pipeline Associate' order by name");
$j=0;
$norow=mysql_num_rows($res);
|
by: RyanN |
last post by:
Hello,
I'm trying to teach myself OOP to do a data project involving
hierarchical data structures.
I've come up with an analogy for testing involving objects for
continents, countries, and states where each object contains some
attributes one of which is a list of objects. E.g. a country will
contain an attribute population and another countries which is a list
of country objects. Anyways, here is what I came up with at first:
|
by: dewraj |
last post by:
Hi
I am using windows applicaiton(.net) as front end,
and I want to get mutiple tables in Dataset by executing a single stored procedure i.e.
SP would return mutiple tables (record sets) with the user specified name.
can anybody guide me no this?
thanks.
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |