refactored read-bytes

to use a protocol to allow writing test cases
also added a check for -1 bytes read in which case throw an EOFException