Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

BufferedInputStream: read() vs read(byte[])  RSS feed

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First of all, hello everybody!
My question also applies to output streams and writes.
Granted I have something like that

is there any advantage in creating a byte buffer and reading a file with read(byte[]) method, as opposed to reading it byte by byte?
My guess is no, since we are simply transferring bytes from one point in memory to another and the compiler can optimize it.

Also, did i put anything redundant into that code?:

Cheers
 
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm no expert on this, so wait for confirmation from one before you take this as gospel, but I thought that the ability to read in data as chunks rather than byte by byte was the whole reason for the existence of the BufferedInputStream class. So if I understand things correctly, you are better off using the read(byte[] b, int off, int len) overload.
 
Sheriff
Posts: 23703
50
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It wouldn't be difficult to put together a quick benchmark to see what difference it makes in reading a large file, let's say. Guessing shouldn't be necessary. Or done.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!