• 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

68.75
/../netty/src/main/java/io/grpc/netty/NettyReadableBuffer.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.netty;
18

19
import com.google.common.base.Preconditions;
20
import io.grpc.internal.AbstractReadableBuffer;
21
import io.netty.buffer.ByteBuf;
22
import java.io.IOException;
23
import java.io.OutputStream;
24
import java.nio.ByteBuffer;
25

26
/**
27
 * A {@link java.nio.Buffer} implementation that is backed by a Netty {@link ByteBuf}. This class
28
 * does not call {@link ByteBuf#retain}, so if that is needed it should be called prior to creating
29
 * this buffer.
30
 */
31
class NettyReadableBuffer extends AbstractReadableBuffer {
32
  private final ByteBuf buffer;
33
  private boolean closed;
34

35
  NettyReadableBuffer(ByteBuf buffer) {
1✔
36
    this.buffer = Preconditions.checkNotNull(buffer, "buffer");
1✔
37
  }
1✔
38

39
  ByteBuf buffer() {
40
    return buffer;
1✔
41
  }
42

43
  @Override
44
  public int readableBytes() {
45
    return buffer.readableBytes();
1✔
46
  }
47

48
  @Override
49
  public void skipBytes(int length) {
50
    buffer.skipBytes(length);
×
51
  }
×
52

53
  @Override
54
  public int readUnsignedByte() {
55
    return buffer.readUnsignedByte();
1✔
56
  }
57

58
  @Override
59
  public void readBytes(byte[] dest, int index, int length) {
60
    buffer.readBytes(dest, index, length);
1✔
61
  }
1✔
62

63
  @Override
64
  public void readBytes(OutputStream dest, int length) {
65
    try {
66
      buffer.readBytes(dest, length);
1✔
67
    } catch (IOException e) {
×
68
      throw new RuntimeException(e);
×
69
    }
1✔
70
  }
1✔
71

72
  @Override
73
  public NettyReadableBuffer readBytes(int length) {
74
    return new NettyReadableBuffer(buffer.readRetainedSlice(length));
1✔
75
  }
76

77
  @Override
78
  public boolean hasArray() {
79
    return buffer.hasArray();
×
80
  }
81

82
  @Override
83
  public byte[] array() {
84
    return buffer.array();
×
85
  }
86

87
  @Override
88
  public int arrayOffset() {
89
    return buffer.arrayOffset() + buffer.readerIndex();
×
90
  }
91

92
  @Override
93
  public void touch() {
94
    buffer.touch();
×
95
  }
×
96

97
  @Override
98
  public boolean markSupported() {
99
    return true;
×
100
  }
101

102
  @Override
103
  public void mark() {
104
    buffer.markReaderIndex();
1✔
105
  }
1✔
106

107
  @Override
108
  public void reset() {
109
    buffer.resetReaderIndex();
1✔
110
  }
1✔
111

112
  @Override
113
  public boolean byteBufferSupported() {
114
    return buffer.nioBufferCount() > 0;
1✔
115
  }
116

117
  @Override
118
  public ByteBuffer getByteBuffer() {
119
    return buffer.nioBufferCount() == 1 ? buffer.nioBuffer() : buffer.nioBuffers()[0];
1✔
120
  }
121

122
  /**
123
   * If the first call to close, calls {@link ByteBuf#release} to release the internal Netty buffer.
124
   */
125
  @Override
126
  public void close() {
127
    // Don't allow slices to close. Also, only allow close to be called once.
128
    if (!closed) {
1✔
129
      closed = true;
1✔
130
      buffer.release();
1✔
131
    }
132
  }
1✔
133
}
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