Data ReadStream::Read( CFIndex length ) const { Data data; Data::Byte * bytes; CFIndex read; if( this->_cfObject == NULL ) { return data; } if( length > 0 ) { bytes = new Data::Byte[ length ]; read = this->Read( bytes, length ); if( read > 0 ) { data.AppendBytes( bytes, read ); } } else { bytes = new Data::Byte[ 4096 ]; while( this->HasBytesAvailable() ) { read = this->Read( bytes, 4096 ); if( read > 0 ) { data.AppendBytes( bytes, read ); } } } delete[] bytes; return data; }