本文整理汇总了Java中org.apache.mina.common.ByteBuffer.getInt方法的典型用法代码示例。如果您正苦于以下问题:Java ByteBuffer.getInt方法的具体用法?Java ByteBuffer.getInt怎么用?Java ByteBuffer.getInt使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.mina.common.ByteBuffer
的用法示例。
在下文中一共展示了ByteBuffer.getInt方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
示例2: 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;
}
}
示例3: 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.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); // removed in v149.2
out.write(decryptedPacket);
return true;
}
return false;
}
示例4: doDecode
import org.apache.mina.common.ByteBuffer; //导入方法依赖的package包/类
@Override
protected boolean doDecode(IoSession session, ByteBuffer in, ProtocolDecoderOutput out)
throws Exception {
final int origonPos = in.position();
final int packetLength = in.remaining();
if(packetLength<PROTOCOL_HEADER_LENGTH){
in.position(origonPos);
return false;
}
int flag = in.getInt();
int chid = in.getInt();
int pcode = in.getInt();
int len = in.getInt();
if (flag != TairConstant.TAIR_PACKET_FLAG)
throw new IOException("flag error, except: " + TairConstant.TAIR_PACKET_FLAG + ", but get " + flag);
if (in.remaining() < len) {
in.position(origonPos);
return false;
}
if(isDebugEnabled){
final String remoteIP = ((InetSocketAddress) session.getRemoteAddress()).toString();
StringBuilder receiveTimeInfo = new StringBuilder();
receiveTimeInfo.append("receive response from [").append(remoteIP).append("],time is: ");
receiveTimeInfo.append(System.currentTimeMillis());
receiveTimeInfo.append(", channel id: ").append(chid);
LOGGER.debug(receiveTimeInfo.toString());
}
byte[] data = new byte[len];
in.get(data);
if (isDebugEnabled)
LOGGER.debug(TairUtil.toHex(data));
BasePacket returnPacket = pstreamer.decodePacket(pcode, data);
TairResponse response=new TairResponse();
response.setRequestId(chid);
response.setResponse(returnPacket);
out.write(response);
return true;
}
示例5: readObject
import org.apache.mina.common.ByteBuffer; //导入方法依赖的package包/类
/**
* Read object from StreamMessage ByteBuffer content
*
* @param wrapMsgContent ByteBuffer which contains data
* @param encoding message encoding
* @return Object extracted from ByteBuffer
* @throws JMSException
* @throws CharacterCodingException
*/
private Object readObject(ByteBuffer wrapMsgContent, String encoding)
throws JMSException, CharacterCodingException {
int position = wrapMsgContent.position();
checkAvailable(1, wrapMsgContent);
byte wireType = wrapMsgContent.get();
Object result = null;
try {
switch (wireType) {
case BOOLEAN_TYPE:
checkAvailable(1, wrapMsgContent);
result = wrapMsgContent.get() != 0;
break;
case BYTE_TYPE:
checkAvailable(1, wrapMsgContent);
result = wrapMsgContent.get();
break;
case BYTEARRAY_TYPE:
checkAvailable(4, wrapMsgContent);
int size = wrapMsgContent.getInt();
if (size == -1) {
result = null;
} else {
byteArrayRemaining = size;
byte[] bytesResult = new byte[size];
readBytesImpl(wrapMsgContent, bytesResult);
result = bytesResult;
}
break;
case SHORT_TYPE:
checkAvailable(2, wrapMsgContent);
result = wrapMsgContent.getShort();
break;
case CHAR_TYPE:
checkAvailable(2, wrapMsgContent);
result = wrapMsgContent.getChar();
break;
case INT_TYPE:
checkAvailable(4, wrapMsgContent);
result = wrapMsgContent.getInt();
break;
case LONG_TYPE:
checkAvailable(8, wrapMsgContent);
result = wrapMsgContent.getLong();
break;
case FLOAT_TYPE:
checkAvailable(4, wrapMsgContent);
result = wrapMsgContent.getFloat();
break;
case DOUBLE_TYPE:
checkAvailable(8, wrapMsgContent);
result = wrapMsgContent.getDouble();
break;
case NULL_STRING_TYPE:
result = null;
break;
case STRING_TYPE:
checkAvailable(1, wrapMsgContent);
result = wrapMsgContent.getString(Charset.forName(encoding).newDecoder());
break;
}
return result;
} catch (RuntimeException e) {
wrapMsgContent.position(position);
throw e;
}
}
示例6: readInt
import org.apache.mina.common.ByteBuffer; //导入方法依赖的package包/类
protected int readInt(ByteBuffer buffer)
{
return buffer.getInt();
}
示例7: readInteger
import org.apache.mina.common.ByteBuffer; //导入方法依赖的package包/类
public static int readInteger(ByteBuffer buffer)
{
return buffer.getInt();
}