aspose 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
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: 433
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: 19785
    
  20

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.