• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

IO Streams as parameters.

 
Qunfeng Wang
Ranch Hand
Posts: 434
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Rajkamal Pillai
Ranch Hand
Posts: 445
1
Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20611
63
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic