File: InputStreamSlowMultibyteRead.md

package info (click to toggle)
error-prone-java 2.18.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 23,204 kB
  • sloc: java: 222,992; xml: 1,319; sh: 25; makefile: 7
file content (14 lines) | stat: -rw-r--r-- 861 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
`java.io.InputStream` defines a single abstract method: `int read()`, which
subclasses implement to return bytes from the logical input stream.

However, in most circumstances, readers from `InputStreams` use higher-level
methods like `read(byte[], int offset, int length)` to read multiple bytes at a
time into a buffer. The default implementation of this method is to repeatedly
call `read()`. However, most InputStream implementations could do much better if
they can read multiple bytes at once (at the very least, avoiding unneeded
`byte` -> `int` -> `byte` casts that are needed when implementing the read()
method over an underlying `byte` source).

The class in question implements `int read()` without also overriding `int
read(byte[], int, int)` and will thus be subject to the costs associated with
the default behavior of the multibyte read method.