You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by StephanEwen <gi...@git.apache.org> on 2014/07/07 14:47:11 UTC

[GitHub] incubator-flink pull request: [FLINK-994] Replaced DataInput and D...

Github user StephanEwen commented on a diff in the pull request:

    https://github.com/apache/incubator-flink/pull/53#discussion_r14593536
  
    --- Diff: stratosphere-runtime/src/main/java/eu/stratosphere/nephele/services/memorymanager/AbstractPagedInputView.java ---
    @@ -183,44 +183,69 @@ protected void clear() {
     	// --------------------------------------------------------------------------------------------
     	//                               Data Input Specific methods
     	// --------------------------------------------------------------------------------------------
    -	
    +
     	@Override
    -	public void readFully(byte[] b) throws IOException {
    -		readFully(b, 0, b.length);
    +	public int read(byte[] b) throws IOException{
    +		return read(b,0,b.length);
     	}
     
     	@Override
    -	public void readFully(byte[] b, int off, int len) throws IOException {
    +	public int read(byte[] b, int off, int len) throws IOException{
     		if (off < 0 || len < 0 || off + len > b.length) {
     			throw new IndexOutOfBoundsException();
     		}
    -		
    +
     		int remaining = this.limitInSegment - this.positionInSegment;
     		if (remaining >= len) {
     			this.currentSegment.get(this.positionInSegment, b, off, len);
     			this.positionInSegment += len;
    +			return len;
     		}
     		else {
     			if (remaining == 0) {
    -				advance();
    +				try {
    +					advance();
    +				}catch(EOFException eof){
    +					return -1;
    +				}
     				remaining = this.limitInSegment - this.positionInSegment;
     			}
    -			
    +
    +			int bytesRead = 0;
     			while (true) {
    -				int toRead = Math.min(remaining, len);
    +				int toRead = Math.min(remaining, len-bytesRead);
     				this.currentSegment.get(this.positionInSegment, b, off, toRead);
     				off += toRead;
    -				len -= toRead;
    -				
    -				if (len > 0) {
    -					advance();
    -					remaining = this.limitInSegment - this.positionInSegment;	
    +				bytesRead += toRead;
    +
    +				if (len > bytesRead) {
    +					try {
    +						advance();
    +					}catch(EOFException eof){
    +						return bytesRead;
    +					}
    +					remaining = this.limitInSegment - this.positionInSegment;
     				}
     				else {
     					this.positionInSegment += toRead;
     					break;
     				}
     			}
    +			return len;
    +		}
    +	}
    +	
    +	@Override
    +	public void readFully(byte[] b) throws IOException {
    +		readFully(b, 0, b.length);
    +	}
    +
    +	@Override
    +	public void readFully(byte[] b, int off, int len) throws IOException {
    +		int bytesRead = read(b,off,len);
    +
    +		if(bytesRead == -1){
    --- End diff --
    
    Should this be `if (bytesRead < len)`


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---