annotate src/org/eclipse/jetty/io/JBuffer.java @ 1054:87275900646e

remove JBuffer.toString()
author Franklin Schmidt <fschmidt@gmail.com>
date Tue, 08 Nov 2016 01:03:02 -0700
parents 7e4b41247544
children 013939bfc9e8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1046
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1 // tmp class to implement Buffer until I can get rid of it
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3 package org.eclipse.jetty.io;
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
5 import java.io.InputStream;
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
6 import java.io.IOException;
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
7 import java.nio.ByteBuffer;
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
8 import java.nio.channels.Channels;
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
9 import java.nio.channels.ReadableByteChannel;
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
10 import org.slf4j.Logger;
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
11 import org.slf4j.LoggerFactory;
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
12 import org.eclipse.jetty.util.TypeUtil;
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
13
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
14
1048
2b769da7f67d remove Buffer
Franklin Schmidt <fschmidt@gmail.com>
parents: 1046
diff changeset
15 public final class JBuffer {
1046
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
16 private static final Logger LOG = LoggerFactory.getLogger(JBuffer.class);
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
17
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
18 private final ByteBuffer bb;
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
19
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
20 public JBuffer(ByteBuffer bb) {
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
21 this.bb = bb;
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
22 }
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
23
1050
5ef954fad97b remove JBuffer.sliceFrom()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1049
diff changeset
24 public int position() {
5ef954fad97b remove JBuffer.sliceFrom()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1049
diff changeset
25 return bb.position();
5ef954fad97b remove JBuffer.sliceFrom()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1049
diff changeset
26 }
5ef954fad97b remove JBuffer.sliceFrom()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1049
diff changeset
27
5ef954fad97b remove JBuffer.sliceFrom()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1049
diff changeset
28 public void position(int i) {
5ef954fad97b remove JBuffer.sliceFrom()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1049
diff changeset
29 bb.position(i);
5ef954fad97b remove JBuffer.sliceFrom()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1049
diff changeset
30 }
5ef954fad97b remove JBuffer.sliceFrom()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1049
diff changeset
31
5ef954fad97b remove JBuffer.sliceFrom()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1049
diff changeset
32 public void limit(int i) {
5ef954fad97b remove JBuffer.sliceFrom()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1049
diff changeset
33 bb.limit(i);
5ef954fad97b remove JBuffer.sliceFrom()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1049
diff changeset
34 }
5ef954fad97b remove JBuffer.sliceFrom()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1049
diff changeset
35
1046
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
36 public byte[] array() {
1053
7e4b41247544 fix JBuffer.array()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1052
diff changeset
37 return bb.array();
7e4b41247544 fix JBuffer.array()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1052
diff changeset
38 }
7e4b41247544 fix JBuffer.array()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1052
diff changeset
39
7e4b41247544 fix JBuffer.array()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1052
diff changeset
40 public boolean hasArray() {
7e4b41247544 fix JBuffer.array()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1052
diff changeset
41 return bb.hasArray();
1046
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
42 }
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
43
1048
2b769da7f67d remove Buffer
Franklin Schmidt <fschmidt@gmail.com>
parents: 1046
diff changeset
44 public JBuffer duplicate() {
1046
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
45 return new JBuffer(bb.duplicate());
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
46 }
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
47
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
48 public int remaining() {
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
49 return bb.remaining();
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
50 }
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
51
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
52 public boolean isReadOnly() {
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
53 return bb.isReadOnly();
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
54 }
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
55
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
56 public boolean hasRemaining() {
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
57 return bb.hasRemaining();
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
58 }
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
59
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
60 public byte get() {
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
61 return bb.get();
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
62 }
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
63
1054
87275900646e remove JBuffer.toString()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1053
diff changeset
64 public void get(byte[] bytes) {
87275900646e remove JBuffer.toString()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1053
diff changeset
65 bb.get(bytes);
87275900646e remove JBuffer.toString()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1053
diff changeset
66 }
87275900646e remove JBuffer.toString()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1053
diff changeset
67
1046
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
68 public void compact() {
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
69 int n = bb.remaining();
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
70 bb.compact();
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
71 bb.position(0);
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
72 bb.limit(n);
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
73 }
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
74
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
75 public int capacity() {
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
76 return bb.capacity();
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
77 }
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
78
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
79
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
80
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
81 public ByteBuffer getByteBuffer() {
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
82 ByteBuffer dup = bb.duplicate();
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
83 dup.limit(dup.capacity());
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
84 return dup;
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
85 }
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
86
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
87 public int getIndex() {
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
88 return bb.position();
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
89 }
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
90
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
91 public void clear() {
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
92 bb.position(0);
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
93 bb.limit(0);
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
94 }
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
95
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
96 public int space() {
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
97 return bb.capacity() - bb.limit();
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
98 }
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
99
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
100
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
101 public int get(byte[] b, int offset, int length) {
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
102 int remaining = bb.remaining();
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
103 if( remaining == 0 )
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
104 return -1;
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
105 if( length > remaining )
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
106 length = remaining;
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
107 bb.get(b,offset,length);
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
108 return length;
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
109 }
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
110
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
111
1048
2b769da7f67d remove Buffer
Franklin Schmidt <fschmidt@gmail.com>
parents: 1046
diff changeset
112 public int put(JBuffer src) {
1046
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
113 return put(src.asArray());
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
114 }
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
115
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
116 public void put(byte b)
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
117 {
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
118 ByteBuffer dup = bb.duplicate();
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
119 dup.position(bb.limit());
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
120 dup.limit(bb.capacity());
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
121 dup.put(b);
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
122 bb.limit(bb.limit()+1);
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
123 }
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
124
1049
4afdf0f0c5bc remove unused JBuffer methods
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
125 private int put(byte[] b, int offset, int length) {
1046
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
126 ByteBuffer dup = bb.duplicate();
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
127 int put = bb.limit();
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
128 int capacity = bb.capacity();
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
129 dup.position(put);
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
130 dup.limit(capacity);
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
131 if( length > capacity - put )
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
132 length = capacity - put;
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
133 dup.put(b,offset,length);
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
134 bb.limit(put+length);
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
135 return length;
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
136 }
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
137
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
138 public int put(byte[] b) {
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
139 return put(b,0,b.length);
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
140 }
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
141
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
142 public final int putIndex() {
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
143 return bb.limit();
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
144 }
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
145
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
146 public void setGetIndex(int getIndex) {
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
147 bb.position(getIndex);
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
148 }
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
149
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
150 public void setPutIndex(int putIndex) {
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
151 bb.limit(putIndex);
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
152 }
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
153
1051
1ab2dd0a7db5 remove JBuffer.get(int)
Franklin Schmidt <fschmidt@gmail.com>
parents: 1050
diff changeset
154 public void skip(int n) {
1046
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
155 if (remaining() < n) n = remaining();
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
156 bb.position(bb.position() + n);
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
157 }
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
158
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
159 public int readFrom(InputStream in,int max) throws IOException {
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
160 ByteBuffer dup = bb.duplicate();
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
161 int put = bb.limit();
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
162 dup.limit( Math.min(put+max,bb.capacity()) );
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
163 dup.position(put);
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
164
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
165 ReadableByteChannel chan = Channels.newChannel(in);
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
166 int n = chan.read(dup);
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
167
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
168 if( n > 0 )
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
169 bb.limit(put+n);
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
170 return n;
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
171 }
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
172
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
173 public final byte[] asArray() {
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
174 byte[] bytes = new byte[remaining()];
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
175 bb.duplicate().get(bytes);
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
176 return bytes;
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
177 }
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
178
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
179 @Override
1054
87275900646e remove JBuffer.toString()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1053
diff changeset
180 public String toString() {
87275900646e remove JBuffer.toString()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1053
diff changeset
181 // return toString("ISO-8859-1");
87275900646e remove JBuffer.toString()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1053
diff changeset
182 // Thread.dumpStack();
87275900646e remove JBuffer.toString()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1053
diff changeset
183 throw new RuntimeException("toString");
1046
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
184 }
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
185
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
186
1048
2b769da7f67d remove Buffer
Franklin Schmidt <fschmidt@gmail.com>
parents: 1046
diff changeset
187 private JBuffer pokeBuffer(int index) {
2b769da7f67d remove Buffer
Franklin Schmidt <fschmidt@gmail.com>
parents: 1046
diff changeset
188 JBuffer dup = duplicate();
1046
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
189 dup.setPutIndex(index);
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
190 return dup;
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
191 }
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
192
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
193 public int poke(int index, byte b[], int offset, int length) {
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
194 return pokeBuffer(index).put(b,offset,length);
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
195 }
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
196
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
197 public void poke(int index, byte b) {
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
198 pokeBuffer(index).put(b);
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
199 }
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
200
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
201
1052
4a2489f1d5fe remove JBuffer.peek()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1051
diff changeset
202 public byte get(int index) {
1046
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
203 return bb.get(index);
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
204 }
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
205
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
206 }