public class ByteBufferUtil extends Object
Messaging Framework では、先頭部分に補助情報を付与することを行う。 このため、ByteBufferを割り当てる際には、先頭部分に空きを設けて、途中の offsetから使用することを行う。
ByteBuffer では、position=0 が先頭バイトとなることを仮定してメソッドが 用意されている。(例:clear(), flip(), rewind()) ここでは、先頭バイトを指すindexとしてmarkを使用する。既存のメソッドに 代わるものとして、positionを0にする代わりに、mark値にセットする、 clear(), flip(), rewind(), flop() を用意する。
read状態は次のような状態である。ここで、+ は読み込むべきデータ。mはmark, pはposition, lはlimit [---m=p++++++l----] この状態にするために、flipを用いる。再読み込みするためには、rewindを用いる。 write状態は次のような状態である。 [---m++++++p----l] この状態にするために、flopを用いる。
| コンストラクタと説明 |
|---|
ByteBufferUtil() |
| 修飾子とタイプ | メソッドと説明 |
|---|---|
static byte[] |
buffer2Bytes(ByteBuffer bbuf)
ByteBufferのpositionからlimitで指定されたbyte列を新規のbyte配列として返す。
|
static ByteBuffer |
byte2Buffer(byte[] data)
指定されたbyte列を値として持つByteBufferを生成する。
|
static ByteBuffer |
byte2Buffer(byte[] buf,
int offset,
int len)
指定されたbyte列を値として持つByteBufferを生成する。
|
static ByteBuffer |
byte2Buffer(int margin,
byte[] buf,
int offset,
int len) |
static void |
clear(ByteBuffer b)
指定されたByteBufferをclearする。
|
static ByteBuffer |
concat(byte[] pre,
ByteBuffer bbuf)
bbufの持つbyte列の先頭にpreで指定されたbyte列を結合する。
|
static ByteBuffer |
concat(ByteBuffer pre,
ByteBuffer bbuf)
bbufの持つbyte列の先頭にpreで指定されたByteBufferを結合する。
|
static void |
copy2Buffer(byte[] src,
int srcOff,
int srcLen,
ByteBuffer dst,
int dstOff)
指定されたbyte列を指定されたByteBufferの指定位置にコピーする。
|
static ByteBuffer |
enhance(ByteBuffer bbuf,
int size)
ByteBufferのbodyをsizeのbyte分だけ拡張する。
|
static ByteBuffer |
enhance(int size,
ByteBuffer bbuf)
ByteBufferのヘッダマージンをsizeのbyte分だけ拡張する。
|
static void |
flip(ByteBuffer b)
指定されたByteBufferを反転する。
|
static void |
flop(ByteBuffer b)
read状態から再びデータをputする状態に変える。
|
static void |
mark(ByteBuffer b)
指定されたByteBufferの先頭マークを設定する。
|
static ByteBuffer |
newByteBuffer(int capacity)
指定された容量capacityを持つByteBufferを生成する。
|
static ByteBuffer |
newByteBuffer(int margin,
int capacity)
指定されたmarginと容量capacityを持つByteBufferを生成する。
|
static ByteBuffer |
put(ByteBuffer bbuf,
byte[] post)
bbufにpostで指定されたbyte列を追加する。
|
static ByteBuffer |
put(ByteBuffer bbuf,
ByteBuffer post)
bbufにpostで指定されたByteBufferを追加する。
|
static ByteBuffer |
reserve(int preLen,
ByteBuffer bbuf)
bbufの持つbyte列の前方にpreLenで指定されたbyte長だけ領域確保する。
|
static void |
reset(int offset,
ByteBuffer b)
指定されたByteBufferの先頭をoffsetとしてresetする。
|
static void |
rewind(ByteBuffer b)
指定されたByteBufferを巻き戻す。
|
static boolean |
startsWith(byte[] prefix,
ByteBuffer bbuf)
bbufの持つbyte列の先頭が、prefixと等しいか判定する。
|
static void |
strip(int preLen,
ByteBuffer bbuf)
bbufの持つbyte列から先頭部preLen分のbyte列を削る。
|
public static void clear(ByteBuffer b)
b - 対象となるByteBufferInvalidMarkException - markがセットされてなかった場合public static void flip(ByteBuffer b)
b - 対象となるByteBufferInvalidMarkException - markがセットされてなかった場合public static void rewind(ByteBuffer b)
b - 対象となるByteBufferInvalidMarkException - markがセットされてなかった場合public static void flop(ByteBuffer b)
b - 対象となるByteBufferpublic static void mark(ByteBuffer b)
b - 対象となるByteBufferpublic static void reset(int offset,
ByteBuffer b)
offset - reset時のoffset値b - 対象となるByteBufferpublic static ByteBuffer newByteBuffer(int margin, int capacity)
margin - 先頭部の余白capacity - 容量public static ByteBuffer newByteBuffer(int capacity)
capacity - 容量public static void copy2Buffer(byte[] src,
int srcOff,
int srcLen,
ByteBuffer dst,
int dstOff)
src - コピー元のbyte配列srcOff - コピー元となるbyte配列のoffsetsrcLen - コピー元となるbyte列の長さdst - コピー先のByteBufferdstOff - コピー先のoffsetBufferOverflowException - ByteBuffer内に残っている容量が不足している場合IndexOutOfBoundsException - srcOffとsrcLengthパラメータの前提条件が満たされていない場合public static ByteBuffer byte2Buffer(int margin, byte[] buf, int offset, int len)
public static ByteBuffer byte2Buffer(byte[] data)
data - byte列全体を格納するbyte配列public static ByteBuffer byte2Buffer(byte[] buf, int offset, int len)
buf - byte列を格納するbyte配列offset - 格納するbyte列の先頭を示すoffsetlen - 格納するbyte列の長さpublic static byte[] buffer2Bytes(ByteBuffer bbuf)
bbuf - 対象となるByteBufferpublic static ByteBuffer enhance(int size, ByteBuffer bbuf)
size - 拡張するbyte数bbuf - 対象となるByteBufferpublic static ByteBuffer enhance(ByteBuffer bbuf, int size)
bbuf - 対象となるByteBuffersize - 拡張するbyte数public static ByteBuffer reserve(int preLen, ByteBuffer bbuf)
preLen - 前方に確保する領域のbyte長bbuf - 対象となるByteBufferpublic static ByteBuffer concat(byte[] pre, ByteBuffer bbuf)
pre - 先頭に結合するbyte列bbuf - 対象となるByteBufferpublic static ByteBuffer concat(ByteBuffer pre, ByteBuffer bbuf)
pre - 先頭に結合するByteBufferbbuf - 対象となるByteBufferpublic static ByteBuffer put(ByteBuffer bbuf, byte[] post)
bbuf - ByteBufferpost - 追加するbyte列public static ByteBuffer put(ByteBuffer bbuf, ByteBuffer post)
bbuf - ByteBufferpost - 追加するByteBufferpublic static void strip(int preLen,
ByteBuffer bbuf)
preLen - 先頭部から削るbyte数bbuf - 対象となるByteBufferIllegalArgumentException - 保持するbyte列より削るbyte数が同じであるか大きい場合public static boolean startsWith(byte[] prefix,
ByteBuffer bbuf)
prefix - 比較するbyte列bbuf - 対象となるByteBufferCopyright © 2017. All rights reserved.