Suppose I have an OutputStream
(and not an ObjectOutputStream
). Is is possible to send a serialized object using the write method? Thanks!
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
You must have to use ObjectOutputStream class and its methods to
*serialize*
objects. In factObjectOutputStream
is a sub-class ofjava.io.OutputStream
(It is an abstract super class of byte-oriented streams). Take a look at an article on Java Serialization API.EDIT: You can use XMLEncoder
You could use ObjectOutputStream to 'capture' the objects data in a byte Array and send this to the OutputStream.
Another non generic option would be to serialize the object in a string representation e.g. CSV
Here is what you do to serialize the object:
If you want to control the
byte[]
output:This is trivial: you can simply wrap your original
OutputStream
in a newObjectOutputStream
, and then use the specialized methods ofObjectOutputStream
:Internally,
ObjectOutputStream
will call the underlyingOutputStream
'swrite()
method.