1
0
mirror of https://github.com/square/okhttp.git synced 2026-01-22 15:42:00 +03:00

Merge pull request #516 from square/jwilson_0208_byte_at_to_get_byte

Rename byteAt to getByte.
This commit is contained in:
Adrian Cole
2014-02-08 10:17:00 -05:00
3 changed files with 9 additions and 9 deletions

View File

@@ -109,7 +109,7 @@ public final class GzipSource implements Source {
// |ID1|ID2|CM |FLG| MTIME |XFL|OS | (more-->)
// +---+---+---+---+---+---+---+---+---+---+
require(10, deadline);
byte flags = buffer.byteAt(3);
byte flags = buffer.getByte(3);
boolean fhcrc = ((flags >> FHCRC) & 1) == 1;
if (fhcrc) updateCrc(buffer, 0, 10);

View File

@@ -76,7 +76,7 @@ public final class OkBuffer implements Source, Sink {
}
/** Returns the byte at {@code i}. */
public byte byteAt(long i) {
public byte getByte(long i) {
checkOffsetAndCount(byteCount, i, 1);
for (Segment s = head; true; s = s.next) {
int segmentByteCount = s.limit - s.pos;

View File

@@ -516,17 +516,17 @@ public final class OkBufferTest {
buffer.writeUtf8("a");
buffer.writeUtf8(repeat('b', Segment.SIZE));
buffer.writeUtf8("c");
assertEquals('a', buffer.byteAt(0));
assertEquals('a', buffer.byteAt(0)); // Peek doesn't mutate!
assertEquals('c', buffer.byteAt(buffer.byteCount - 1));
assertEquals('b', buffer.byteAt(buffer.byteCount - 2));
assertEquals('b', buffer.byteAt(buffer.byteCount - 3));
assertEquals('a', buffer.getByte(0));
assertEquals('a', buffer.getByte(0)); // getByte doesn't mutate!
assertEquals('c', buffer.getByte(buffer.byteCount - 1));
assertEquals('b', buffer.getByte(buffer.byteCount - 2));
assertEquals('b', buffer.getByte(buffer.byteCount - 3));
}
@Test public void byteAtOfEmptyBuffer() throws Exception {
@Test public void getByteOfEmptyBuffer() throws Exception {
OkBuffer buffer = new OkBuffer();
try {
buffer.byteAt(0);
buffer.getByte(0);
fail();
} catch (IndexOutOfBoundsException expected) {
}