• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

IO Streams as parameters.

 
Ranch Hand
Posts: 434
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 479
1
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic