comparison src/org/eclipse/jetty/io/JBuffer.java @ 1064:a0abb16cf6e7

remove JBuffer.readFrom()
author Franklin Schmidt <fschmidt@gmail.com>
date Wed, 09 Nov 2016 03:09:37 -0700
parents 0157e92670f5
children 158d1e6ac17f
comparison
equal deleted inserted replaced
1063:0157e92670f5 1064:a0abb16cf6e7
3 package org.eclipse.jetty.io; 3 package org.eclipse.jetty.io;
4 4
5 import java.io.InputStream; 5 import java.io.InputStream;
6 import java.io.IOException; 6 import java.io.IOException;
7 import java.nio.ByteBuffer; 7 import java.nio.ByteBuffer;
8 import java.nio.channels.Channels;
9 import java.nio.channels.ReadableByteChannel;
10 import org.slf4j.Logger; 8 import org.slf4j.Logger;
11 import org.slf4j.LoggerFactory; 9 import org.slf4j.LoggerFactory;
12 import org.eclipse.jetty.util.TypeUtil; 10 import org.eclipse.jetty.util.TypeUtil;
13 11
14 12
142 public void skip(int n) { 140 public void skip(int n) {
143 if (remaining() < n) n = remaining(); 141 if (remaining() < n) n = remaining();
144 bb.position(bb.position() + n); 142 bb.position(bb.position() + n);
145 } 143 }
146 144
147 public int readFrom(InputStream in,int max) throws IOException {
148 ByteBuffer dup = bb.duplicate();
149 int put = bb.limit();
150 dup.limit( Math.min(put+max,bb.capacity()) );
151 dup.position(put);
152
153 ReadableByteChannel chan = Channels.newChannel(in);
154 int n = chan.read(dup);
155
156 if( n > 0 )
157 bb.limit(put+n);
158 return n;
159 }
160
161 private final byte[] asArray() { 145 private final byte[] asArray() {
162 byte[] bytes = new byte[remaining()]; 146 byte[] bytes = new byte[remaining()];
163 bb.duplicate().get(bytes); 147 bb.duplicate().get(bytes);
164 return bytes; 148 return bytes;
165 } 149 }
166 150 /*
167 @Override 151 @Override
168 public String toString() { 152 public String toString() {
169 // return toString("ISO-8859-1"); 153 // return toString("ISO-8859-1");
170 // Thread.dumpStack(); 154 // Thread.dumpStack();
171 throw new RuntimeException("toString"); 155 throw new RuntimeException("toString");
172 } 156 }
173 157 */
174 158
175 public byte get(int index) { 159 public byte get(int index) {
176 return bb.get(index); 160 return bb.get(index);
177 } 161 }
178 162