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

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).
This commit is contained in:
jwilson
2014-02-08 07:44:47 -05:00
parent 1b25214f59
commit 1f97e6b74c
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) {
}