• Post Reply Bookmark Topic Watch Topic
  • New Topic

ByteArrayInputStream  RSS feed

 
Ranch Hand
Posts: 285
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What are the effects if I have a object of type ByteArrayInputStream, but never call the close method?


I had a class that implemented Runnable, that in its run methods call another class's method which is non-static. It has a local variable that has an object of type ByteArrayInputStream which is really just the input stream of an HttpURLConnection object, after some manipulations. The manipulations are:

inputStream.read(buffer,bytesCopied,contentLength-bytesCopied);

That inputStream is closed and a new one :
ByteArrayInputStream is = new ByteArrayInputStream(buffer); is created. This one is never closed...

I do plan on closing it now that I see that I did not, but in a thread or non thread enviornment, would this cause any potential problems?
 
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would guess that close() is a no-op on ByteArrayInputStream. Let's go look at the JDK source... Yep.



So forgettng to call it has no practical effect.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!