本文整理汇总了Java中org.apache.mina.common.ByteBuffer.get方法的典型用法代码示例。如果您正苦于以下问题:Java ByteBuffer.get方法的具体用法?Java ByteBuffer.get怎么用?Java ByteBuffer.get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.mina.common.ByteBuffer
的用法示例。
在下文中一共展示了ByteBuffer.get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: appendDebugInformation
import org.apache.mina.common.ByteBuffer; //导入方法依赖的package包/类
private String appendDebugInformation(ByteBuffer buffer, String text) {
int mark = buffer.position();
try {
StringBuilder sb = new StringBuilder(text);
sb.append("\nBuffer debug info: ").append(getBufferDebugInfo(buffer));
buffer.position(0);
sb.append("\nBuffer contents: ");
try {
final byte[] array = new byte[buffer.limit()];
for(int i = 0; i < array.length; ++i)
array[i] = buffer.get();
sb.append(new String(array, "ISO-8859-1"));
} catch (Exception e) {
sb.append(buffer.getHexDump());
}
text = sb.toString();
} finally {
buffer.position(mark);
}
return text;
}
示例2: startsWith
import org.apache.mina.common.ByteBuffer; //导入方法依赖的package包/类
private static boolean startsWith(ByteBuffer buffer, int bufferOffset, byte[] data) {
try {
if (bufferOffset + data.length > buffer.limit()) {
return false;
}
//StringBuffer sb = new StringBuffer();
for (int dataOffset = 0; dataOffset < data.length && bufferOffset < buffer.limit(); dataOffset++, bufferOffset++) {
byte b = buffer.get(bufferOffset);
if(b == '\r' && dataOffset > 0 && buffer.get(bufferOffset - 1) == '\u0001') {
return true; // EOF io
}
byte bPatern = data[dataOffset];
if (b != bPatern && bPatern != '?') {
return false;
}
}
return true;
} catch (Exception ex) {
ex.printStackTrace();
}
return false;
}
示例3: extractByteMessageContent
import org.apache.mina.common.ByteBuffer; //导入方法依赖的package包/类
/**
* Extract ByteMessage from ByteBuffer
*
* @param wrapMsgContent ByteBuffer which contains data
* @param byteMsgContent byte[] of message content
* @return extracted content as text
*/
private String extractByteMessageContent(ByteBuffer wrapMsgContent, byte[] byteMsgContent) {
String wholeMsg;
if (byteMsgContent == null) {
throw new IllegalArgumentException("byte array must not be null");
}
int count = (wrapMsgContent.remaining() >= byteMsgContent.length ?
byteMsgContent.length :
wrapMsgContent.remaining());
if (count == 0) {
wholeMsg = String.valueOf(-1);
} else {
wrapMsgContent.get(byteMsgContent, 0, count);
wholeMsg = String.valueOf(count);
}
return wholeMsg;
}
示例4: readBooleans
import org.apache.mina.common.ByteBuffer; //导入方法依赖的package包/类
public static boolean[] readBooleans(ByteBuffer buffer)
{
final byte packedValue = buffer.get();
if (packedValue == 0)
{
return ALL_FALSE_ARRAY;
}
final boolean[] result = new boolean[8];
result[0] = ((packedValue & 1) != 0);
result[1] = ((packedValue & (1 << 1)) != 0);
result[2] = ((packedValue & (1 << 2)) != 0);
result[3] = ((packedValue & (1 << 3)) != 0);
if ((packedValue & 0xF0) == 0)
{
result[0] = ((packedValue & 1) != 0);
}
result[4] = ((packedValue & (1 << 4)) != 0);
result[5] = ((packedValue & (1 << 5)) != 0);
result[6] = ((packedValue & (1 << 6)) != 0);
result[7] = ((packedValue & (1 << 7)) != 0);
return result;
}
示例5: readShortString
import org.apache.mina.common.ByteBuffer; //导入方法依赖的package包/类
public static String readShortString(ByteBuffer buffer)
{
short length = buffer.getUnsigned();
if (length == 0)
{
return null;
}
else
{
// this may seem rather odd to declare two array but testing has shown
// that constructing a string from a byte array is 5 (five) times slower
// than constructing one from a char array.
// this approach here is valid since we know that all the chars are
// ASCII (0-127)
byte[] stringBytes = new byte[length];
buffer.get(stringBytes, 0, length);
char[] stringChars = new char[length];
for (int i = 0; i < stringChars.length; i++)
{
stringChars[i] = (char) stringBytes[i];
}
return new String(stringChars);
}
}
示例6: readLongString
import org.apache.mina.common.ByteBuffer; //导入方法依赖的package包/类
public static String readLongString(ByteBuffer buffer)
{
long length = buffer.getUnsignedInt();
if (length == 0)
{
return "";
}
else
{
// this may seem rather odd to declare two array but testing has shown
// that constructing a string from a byte array is 5 (five) times slower
// than constructing one from a char array.
// this approach here is valid since we know that all the chars are
// ASCII (0-127)
byte[] stringBytes = new byte[(int) length];
buffer.get(stringBytes, 0, (int) length);
char[] stringChars = new char[(int) length];
for (int i = 0; i < stringChars.length; i++)
{
stringChars[i] = (char) stringBytes[i];
}
return new String(stringChars);
}
}
示例7: AMQShortString
import org.apache.mina.common.ByteBuffer; //导入方法依赖的package包/类
private AMQShortString(ByteBuffer data, final int length)
{
if (length > MAX_LENGTH)
{
throw new IllegalArgumentException("Cannot create AMQShortString with number of octets over 255!");
}
if(data.isDirect() || data.isReadOnly())
{
byte[] dataBytes = new byte[length];
data.get(dataBytes);
_data = dataBytes;
_offset = 0;
}
else
{
_data = data.array();
_offset = data.arrayOffset() + data.position();
data.skip(length);
}
_length = length;
}
示例8: doDecode
import org.apache.mina.common.ByteBuffer; //导入方法依赖的package包/类
/**
* Delegates decoding AMQP from the data buffer that Mina has retrieved from the wire, to the data or protocol
* intiation decoders.
*
* @param session The Mina session.
* @param in The raw byte buffer.
* @param out The Mina object output gatherer to write decoded objects to.
*
* @return <tt>true</tt> if the data was decoded, <tt>false<tt> if more is needed and the data should accumulate.
*
* @throws Exception If the data cannot be decoded for any reason.
*/
protected boolean doDecode(IoSession session, ByteBuffer in, ProtocolDecoderOutput out) throws Exception
{
boolean decoded;
if (_expectProtocolInitiation
|| (firstDecode
&& (in.remaining() > 0)
&& (in.get(in.position()) == (byte)'A')))
{
decoded = doDecodePI(session, in, out);
}
else
{
decoded = doDecodeDataBlock(session, in, out);
}
if(firstDecode && decoded)
{
firstDecode = false;
}
return decoded;
}
示例9: toString
import org.apache.mina.common.ByteBuffer; //导入方法依赖的package包/类
/**
* Turns a <code>org.apache.mina.common.ByteBuffer</code> into a hexadecimal
* string.
*
* @param buf The <code>org.apache.mina.common.ByteBuffer</code> to convert.
* @return The hexadecimal representation of <code>buf</code>
*/
public static String toString(final ByteBuffer buf) {
buf.flip();
final byte arr[] = new byte[buf.remaining()];
buf.get(arr);
String ret = toString(arr);
buf.flip();
buf.put(arr);
return ret;
}
示例10: doDecode
import org.apache.mina.common.ByteBuffer; //导入方法依赖的package包/类
@Override
protected boolean doDecode(IoSession session, ByteBuffer in, ProtocolDecoderOutput out) throws Exception {
final DecoderState decoderState = (DecoderState) session.getAttribute(DECODER_STATE_KEY);
/* if (decoderState == null) {
decoderState = new DecoderState();
session.setAttribute(DECODER_STATE_KEY, decoderState);
}*/
final MapleClient client = (MapleClient) session.getAttribute(MapleClient.CLIENT_KEY);
if (decoderState != null) {
if (decoderState.packetlength == -1) {
if (in.remaining() >= 4) {
final int packetHeader = in.getInt();
if (!client.getReceiveCrypto().checkPacket(packetHeader)) {
session.close();
return false;
}
decoderState.packetlength = MapleAESOFB.getPacketLength(packetHeader);
} else {
return false;
}
}
if (in.remaining() >= decoderState.packetlength) {
final byte decryptedPacket[] = new byte[decoderState.packetlength];
in.get(decryptedPacket, 0, decoderState.packetlength);
decoderState.packetlength = -1;
client.getReceiveCrypto().crypt(decryptedPacket);
// MapleCustomEncryption.decryptData(decryptedPacket);
out.write(decryptedPacket);
return true;
}
}
return false;
}
示例11: toString
import org.apache.mina.common.ByteBuffer; //导入方法依赖的package包/类
/**
* Turns a {@link org.apache.mina.common.ByteBuffer ByteBuffer}
* into a hexadecimal string.
*
* @param buf The <code>ByteBuffer</code> to convert.
* @return The hexadecimal representation of <code>buf</code>.
*/
public static String toString(final ByteBuffer buf) {
buf.flip();
final byte[] arr = new byte[buf.remaining()];
buf.get(arr);
final String ret = toString(arr);
buf.flip();
buf.put(arr);
return ret;
}
示例12: doDecode
import org.apache.mina.common.ByteBuffer; //导入方法依赖的package包/类
@Override
protected boolean doDecode(final IoSession session, final ByteBuffer in, final ProtocolDecoderOutput out) throws Exception {
final MapleClient client = (MapleClient) session.getAttribute(MapleClient.CLIENT_KEY);
DecoderState decoderState = (DecoderState) session.getAttribute(DECODER_STATE_KEY);
if (decoderState == null) {
decoderState = new DecoderState();
session.setAttribute(DECODER_STATE_KEY, decoderState);
}
if (in.remaining() >= 4 && decoderState.packetlength == -1) {
final int packetHeader = in.getInt();
if (!client.getReceiveCrypto().checkPacket(packetHeader)) {
System.err.println(MapleClient.getLogMessage(client, "Client failed packet check -> disconnecting"));
session.close();
return false;
}
decoderState.packetlength = MapleAESOFB.getPacketLength(packetHeader);
} else if (in.remaining() < 4 && decoderState.packetlength == -1) {
//System.err.println("decode... not enough data");
return false;
}
if (in.remaining() >= decoderState.packetlength) {
final byte[] decryptedPacket = new byte[decoderState.packetlength];
in.get(decryptedPacket, 0, decoderState.packetlength);
decoderState.packetlength = -1;
client.getReceiveCrypto().crypt(decryptedPacket);
MapleCustomEncryption.decryptData(decryptedPacket);
out.write(decryptedPacket);
return true;
} else {
//System.err.println("decode... not enough data to decode (need " + decoderState.packetlength + ")");
return false;
}
}
示例13: toByteArray
import org.apache.mina.common.ByteBuffer; //导入方法依赖的package包/类
@Converter
public static byte[] toByteArray(ByteBuffer buffer) {
buffer.mark();
try {
byte[] answer = new byte[buffer.remaining()];
buffer.get(answer);
return answer;
} finally {
buffer.reset();
}
}
示例14: getDecoder
import org.apache.mina.common.ByteBuffer; //导入方法依赖的package包/类
public ProtocolDecoder getDecoder() throws Exception {
return new CumulativeProtocolDecoder() {
protected boolean doDecode(IoSession session, ByteBuffer in, ProtocolDecoderOutput out) throws Exception {
if (in.remaining() > 0) {
byte[] buf = new byte[in.remaining()];
in.get(buf);
out.write(new String(buf, "US-ASCII"));
return true;
} else {
return false;
}
}
};
}
示例15: indexOf
import org.apache.mina.common.ByteBuffer; //导入方法依赖的package包/类
private static int indexOf(ByteBuffer buffer, int position, byte[] data) {
for (int offset = position, limit = buffer.limit() - data.length + 1; offset < limit; offset++) {
if (buffer.get(offset) == data[0] && startsWith(buffer, offset, data)) {
return offset;
}
}
return -1;
}