@Override
	public void received(ByteBuffer buffer) {
		if (ended) {
			throw new IllegalStateException();
		}
		
		if ((countRead + buffer.remaining()) > contentLength) {
			ByteBuffer b = buffer.duplicate();
			int l = (int) (contentLength - countRead);
			b.limit(b.position() + l);
			buffer.position(buffer.position() + l);
			buffer = b;
		}
		
		countRead += buffer.remaining();
		if (buffer.hasRemaining()) {
			wrappee.received(buffer);
		}
		if (countRead == contentLength) {
			ended = true;
			wrappee.ended();
		}
	}
@Override
	public void received(ByteBuffer buffer) {
		if (ended) {
			throw new IllegalStateException();
		}
		
		if ((countRead + buffer.remaining()) > contentLength) {
			ByteBuffer b = buffer.duplicate();
			int l = (int) (contentLength - countRead);
			b.limit(b.position() + l);
			buffer.position(buffer.position() + l);
			buffer = b;
		}
		
		countRead += buffer.remaining();
		if (buffer.hasRemaining()) {
			wrappee.received(buffer);
		}
		if (countRead == contentLength) {
			ended = true;
			wrappee.ended();
		}
	}
@ Override public void received ( ByteBuffer buffer ) { if ( ended ) { throw new IllegalStateException ( ) ; } if ( ( countRead + buffer . remaining ( ) ) > contentLength ) { ByteBuffer b = buffer . duplicate ( ) ; int l = ( int ) ( contentLength - countRead ) ; b . limit ( b . position ( ) + l ) ; buffer . position ( buffer . position ( ) + l ) ; buffer = b ; } countRead += buffer . remaining ( ) ; if ( buffer . hasRemaining ( ) ) { wrappee . received ( buffer ) ; } if ( countRead == contentLength ) { ended = true ; wrappee . ended ( ) ; } }
MUST sync-ly consume buffer
MUST sync - ly consume buffer