• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

can we serialize InputStream and OutputStream object?

 
Kaleeswaran Karuppusamy
Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can we serialize InputStream and OutputStream object.can we set InputStream and OutputStream as return type of RMI or EJB Method.
 
Nitesh Kant
Bartender
Posts: 1638
IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Nitesh Kant
Bartender
Posts: 1638
IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 Karuppusamy
Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can we use OutputStream Object as return type of method in a EJB or RMI?
 
Nitesh Kant
Bartender
Posts: 1638
IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Kalees Waran:
can we use OutputStream Object as return type of method in a EJB or RMI?


No
 
Kaleeswaran Karuppusamy
Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
then,what are the return type we can use in RMI and EJB method call?
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Kaleeswaran Karuppusamy
Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what is the reason EJB not supporting method return type as java.io class?
 
Nitesh Kant
Bartender
Posts: 1638
IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 Karuppusamy
Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am confused Jim mentioned earlier InputStream is already implement serialible object .then what is the trouble to use as return type
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 Karuppusamy
Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
[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
Posts: 7
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi friends

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

This could resolve this problem

Greetings
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic