From 1f97e6b74cd1f8a880264f6da500087172adfa7f Mon Sep 17 00:00:00 2001 From: jwilson Date: Sat, 8 Feb 2014 07:44:47 -0500 Subject: [PATCH] Rename byteAt to getByte. Should we later support random access for other primitives or random bulk access, I'd like the prefix to stay constant (getByte, getInt, getLong, getBytes) vs. the suffix (byteAt, intAt, longAt). Prefixing may work better for autocomplete in IDEs, particularly since we already use a prefix for our consuming reads (readByte, readInt, readLong). --- .../squareup/okhttp/internal/bytes/GzipSource.java | 2 +- .../squareup/okhttp/internal/bytes/OkBuffer.java | 2 +- .../okhttp/internal/bytes/OkBufferTest.java | 14 +++++++------- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/okhttp-protocols/src/main/java/com/squareup/okhttp/internal/bytes/GzipSource.java b/okhttp-protocols/src/main/java/com/squareup/okhttp/internal/bytes/GzipSource.java index 75d305c9d..14fa221d8 100644 --- a/okhttp-protocols/src/main/java/com/squareup/okhttp/internal/bytes/GzipSource.java +++ b/okhttp-protocols/src/main/java/com/squareup/okhttp/internal/bytes/GzipSource.java @@ -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); diff --git a/okhttp-protocols/src/main/java/com/squareup/okhttp/internal/bytes/OkBuffer.java b/okhttp-protocols/src/main/java/com/squareup/okhttp/internal/bytes/OkBuffer.java index d4cb5115a..cf6ddbdff 100644 --- a/okhttp-protocols/src/main/java/com/squareup/okhttp/internal/bytes/OkBuffer.java +++ b/okhttp-protocols/src/main/java/com/squareup/okhttp/internal/bytes/OkBuffer.java @@ -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; diff --git a/okhttp-protocols/src/test/java/com/squareup/okhttp/internal/bytes/OkBufferTest.java b/okhttp-protocols/src/test/java/com/squareup/okhttp/internal/bytes/OkBufferTest.java index 909d9f764..595ae4ac8 100644 --- a/okhttp-protocols/src/test/java/com/squareup/okhttp/internal/bytes/OkBufferTest.java +++ b/okhttp-protocols/src/test/java/com/squareup/okhttp/internal/bytes/OkBufferTest.java @@ -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) { }