Skip to content

Package: AbstractTGrizzlyTransport

AbstractTGrizzlyTransport

nameinstructionbranchcomplexitylinemethod
AbstractTGrizzlyTransport()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
checkReadBytesAvailable(long)
M: 1 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getConfiguration()
M: 2 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
open()
M: 1 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
read(byte[], int, int)
M: 21 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 5 C: 0
0%
M: 1 C: 0
0%
updateKnownMessageSize(long)
M: 1 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
write(byte[], int, int)
M: 18 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 7 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*
2: * Copyright (c) 2011, 2022 Oracle and/or its affiliates. All rights reserved.
3: *
4: * This program and the accompanying materials are made available under the
5: * terms of the Eclipse Public License v. 2.0, which is available at
6: * http://www.eclipse.org/legal/epl-2.0.
7: *
8: * This Source Code may also be made available under the following Secondary
9: * Licenses when the conditions for such availability set forth in the
10: * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
11: * version 2 with the GNU Classpath Exception, which is available at
12: * https://www.gnu.org/software/classpath/license.html.
13: *
14: * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15: */
16:
17: package org.glassfish.grizzly.thrift;
18:
19: import java.io.IOException;
20:
21: import org.apache.thrift.TConfiguration;
22: import org.apache.thrift.transport.TTransport;
23: import org.apache.thrift.transport.TTransportException;
24: import org.glassfish.grizzly.Buffer;
25: import org.glassfish.grizzly.utils.BufferOutputStream;
26:
27: /**
28: * Abstract class for implementing thrift's TTransport. By using
29: * BufferOutputStream, the output buffer will be increased automatically by
30: * given MemoryManager if it doesn't have enough spaces.
31: *
32: * @author Bongjae Chang
33: */
34: public abstract class AbstractTGrizzlyTransport extends TTransport {
35:
36: @Override
37: public void open() throws TTransportException {
38: }
39:
40: @Override
41: public int read(byte[] buf, int off, int len) throws TTransportException {
42: final Buffer input = getInputBuffer();
43: final int readableBytes = input.remaining();
44:• final int bytesToRead = len > readableBytes ? readableBytes : len;
45: input.get(buf, off, bytesToRead);
46: return bytesToRead;
47: }
48:
49: @Override
50: public void write(byte[] buf, int off, int len) throws TTransportException {
51: final BufferOutputStream outputStream = getOutputStream();
52:• if (outputStream != null) {
53: try {
54: outputStream.write(buf, off, len);
55: } catch (IOException ie) {
56: throw new TTransportException(ie);
57: }
58: }
59: }
60:
61: @Override
62: public abstract void flush() throws TTransportException;
63:
64: @Override
65: public TConfiguration getConfiguration() {
66: return null;
67: }
68:
69: @Override
70: public void updateKnownMessageSize(long l) throws TTransportException {
71:
72: }
73:
74: @Override
75: public void checkReadBytesAvailable(long l) throws TTransportException {
76:
77: }
78:
79: protected abstract Buffer getInputBuffer() throws TTransportException;
80:
81: protected abstract BufferOutputStream getOutputStream() throws TTransportException;
82: }