Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 0 additions & 20 deletions core/src/main/java/io/grpc/internal/CompositeReadableBuffer.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import java.io.IOException;
import java.io.OutputStream;
import java.nio.Buffer;
import java.nio.ByteBuffer;
import java.nio.InvalidMarkException;
import java.util.ArrayDeque;
Expand Down Expand Up @@ -120,20 +119,6 @@ public int read(ReadableBuffer buffer, int length, byte[] dest, int offset) {
}
};

private static final NoThrowReadOperation<ByteBuffer> BYTE_BUF_OP =
new NoThrowReadOperation<ByteBuffer>() {
@Override
public int read(ReadableBuffer buffer, int length, ByteBuffer dest, int unused) {
// Change the limit so that only lengthToCopy bytes are available.
int prevLimit = dest.limit();
((Buffer) dest).limit(dest.position() + length);
// Write the bytes and restore the original limit.
buffer.readBytes(dest);
((Buffer) dest).limit(prevLimit);
return 0;
}
};

private static final ReadOperation<OutputStream> STREAM_OP =
new ReadOperation<OutputStream>() {
@Override
Expand All @@ -149,11 +134,6 @@ public void readBytes(byte[] dest, int destOffset, int length) {
executeNoThrow(BYTE_ARRAY_OP, length, dest, destOffset);
}

@Override
public void readBytes(ByteBuffer dest) {
executeNoThrow(BYTE_BUF_OP, dest.remaining(), dest, 0);
}

@Override
public void readBytes(OutputStream dest, int length) throws IOException {
execute(STREAM_OP, length, dest, 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,6 @@ public void readBytes(byte[] dest, int destOffset, int length) {
buf.readBytes(dest, destOffset, length);
}

@Override
public void readBytes(ByteBuffer dest) {
buf.readBytes(dest);
}

@Override
public void readBytes(OutputStream dest, int length) throws IOException {
buf.readBytes(dest, length);
Expand Down
9 changes: 0 additions & 9 deletions core/src/main/java/io/grpc/internal/ReadableBuffer.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,6 @@ public interface ReadableBuffer extends Closeable {
*/
void readBytes(byte[] dest, int destOffset, int length);

/**
* Reads from this buffer until the destination's position reaches its limit, and increases the
* read position by the number of the transferred bytes.
*
* @param dest the destination buffer to receive the bytes.
* @throws IndexOutOfBoundsException if required bytes are not readable
*/
void readBytes(ByteBuffer dest);

/**
* Reads {@code length} bytes from this buffer and writes them to the destination stream.
* Increments the read position by {@code length}. If the required bytes are not readable, throws
Expand Down
24 changes: 0 additions & 24 deletions core/src/main/java/io/grpc/internal/ReadableBuffers.java
Original file line number Diff line number Diff line change
Expand Up @@ -171,15 +171,6 @@ public void readBytes(byte[] dest, int destIndex, int length) {
offset += length;
}

@Override
public void readBytes(ByteBuffer dest) {
Preconditions.checkNotNull(dest, "dest");
int length = dest.remaining();
checkReadable(length);
dest.put(bytes, offset, length);
offset += length;
}

@Override
public void readBytes(OutputStream dest, int length) throws IOException {
checkReadable(length);
Expand Down Expand Up @@ -262,21 +253,6 @@ public void readBytes(byte[] dest, int destOffset, int length) {
bytes.get(dest, destOffset, length);
}

@Override
public void readBytes(ByteBuffer dest) {
Preconditions.checkNotNull(dest, "dest");
int length = dest.remaining();
checkReadable(length);

// Change the limit so that only length bytes are available.
int prevLimit = bytes.limit();
((Buffer) bytes).limit(bytes.position() + length);

// Write the bytes and restore the original limit.
dest.put(bytes);
bytes.limit(prevLimit);
}

@Override
public void readBytes(OutputStream dest, int length) throws IOException {
checkReadable(length);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.nio.Buffer;
import java.nio.ByteBuffer;
import java.nio.InvalidMarkException;
import org.junit.After;
import org.junit.Before;
Expand Down Expand Up @@ -121,27 +119,6 @@ public void readByteArrayShouldSucceed() {
assertEquals(EXPECTED_VALUE, new String(bytes, UTF_8));
}

@Test
public void readByteBufferShouldSucceed() {
ByteBuffer byteBuffer = ByteBuffer.allocate(EXPECTED_VALUE.length());
int remaining = EXPECTED_VALUE.length();

((Buffer) byteBuffer).limit(1);
composite.readBytes(byteBuffer);
remaining--;
assertEquals(remaining, composite.readableBytes());

((Buffer) byteBuffer).limit(byteBuffer.limit() + 5);
composite.readBytes(byteBuffer);
remaining -= 5;
assertEquals(remaining, composite.readableBytes());

((Buffer) byteBuffer).limit(byteBuffer.limit() + remaining);
composite.readBytes(byteBuffer);
assertEquals(0, composite.readableBytes());
assertEquals(EXPECTED_VALUE, new String(byteBuffer.array(), UTF_8));
}

@Test
public void readStreamShouldSucceed() throws IOException {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
Expand Down Expand Up @@ -216,18 +193,6 @@ public void markAndResetWithReadByteArrayShouldSucceed() {
assertArrayEquals(first, second);
}

@Test
public void markAndResetWithReadByteBufferShouldSucceed() {
byte[] first = new byte[EXPECTED_VALUE.length()];
composite.mark();
composite.readBytes(ByteBuffer.wrap(first));
composite.reset();
byte[] second = new byte[EXPECTED_VALUE.length()];
assertEquals(EXPECTED_VALUE.length(), composite.readableBytes());
composite.readBytes(ByteBuffer.wrap(second));
assertArrayEquals(first, second);
}

@Test
public void markAndResetWithReadStreamShouldSucceed() throws IOException {
ByteArrayOutputStream first = new ByteArrayOutputStream();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import java.io.IOException;
import java.io.OutputStream;
import java.lang.reflect.Method;
import java.nio.ByteBuffer;
import java.util.Collections;
import org.junit.Before;
import org.junit.Rule;
Expand Down Expand Up @@ -91,14 +90,6 @@ public void readBytes() {
verify(delegate).readBytes(dest, 1, 2);
}

@Test
public void readBytes_overload1() {
ByteBuffer dest = ByteBuffer.allocate(0);
buffer.readBytes(dest);

verify(delegate).readBytes(dest);
}

@Test
public void readBytes_overload2() throws IOException {
OutputStream dest = mock(OutputStream.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import static org.junit.Assert.assertEquals;

import java.io.ByteArrayOutputStream;
import java.nio.Buffer;
import java.nio.ByteBuffer;
import java.util.Arrays;
import org.junit.Assume;
Expand Down Expand Up @@ -83,30 +82,6 @@ public void partialReadToStreamShouldSucceed() throws Exception {
assertEquals(msg.length() - 2, buffer.readableBytes());
}

@Test
public void readToByteBufferShouldSucceed() {
ReadableBuffer buffer = buffer();
ByteBuffer byteBuffer = ByteBuffer.allocate(msg.length());
buffer.readBytes(byteBuffer);
((Buffer) byteBuffer).flip();
byte[] array = new byte[msg.length()];
byteBuffer.get(array);
assertArrayEquals(msg.getBytes(UTF_8), array);
assertEquals(0, buffer.readableBytes());
}

@Test
public void partialReadToByteBufferShouldSucceed() {
ReadableBuffer buffer = buffer();
ByteBuffer byteBuffer = ByteBuffer.allocate(2);
buffer.readBytes(byteBuffer);
((Buffer) byteBuffer).flip();
byte[] array = new byte[2];
byteBuffer.get(array);
assertArrayEquals(new byte[]{'h', 'e'}, array);
assertEquals(msg.length() - 2, buffer.readableBytes());
}

@Test
public void partialReadToReadableBufferShouldSucceed() {
ReadableBuffer buffer = buffer();
Expand Down
5 changes: 0 additions & 5 deletions netty/src/main/java/io/grpc/netty/NettyReadableBuffer.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,6 @@ public void readBytes(byte[] dest, int index, int length) {
buffer.readBytes(dest, index, length);
}

@Override
public void readBytes(ByteBuffer dest) {
buffer.readBytes(dest);
}

@Override
public void readBytes(OutputStream dest, int length) {
try {
Expand Down
7 changes: 0 additions & 7 deletions okhttp/src/main/java/io/grpc/okhttp/OkHttpReadableBuffer.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import java.io.EOFException;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.ByteBuffer;

/**
* A {@link ReadableBuffer} implementation that is backed by an {@link okio.Buffer}.
Expand Down Expand Up @@ -71,12 +70,6 @@ public void readBytes(byte[] dest, int destOffset, int length) {
}
}

@Override
public void readBytes(ByteBuffer dest) {
// We are not using it.
throw new UnsupportedOperationException();
}

@Override
public void readBytes(OutputStream dest, int length) throws IOException {
buffer.writeTo(dest, length);
Expand Down
12 changes: 0 additions & 12 deletions okhttp/src/test/java/io/grpc/okhttp/OkHttpReadableBufferTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,6 @@ public void setup() {
}
}

@Override
@Test
public void readToByteBufferShouldSucceed() {
// Not supported.
}

@Override
@Test
public void partialReadToByteBufferShouldSucceed() {
// Not supported.
}

@Override
@Test
public void markAndResetWithReadShouldSucceed() {
Expand Down