]> git.proxmox.com Git - ceph.git/blob - ceph/src/jaegertracing/thrift/lib/java/src/org/apache/thrift/transport/TMemoryInputTransport.java
buildsys: switch source download to quincy
[ceph.git] / ceph / src / jaegertracing / thrift / lib / java / src / org / apache / thrift / transport / TMemoryInputTransport.java
1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19 package org.apache.thrift.transport;
20
21 public final class TMemoryInputTransport extends TTransport {
22
23 private byte[] buf_;
24 private int pos_;
25 private int endPos_;
26
27 public TMemoryInputTransport() {
28 }
29
30 public TMemoryInputTransport(byte[] buf) {
31 reset(buf);
32 }
33
34 public TMemoryInputTransport(byte[] buf, int offset, int length) {
35 reset(buf, offset, length);
36 }
37
38 public void reset(byte[] buf) {
39 reset(buf, 0, buf.length);
40 }
41
42 public void reset(byte[] buf, int offset, int length) {
43 buf_ = buf;
44 pos_ = offset;
45 endPos_ = offset + length;
46 }
47
48 public void clear() {
49 buf_ = null;
50 }
51
52 @Override
53 public void close() {}
54
55 @Override
56 public boolean isOpen() {
57 return true;
58 }
59
60 @Override
61 public void open() throws TTransportException {}
62
63 @Override
64 public int read(byte[] buf, int off, int len) throws TTransportException {
65 int bytesRemaining = getBytesRemainingInBuffer();
66 int amtToRead = (len > bytesRemaining ? bytesRemaining : len);
67 if (amtToRead > 0) {
68 System.arraycopy(buf_, pos_, buf, off, amtToRead);
69 consumeBuffer(amtToRead);
70 }
71 return amtToRead;
72 }
73
74 @Override
75 public void write(byte[] buf, int off, int len) throws TTransportException {
76 throw new UnsupportedOperationException("No writing allowed!");
77 }
78
79 @Override
80 public byte[] getBuffer() {
81 return buf_;
82 }
83
84 public int getBufferPosition() {
85 return pos_;
86 }
87
88 public int getBytesRemainingInBuffer() {
89 return endPos_ - pos_;
90 }
91
92 public void consumeBuffer(int len) {
93 pos_ += len;
94 }
95
96 }