Mercurial Hosting > luan
diff 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 |
line wrap: on
line diff
--- a/src/org/eclipse/jetty/io/BufferUtil.java Sun Nov 06 14:54:43 2016 -0700 +++ b/src/org/eclipse/jetty/io/BufferUtil.java Mon Nov 07 22:39:39 2016 -0700 @@ -18,6 +18,10 @@ package org.eclipse.jetty.io; +import java.nio.ByteBuffer; +import org.eclipse.jetty.io.nio.NIOBuffer; +import org.eclipse.jetty.util.StringUtil; + /* ------------------------------------------------------------------------------- */ /** Buffer utility methods. @@ -273,4 +277,33 @@ buffer.put((byte)10); } + + public static final NIOBuffer EMPTY_BUFFER = new JBuffer(ByteBuffer.allocate(0)); + + public static NIOBuffer wrap(byte[] array,int offset,int length) { + return new JBuffer(ByteBuffer.wrap(array,offset,length)); + } + + public static NIOBuffer wrap(byte[] array) { + return new JBuffer(ByteBuffer.wrap(array)); + } + + public static NIOBuffer wrap(String s) { + byte[] bytes = StringUtil.getBytes(s); + ByteBuffer bb = ByteBuffer.wrap(bytes).asReadOnlyBuffer(); + return new JBuffer(bb); + } + + public static NIOBuffer newBuffer(int size) { + ByteBuffer bb = ByteBuffer.allocate(size); + bb.limit(0); + return new JBuffer(bb); + } + + public static NIOBuffer newDirectBuffer(int size) { + ByteBuffer bb = ByteBuffer.allocateDirect(size); + bb.limit(0); + return new JBuffer(bb); + } + }