• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

grpc / grpc-java / #20123

22 Dec 2025 07:27PM UTC coverage: 88.719% (-0.03%) from 88.747%
#20123

push

github

web-flow
core: Delete ReadableBuffer.readBytes(ByteBuffer) (#12580)

At the very least it isn't used now. The method is as old as
ReadableBuffer itself (05a2b252b), but it appears to have never actually
been used.

35445 of 39952 relevant lines covered (88.72%)

0.89 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

72.41
/../okhttp/src/main/java/io/grpc/okhttp/OkHttpReadableBuffer.java
1
/*
2
 * Copyright 2014 The gRPC Authors
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *     http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16

17
package io.grpc.okhttp;
18

19
import io.grpc.internal.AbstractReadableBuffer;
20
import io.grpc.internal.ReadableBuffer;
21
import java.io.EOFException;
22
import java.io.IOException;
23
import java.io.OutputStream;
24

25
/**
26
 * A {@link ReadableBuffer} implementation that is backed by an {@link okio.Buffer}.
27
 */
28
class OkHttpReadableBuffer extends AbstractReadableBuffer {
29
  private final okio.Buffer buffer;
30

31
  OkHttpReadableBuffer(okio.Buffer buffer) {
1✔
32
    this.buffer = buffer;
1✔
33
  }
1✔
34

35
  @Override
36
  public int readableBytes() {
37
    return (int) buffer.size();
1✔
38
  }
39

40
  @Override
41
  public int readUnsignedByte() {
42
    try {
43
      fakeEofExceptionMethod(); // Okio 2.x can throw EOFException from readByte()
1✔
44
      return buffer.readByte() & 0x000000FF;
1✔
45
    } catch (EOFException e) {
×
46
      throw new IndexOutOfBoundsException(e.getMessage());
×
47
    }
48
  }
49

50
  private void fakeEofExceptionMethod() throws EOFException {}
1✔
51

52
  @Override
53
  public void skipBytes(int length) {
54
    try {
55
      buffer.skip(length);
×
56
    } catch (EOFException e) {
×
57
      throw new IndexOutOfBoundsException(e.getMessage());
×
58
    }
×
59
  }
×
60

61
  @Override
62
  public void readBytes(byte[] dest, int destOffset, int length) {
63
    while (length > 0) {
1✔
64
      int bytesRead = buffer.read(dest, destOffset, length);
1✔
65
      if (bytesRead == -1) {
1✔
66
        throw new IndexOutOfBoundsException("EOF trying to read " + length + " bytes");
×
67
      }
68
      length -= bytesRead;
1✔
69
      destOffset += bytesRead;
1✔
70
    }
1✔
71
  }
1✔
72

73
  @Override
74
  public void readBytes(OutputStream dest, int length) throws IOException {
75
    buffer.writeTo(dest, length);
1✔
76
  }
1✔
77

78
  @Override
79
  public ReadableBuffer readBytes(int length) {
80
    okio.Buffer buf = new okio.Buffer();
1✔
81
    buf.write(buffer, length);
1✔
82
    return new OkHttpReadableBuffer(buf);
1✔
83
  }
84

85
  @Override
86
  public void close() {
87
    buffer.clear();
1✔
88
  }
1✔
89
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc