Skip to content

Commit

Permalink
Automatic code cleanup.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 383207440
  • Loading branch information
Googler authored and copybara-github committed Jul 6, 2021
1 parent 6a2e606 commit ec3d4bd
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,19 @@ public long read(ByteBuffer[] dsts, int offset, int length) throws IOException {
throw new UnsupportedOperationException("Not supported yet.");
}

@Override
public int read(ByteBuffer dst, long position) throws IOException {
if (position < 0 || position >= data.length) {
throw new IOException("out of bounds");
}
int remaining = data.length - (int) position;
if (dst.remaining() < remaining) {
remaining = dst.remaining();
}
dst.put(data, (int) position, remaining);
return remaining;
}

@Override
public int write(ByteBuffer src) throws IOException {
throw new UnsupportedOperationException("Not supported yet.");
Expand All @@ -124,6 +137,11 @@ public long write(ByteBuffer[] srcs, int offset, int length) throws IOException
throw new UnsupportedOperationException("Not supported yet.");
}

@Override
public int write(ByteBuffer src, long position) throws IOException {
throw new UnsupportedOperationException("Not supported yet.");
}

@Override
public long position() throws IOException {
return position;
Expand Down Expand Up @@ -162,24 +180,6 @@ public long transferFrom(ReadableByteChannel src, long position, long count)
throw new UnsupportedOperationException("Not supported yet.");
}

@Override
public int read(ByteBuffer dst, long position) throws IOException {
if (position < 0 || position >= data.length) {
throw new IOException("out of bounds");
}
int remaining = data.length - (int) position;
if (dst.remaining() < remaining) {
remaining = dst.remaining();
}
dst.put(data, (int) position, remaining);
return remaining;
}

@Override
public int write(ByteBuffer src, long position) throws IOException {
throw new UnsupportedOperationException("Not supported yet.");
}

@Override
public MappedByteBuffer map(FileChannel.MapMode mode, long position, long size)
throws IOException {
Expand Down Expand Up @@ -227,6 +227,11 @@ public long read(ByteBuffer[] dsts, int offset, int length) throws IOException {
throw new UnsupportedOperationException("Not supported yet.");
}

@Override
public int read(ByteBuffer dst, long position) throws IOException {
throw new UnsupportedOperationException("Not supported yet.");
}

@Override
public int write(ByteBuffer src) throws IOException {
byte[] bytes = new byte[src.remaining()];
Expand All @@ -241,6 +246,11 @@ public long write(ByteBuffer[] srcs, int offset, int length) throws IOException
throw new UnsupportedOperationException("Not supported yet.");
}

@Override
public int write(ByteBuffer src, long position) throws IOException {
throw new UnsupportedOperationException("Not supported yet.");
}

@Override
public long position() throws IOException {
return position;
Expand Down Expand Up @@ -278,16 +288,6 @@ public long transferFrom(ReadableByteChannel src, long position, long count)
throw new UnsupportedOperationException("Not supported yet.");
}

@Override
public int read(ByteBuffer dst, long position) throws IOException {
throw new UnsupportedOperationException("Not supported yet.");
}

@Override
public int write(ByteBuffer src, long position) throws IOException {
throw new UnsupportedOperationException("Not supported yet.");
}

@Override
public MappedByteBuffer map(FileChannel.MapMode mode, long position, long size)
throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ public void testScanBackwardsTo() {
private void assertLocation(byte[] target, byte[] domain, int expected) {
int pos = ScanUtil.scanTo(target, domain != null ? ByteBuffer.wrap(domain) : null);
assertWithMessage("Position of " + Arrays.toString(target) + " in " + Arrays.toString(domain))
.that(expected).isEqualTo(pos);
.that(pos)
.isEqualTo(expected);
}

private void assertBackwardsLocation(byte[] target, byte[] domain, int expected) {
Expand All @@ -90,8 +91,16 @@ private void assertBackwardsLocation(byte[] target, byte[] domain, int expected)
buf.position(buf.limit());
}
int pos = ScanUtil.scanBackwardsTo(target, buf);
assertWithMessage("Position of " + Arrays.toString(target) + " in " + Arrays.toString(domain)
+ ", " + buf.position() + ", " + buf.limit())
.that(expected).isEqualTo(pos);
assertWithMessage(
"Position of "
+ Arrays.toString(target)
+ " in "
+ Arrays.toString(domain)
+ ", "
+ buf.position()
+ ", "
+ buf.limit())
.that(pos)
.isEqualTo(expected);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -143,22 +143,22 @@ static class TestView extends View<TestView> {
super(buffer);
}

// Will advance buffer position
// Will advance buffer position.
public void putInt(int value) {
buffer.putInt(value);
}

// Will advance buffer position
public int getInt() {
return buffer.getInt();
}

// will not advance buffer position
// Will not advance buffer position.
public void putInt(int index, int value) {
buffer.putInt(index, value);
}

// will not advance buffer position
// Will advance buffer position.
public int getInt() {
return buffer.getInt();
}

// Will not advance buffer position.
public int getInt(int index) {
return buffer.getInt(index);
}
Expand Down

0 comments on commit ec3d4bd

Please sign in to comment.