File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes I/O and Streams and the fly likes IO Streams as parameters. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "IO Streams as parameters." Watch "IO Streams as parameters." New topic
Author

IO Streams as parameters.

Qunfeng Wang
Ranch Hand

Joined: Jan 28, 2005
Posts: 425
I wonder if it's a bad practice to use IO Streams as parameters, and how to walk around this.

Because it will raise a problem: where to close the stream? after the invoking or when the invoked method finished?


To be or not to be. It's a question.
Rajkamal Pillai
Ranch Hand

Joined: Mar 02, 2005
Posts: 443
    
    1

Hi,

I am not able to think of any performance related constraints regarding passing streams as parameters. IMHO, it is the responsibility of the block of code taht opened the resource connection/stream to take care of closing it, handling all exceptions thrown in the appropriate fashion during any operations performed on the same.

Thanks,
Raj.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19538
    
  16

Raj Kamal wrote:IMHO, it is the responsibility of the block of code taht opened the resource connection/stream to take care of closing it

I couldn't agree more. The called method that takes an InputStream doesn't know if it is still needed afterwards; perhaps it has a mark that allows the calling method to go back in the InputStream and do some more reading. If the called method closes it then the calling method will have a problem.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: IO Streams as parameters.
 
Similar Threads
IO Streams to use
Question about ObjectOutputStream close() method
confused with java.io.
Basic: How IO reads or write ByteStream and CharacterStream
[SOLVED] Can I pass sockets to different threads?