wood burning stoves 2.0*
The moose likes I/O and Streams and the fly likes can we serialize InputStream and OutputStream object? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "can we serialize InputStream and OutputStream object?" Watch "can we serialize InputStream and OutputStream object?" New topic
Author

can we serialize InputStream and OutputStream object?

Kaleeswaran Karuppasamy
Ranch Hand

Joined: Jul 19, 2007
Posts: 154
can we serialize InputStream and OutputStream object.can we set InputStream and OutputStream as return type of RMI or EJB Method.


Judge a man by his questions rather than his answers --Voltaire
SCJP 1.5 97%
Nitesh Kant
Bartender

Joined: Feb 25, 2007
Posts: 1638

Streams and File objects are very particular to the machine they were created on and are of no use out of that machine.
So, it does not make sense to return them from a remote method. This is the reason why these classes do not implement Serializable and hence can not be serialized.


apigee, a better way to API!
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
Well, serialization is not used only for remote methods - it can also be used by an application on a single machine, to save state when the application terminates and is restarted. Thus, it can be useful to save File objects, and File does in fact implement Serializable.

Now serializing streams is a very different matter. The whole point of a stream is that you're taking data and either writing or reading it as a sequence of bytes - thus, the data is already being serialized. That's what serialization is, the process of converting objects to and from a sequence of bytes. If the data is already expressed as a sequence of bytes, there's nothing to do - it's pointless.

Attempting to serialize a stream is also kind of like attempting to send a telephone through your telephone. You use the telephone to send messages, data. You don't use it to send other telephones; that makes no sense. You might want to transmit information like a telephone number, that someone else can then use to initiate their own telephone call. But the other person you tell the number to still needs to use their own telephone and dial the number themselves; you can't send them a phone over the phone so they can use it.


"I'm not back." - Bill Harding, Twister
Nitesh Kant
Bartender

Joined: Feb 25, 2007
Posts: 1638

Jim:
Attempting to serialize a stream is also kind of like attempting to send a telephone through your telephone. You use the telephone to send messages, data. You don't use it to send other telephones; that makes no sense. You might want to transmit information like a telephone number, that someone else can then use to initiate their own telephone call. But the other person you tell the number to still needs to use their own telephone and dial the number themselves; you can't send them a phone over the phone so they can use it.


Awesome analogy Jim. Kudos!!
Kaleeswaran Karuppasamy
Ranch Hand

Joined: Jul 19, 2007
Posts: 154
can we use OutputStream Object as return type of method in a EJB or RMI?
Nitesh Kant
Bartender

Joined: Feb 25, 2007
Posts: 1638

Originally posted by Kalees Waran:
can we use OutputStream Object as return type of method in a EJB or RMI?


No
Kaleeswaran Karuppasamy
Ranch Hand

Joined: Jul 19, 2007
Posts: 154
then,what are the return type we can use in RMI and EJB method call?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42608
    
  65
I think RMI can return just about anything that implements Serializable.

In addition to that, EJBs can't use (and thus return) anything in the java.io package.


Ping & DNS - my free Android networking tools app
Kaleeswaran Karuppasamy
Ranch Hand

Joined: Jul 19, 2007
Posts: 154
what is the reason EJB not supporting method return type as java.io class?
Nitesh Kant
Bartender

Joined: Feb 25, 2007
Posts: 1638

Originally posted by Kalees Waran:
then,what are the return type we can use in RMI and EJB method call?


Any class that implements Serializable.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42608
    
  65
Originally posted by Kalees Waran:
what is the reason EJB not supporting method return type as java.io class?


The EJB specification says so. If a managed bean uses any kind of I/O then that makes it hard for the app server to manage resources, and violates a number of assumptions about what the app server can or can not do with an EJB.
Kaleeswaran Karuppasamy
Ranch Hand

Joined: Jul 19, 2007
Posts: 154
i am confused Jim mentioned earlier InputStream is already implement serialible object .then what is the trouble to use as return type
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42608
    
  65
Jim mentioned earlier InputStream is already implement serialible object .then what is the trouble to use as return type


That's a misunderstanding. InputStream implements the serialization process; it does not implement the Serializable interface, not would it make sense for it to do so.
Kaleeswaran Karuppasamy
Ranch Hand

Joined: Jul 19, 2007
Posts: 154
http://weblogs.java.net/blog/guruwons/archive/2006/11/sending_large_f.html

this link explain different implementation to send large file. could i know this is the right implementation of jms to sending large file? or its violating any EJB specification ..please suggest me...
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
[Kalees]: i am confused Jim mentioned earlier InputStream is already implement serialible object .then what is the trouble to use as return type

[Ulf]: That's a misunderstanding. InputStream implements the serialization process; it does not implement the Serializable interface, not would it make sense for it to do so.

Also, I said that the File class implements Serializable. But InputStream classes do not.
Manuel Loayza
Greenhorn

Joined: Jan 22, 2008
Posts: 7

Hi friends

http://openhms.sourceforge.net/rmiio/

This could resolve this problem

Greetings
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: can we serialize InputStream and OutputStream object?