I want to convert my object to byte array and then next to an object and run a method..The codes are below: -
public class test_serialisation implements Serializable{
-
-
/**
-
*
-
*/
-
private static final long serialVersionUID = 1L;
-
-
-
public static void main(String[] args) {
-
// TODO Auto-generated method stub
-
ObjectOutputStream ob;
-
FileOutputStream f;
-
Object ob1;
-
//DatagramSocket sck=new DatagramSocket();
-
ByteArrayOutputStream buf;
-
byte[] arr1=new byte[256];
-
try {
-
buf=new ByteArrayOutputStream();
-
-
-
ByteArrayOutputStream baos = new ByteArrayOutputStream();
-
ObjectOutputStream oos = new ObjectOutputStream(baos);
-
oos.writeObject(new test_serialisation());
-
oos.flush();
-
oos.close();
-
-
-
byte[] sendBytes = baos.toByteArray();
-
System.out.println("testing bytes array.........");
-
System.out.println(sendBytes.length);
-
-
System.out.println("sendBytes.length : " + sendBytes.length);
-
-
//ds.send(dp);
-
ByteArrayInputStream out=new ByteArrayInputStream(arr1);
-
ObjectInputStream n=new ObjectInputStream(out);
-
test_serialisation bb=(test_serialisation) n.readObject();
-
bb.test();
-
-
FileInputStream in = new FileInputStream("tmp");
-
ObjectInputStream ss = new ObjectInputStream(in);
-
-
-
-
-
-
-
} catch (Exception e) {
-
-
e.printStackTrace();
-
}
-
-
}
-
-
-
public void test(){
-
System.out.println("Serialisation working");
-
}
-
-
}
-
-
-
When I run this code,I get the java.io.StreamC orruptedExcepti on and the stacktrace is:; - java.io.StreamCorruptedException: invalid stream header
-
at java.io.ObjectInputStream.readStreamHeader(Unknown Source)
-
at java.io.ObjectInputStream.<init>(Unknown Source)
-
at test_serialisation.main(test_serialisation.java:55)
-
I would appreciate if anyone could help me out wd this exception ...
Thanks in advance
1 13398 Nepomuk 3,112
Recognized Expert Specialist
Which is the line 55 in your code? Because in the code you posted, line 55 is empty, although the error message states, that your problem is there.
And what error does it through, if you don't catch the exception?
Greetings,
Nepomuk
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Lou |
last post by:
How do you convert a byte array to a string?
|
by: Gator |
last post by:
Hi All,
Basically my situation is this, I have a server implemented in C++,
unmanaged code, using proprietery protocol over TCP/IP to communicate
with the cilent(c++ also).
Now, I am implementing the another client in C#. Server side can not
be
changed :(
So, I am using tcp/ip sockets. In the end I get byte on the client
side, which originally was some C++ class object, converted to byte
array.
|
by: Andrew Inwards |
last post by:
Can anyone tell me how to convert a byte array to a stream.?
Thanks
Andrew
|
by: Dave |
last post by:
Hi, I'm trying to convert a byte array to string
--This works...
System.BitConverter.ToString(bytes)
"EB-55-79-20-18-B2-76-4D-85-0A-93-6B-97-33-31-B8"
--This doesn't, but returns "System.Byte". How do I do this with
System.Convert.ToString()???
|
by: Terry Olsen |
last post by:
Looking for info on how to convert a byte array to a string, and string to
byte array. Thanks.
| |
by: Charles Law |
last post by:
I thought this had come up before, but I now cannot find it.
I have a byte array, such as
Dim a() As Byte = {1, 2, 3, 4}
I want to convert this to an Int32 = 01020304 (hex).
If I use BitConverter, I get 04030201.
|
by: |
last post by:
Hi,
How do I convert a byte to an object?
I am trying to use IADs PutEx and the last parameter required a variant
array.
Thanks,
Alex
|
by: MrVS |
last post by:
Hi,
I have a C++ CLR class method that takes System::Byte *b as parameter argument. I want the CSharp caller pass a byte * to this function.
But in the CSharp prorgram, I only managed to create a byte array (byte).
Can anyone tell me how to convert byte array to byte pointer in CSharp?
Please show me an simple example about how to do it.
Thank you for your help
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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: 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: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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...
| |