Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: wordsmithing

The abstract InputStream.read() and Reader.read() methods are used to read a byte or character from a stream, respectively. The  InputStream.read() method reads a single byte from an input source and returns its value as an int in the range 0 to 255 (0x00-0xff). The Reader.read() method reads a single character, and returns its value as an int in the range 0 to 65,535 (0x000x0000-0xffff). Both methods return the 32-bit value -1 (0xffffffff) to indicate that the end of the stream has been reached and no data is available. The larger int size is returned used by both methods to differentiate between the end of stream indicator and a the maximum byte (0xff) or character (0xffff) value. The end of stream indicator is an example of an in-band error indicator. In-band error indicators are problematic to work with, and the creation of new in-band-error indicators is discouraged.

...

This rule applies to any method that returns the value -1 to indicate the end of the a stream including . This includes any InputStream or Reader subclass that provides an implementation of the read() method. This rule is a specific instance of rule NUM12-J. Ensure conversions of numeric types to narrower types do not result in lost or misinterpreted data.

...