comparison src/org/eclipse/jetty/io/BufferUtil.java @ 1046:a8c92b0a08ed

add JBuffer
author Franklin Schmidt <fschmidt@gmail.com>
date Mon, 07 Nov 2016 22:39:39 -0700
parents e350c11242be
children 2b769da7f67d
comparison
equal deleted inserted replaced
1045:48506d03e230 1046:a8c92b0a08ed
15 // You may elect to redistribute this code under either of these licenses. 15 // You may elect to redistribute this code under either of these licenses.
16 // ======================================================================== 16 // ========================================================================
17 // 17 //
18 18
19 package org.eclipse.jetty.io; 19 package org.eclipse.jetty.io;
20
21 import java.nio.ByteBuffer;
22 import org.eclipse.jetty.io.nio.NIOBuffer;
23 import org.eclipse.jetty.util.StringUtil;
20 24
21 25
22 /* ------------------------------------------------------------------------------- */ 26 /* ------------------------------------------------------------------------------- */
23 /** Buffer utility methods. 27 /** Buffer utility methods.
24 * 28 *
271 { 275 {
272 buffer.put((byte)13); 276 buffer.put((byte)13);
273 buffer.put((byte)10); 277 buffer.put((byte)10);
274 } 278 }
275 279
280
281 public static final NIOBuffer EMPTY_BUFFER = new JBuffer(ByteBuffer.allocate(0));
282
283 public static NIOBuffer wrap(byte[] array,int offset,int length) {
284 return new JBuffer(ByteBuffer.wrap(array,offset,length));
285 }
286
287 public static NIOBuffer wrap(byte[] array) {
288 return new JBuffer(ByteBuffer.wrap(array));
289 }
290
291 public static NIOBuffer wrap(String s) {
292 byte[] bytes = StringUtil.getBytes(s);
293 ByteBuffer bb = ByteBuffer.wrap(bytes).asReadOnlyBuffer();
294 return new JBuffer(bb);
295 }
296
297 public static NIOBuffer newBuffer(int size) {
298 ByteBuffer bb = ByteBuffer.allocate(size);
299 bb.limit(0);
300 return new JBuffer(bb);
301 }
302
303 public static NIOBuffer newDirectBuffer(int size) {
304 ByteBuffer bb = ByteBuffer.allocateDirect(size);
305 bb.limit(0);
306 return new JBuffer(bb);
307 }
308
276 } 309 }