Objective: Implement the functionality for the BitReader class and ensure it can read various data types from a byte array.
Functionality Requirements:
Implement the constructor BitReader(byte[] data) that initializes the reader with the provided byte array.
Implement the method byte readByte() that reads a single byte from the byte array.
Implement the method boolean readBoolean() that reads a single boolean value from the byte array. This will interpret 0 as false and any non-zero value as true.
Implement the method int readInt() that reads a 4-byte integer from the byte array.
Implement the method int readInt(int nbits) that reads an integer using a specified number of bits, ensuring the appropriate handling of overflow or bit shifting.
Implement the method char readChar() which reads two bytes from the byte array and combines them into a character, as shown in the provided implementation.
Input/Output Requirements:
The constructor BitReader(byte[] data) must accept a non-null byte array.
The readByte() method should return a single byte from the byte array or throw an exception if the end of the array is reached.
The readBoolean() method should return a boolean value based on the current position in the byte array.
The readInt() method should return a 4-byte integer starting from the current position in the byte array.
The readInt(int nbits) method should return an integer based on the specified number of bits.
The readChar() method should return a character constructed from the next two bytes of the byte array.
Implementation Location:
Place the implementation of the BitReader class inside the /app/ directory.
Additional Notes:
Ensure to include error handling for cases where the byte array does not have enough remaining bytes to read the requested data type.
Document the assumptions and any edge cases considered during implementation.