buffer.length on success, negative on error, otherwise, the number of bytes read before EOF
See Implementation