I’m trying to read the header of an InputStream file. Every header info contains information. However, I have trouble to understand the process of reading the header.
For example, I have:
InputStream sourceFile = //.... stuff.
sourceFile.read() | (sourceFile.read() << 8) | (sourceFile.read() << 16)
| (sourceFile.read() << 24)
from an example code.
Why don’t I just use sourceFile.read() once? What does the single | means and what does << number in this particular context mean?
Thanks for any clarification!
read()returnsint, but it reads one byte from the file, so the idea is to get the first 4 bytes and convert them to a 32-bit int (while changing their endianness).The operators you refer to are binary and bitwise operators. please refer here for more information.