Skip to content

Commit

Permalink
Merge pull request square#516 from square/jwilson_0208_byte_at_to_get…
Browse files Browse the repository at this point in the history
…_byte

Rename byteAt to getByte.
  • Loading branch information
Adrian Cole committed Feb 8, 2014
2 parents 1b25214 + 1f97e6b commit 4c8ce7c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ private void consumeHeader(Deadline deadline) throws IOException {
// |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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public byte readByte() {
}

/** 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -516,17 +516,17 @@ private List<Integer> moveBytesBetweenBuffers(String... contents) {
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) {
}
Expand Down

0 comments on commit 4c8ce7c

Please sign in to comment.