Java Streams  «Prev 

Creating Efficient input using Streams

How do you create Efficient Input using Streams in Java?

Read() variants

Here are two variants on the read() method:

Method Signature
public int read(byte b[]) throws IOException
public int read(byte b[], int offset, int length)
throws IOException

  1. The first variant tries to read enough data to fill the array b.
  2. The second variant tries to read length bytes of data into the array b starting at position offset.
Neither of these methods is guaranteed to read as many bytes as they want.
Both methods return the number of bytes actually read, or -1 on end-of-stream.
Question: How do you create Efficient Input using Streams in Java?