本文整理匯總了Java中org.apache.mina.core.buffer.IoBuffer.get方法的典型用法代碼示例。如果您正苦於以下問題:Java IoBuffer.get方法的具體用法?Java IoBuffer.get怎麽用?Java IoBuffer.get使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.mina.core.buffer.IoBuffer
的用法示例。
在下文中一共展示了IoBuffer.get方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: decode
import org.apache.mina.core.buffer.IoBuffer; //導入方法依賴的package包/類
/**
* {@inheritDoc}
*/
public DecodingState decode(IoBuffer in, ProtocolDecoderOutput out) throws Exception {
int beginPos = in.position();
int limit = in.limit();
for (int i = beginPos; i < limit; i++) {
byte b = in.get(i);
if (!canSkip(b)) {
in.position(i);
int answer = this.skippedBytes;
this.skippedBytes = 0;
return finishDecode(answer);
}
skippedBytes++;
}
in.position(limit);
return this;
}
示例2: handleData
import org.apache.mina.core.buffer.IoBuffer; //導入方法依賴的package包/類
@Override
public void handleData ( final IoBuffer data, final Map<String, Variant> attributes, final Variant timestamp )
{
final byte b = data.get ( toAddress ( this.readIndex ) );
final boolean flag = ( b & 1 << this.readSubIndex ) != 0;
if ( this.invertRead )
{
attributes.put ( this.name, flag ? Variant.FALSE : Variant.TRUE );
}
else
{
attributes.put ( this.name, flag ? Variant.TRUE : Variant.FALSE );
}
if ( !Boolean.valueOf ( flag ).equals ( this.lastValue ) )
{
this.lastValue = flag;
this.lastTimestamp = timestamp;
}
if ( this.enableTimestamp )
{
attributes.put ( this.name + ".timestamp", this.lastTimestamp );
}
}
示例3: readBytesArrayWithPrefix
import org.apache.mina.core.buffer.IoBuffer; //導入方法依賴的package包/類
/**
* Read a set of bytes with the first byte being the number of bytes to read
*
* @param buffer
* the buffer to read from
* @return the result read
*/
private static byte[] readBytesArrayWithPrefix ( final IoBuffer buffer )
{
final short numOfBytes = buffer.getUnsigned ();
logger.trace ( "Prepare to read {} bytes", numOfBytes );
final byte[] result = new byte[numOfBytes];
buffer.get ( result, 0, numOfBytes );
return result;
}
示例4: decodeResponseData
import org.apache.mina.core.buffer.IoBuffer; //導入方法依賴的package包/類
private void decodeResponseData ( final IoBuffer data, final ProtocolDecoderOutput output, final int sequence ) throws ProtocolCodecException
{
final byte nin = data.get ();
final Object[] vars = new Object[nin];
for ( int i = 0; i < nin; i++ )
{
vars[i] = decodeData ( data );
}
final DataMessage msg = new DataMessage ( sequence, CommandCode.RESPOND_DATA, vars );
output.write ( msg );
}
示例5: decodeMessage
import org.apache.mina.core.buffer.IoBuffer; //導入方法依賴的package包/類
@Override
public org.eclipse.scada.ae.data.message.StartBrowse decodeMessage ( final BinaryContext _context, final IoBuffer _data ) throws Exception
{
// message code
{
final int messageCode = _data.getInt ();
if ( messageCode != MESSAGE_CODE )
{
throw new IllegalStateException ( String.format ( "Expected messageCode %s but found %s", MESSAGE_CODE, messageCode ) );
}
}
final byte numberOfFields = _data.get ();
// decode attributes
logger.trace ( "Decoding {} fields", numberOfFields );
for ( int i = 0; i < numberOfFields; i++ )
{
final byte fieldNumber = _data.get ();
switch ( fieldNumber )
{
default:
logger.warn ( "Received unknown field number: {}", fieldNumber );
break;
}
}
// create object
return new org.eclipse.scada.ae.data.message.StartBrowse ();
}
示例6: decode
import org.apache.mina.core.buffer.IoBuffer; //導入方法依賴的package包/類
/**
* {@inheritDoc}
*/
public DecodingState decode(IoBuffer in, ProtocolDecoderOutput out) throws Exception {
boolean found = false;
boolean finished = false;
while (in.hasRemaining()) {
byte b = in.get();
if (!hasCR) {
if (b == CR) {
hasCR = true;
} else {
if (b == LF) {
found = true;
} else {
in.position(in.position() - 1);
found = false;
}
finished = true;
break;
}
} else {
if (b == LF) {
found = true;
finished = true;
break;
}
throw new ProtocolDecoderException("Expected LF after CR but was: " + (b & 0xff));
}
}
if (finished) {
hasCR = false;
return finishDecode(found, out);
}
return this;
}
示例7: isCloseNotify
import org.apache.mina.core.buffer.IoBuffer; //導入方法依賴的package包/類
private boolean isCloseNotify(Object message) {
if (!(message instanceof IoBuffer)) {
return false;
}
IoBuffer buf = (IoBuffer) message;
int offset = buf.position();
return (buf.get(offset + 0) == 0x15) /* Alert */
&& (buf.get(offset + 1) == 0x03) /* TLS/SSL */
&& ((buf.get(offset + 2) == 0x00) /* SSL 3.0 */
|| (buf.get(offset + 2) == 0x01) /* TLS 1.0 */
|| (buf.get(offset + 2) == 0x02) /* TLS 1.1 */
|| (buf.get(offset + 2) == 0x03)) /* TLS 1.2 */
&& (buf.get(offset + 3) == 0x00); /* close_notify */
}
示例8: inlindeDecodeValueEntry
import org.apache.mina.core.buffer.IoBuffer; //導入方法依賴的package包/類
protected static org.eclipse.scada.hd.data.ValueEntry inlindeDecodeValueEntry ( final BinaryContext _context, final IoBuffer _data ) throws Exception
{
// number of fields
final byte numberOfFields = _data.get ();
// decode attributes
String valueType = null;
java.util.List<Double> values = null;
logger.trace ( "Decoding {} fields", numberOfFields );
for ( int i = 0; i < numberOfFields; i++ )
{
final byte fieldNumber = _data.get ();
switch ( fieldNumber )
{
case 1:
{
valueType = _context.decodeString ( _data );
}
break;
case 2:
{
values = _context.decodeDoubleList ( _data );
}
break;
default:
logger.warn ( "Received unknown field number: {}", fieldNumber );
break;
}
}
// create object
return new org.eclipse.scada.hd.data.ValueEntry ( valueType, values );
}
示例9: decodeMessage
import org.apache.mina.core.buffer.IoBuffer; //導入方法依賴的package包/類
@Override
public org.eclipse.scada.ae.data.message.SubscribeMonitorPool decodeMessage ( final BinaryContext _context, final IoBuffer _data ) throws Exception
{
// message code
{
final int messageCode = _data.getInt ();
if ( messageCode != MESSAGE_CODE )
{
throw new IllegalStateException ( String.format ( "Expected messageCode %s but found %s", MESSAGE_CODE, messageCode ) );
}
}
final byte numberOfFields = _data.get ();
// decode attributes
String monitorPoolId = null;
logger.trace ( "Decoding {} fields", numberOfFields );
for ( int i = 0; i < numberOfFields; i++ )
{
final byte fieldNumber = _data.get ();
switch ( fieldNumber )
{
case 1:
{
monitorPoolId = _context.decodeString ( _data );
}
break;
default:
logger.warn ( "Received unknown field number: {}", fieldNumber );
break;
}
}
// create object
return new org.eclipse.scada.ae.data.message.SubscribeMonitorPool ( monitorPoolId );
}
示例10: decodeMessage
import org.apache.mina.core.buffer.IoBuffer; //導入方法依賴的package包/類
@Override
public org.eclipse.scada.ca.data.message.GetConfigurationRequest decodeMessage ( final BinaryContext _context, final IoBuffer _data ) throws Exception
{
// message code
{
final int messageCode = _data.getInt ();
if ( messageCode != MESSAGE_CODE )
{
throw new IllegalStateException ( String.format ( "Expected messageCode %s but found %s", MESSAGE_CODE, messageCode ) );
}
}
final byte numberOfFields = _data.get ();
// decode attributes
org.eclipse.scada.core.data.Request request = null;
String factoryId = null;
String configurationId = null;
logger.trace ( "Decoding {} fields", numberOfFields );
for ( int i = 0; i < numberOfFields; i++ )
{
final byte fieldNumber = _data.get ();
switch ( fieldNumber )
{
case 1:
{
request = org.eclipse.scada.core.protocol.ngp.codec.Structures.decodeRequest ( _context, _data, false );
}
break;
case 2:
{
factoryId = _context.decodeString ( _data );
}
break;
case 3:
{
configurationId = _context.decodeString ( _data );
}
break;
default:
logger.warn ( "Received unknown field number: {}", fieldNumber );
break;
}
}
// create object
return new org.eclipse.scada.ca.data.message.GetConfigurationRequest ( request, factoryId, configurationId );
}
示例11: decodeMessage
import org.apache.mina.core.buffer.IoBuffer; //導入方法依賴的package包/類
@Override
public org.eclipse.scada.ca.data.message.ErrorResponse decodeMessage ( final BinaryContext _context, final IoBuffer _data ) throws Exception
{
// message code
{
final int messageCode = _data.getInt ();
if ( messageCode != MESSAGE_CODE )
{
throw new IllegalStateException ( String.format ( "Expected messageCode %s but found %s", MESSAGE_CODE, messageCode ) );
}
}
final byte numberOfFields = _data.get ();
// decode attributes
org.eclipse.scada.core.data.Response response = null;
org.eclipse.scada.core.data.ErrorInformation errorInformation = null;
logger.trace ( "Decoding {} fields", numberOfFields );
for ( int i = 0; i < numberOfFields; i++ )
{
final byte fieldNumber = _data.get ();
switch ( fieldNumber )
{
case 1:
{
response = org.eclipse.scada.core.protocol.ngp.codec.Structures.decodeResponse ( _context, _data, false );
}
break;
case 2:
{
errorInformation = org.eclipse.scada.core.protocol.ngp.codec.Structures.decodeErrorInformation ( _context, _data, false );
}
break;
default:
logger.warn ( "Received unknown field number: {}", fieldNumber );
break;
}
}
// create object
return new org.eclipse.scada.ca.data.message.ErrorResponse ( response, errorInformation );
}
示例12: decodeMessage
import org.apache.mina.core.buffer.IoBuffer; //導入方法依賴的package包/類
@Override
public org.eclipse.scada.core.data.message.SessionRejected decodeMessage ( final BinaryContext _context, final IoBuffer _data ) throws Exception
{
// message code
{
final int messageCode = _data.getInt ();
if ( messageCode != MESSAGE_CODE )
{
throw new IllegalStateException ( String.format ( "Expected messageCode %s but found %s", MESSAGE_CODE, messageCode ) );
}
}
final byte numberOfFields = _data.get ();
// decode attributes
String errorReason = null;
logger.trace ( "Decoding {} fields", numberOfFields );
for ( int i = 0; i < numberOfFields; i++ )
{
final byte fieldNumber = _data.get ();
switch ( fieldNumber )
{
case 1:
{
errorReason = _context.decodeString ( _data );
}
break;
default:
logger.warn ( "Received unknown field number: {}", fieldNumber );
break;
}
}
// create object
return new org.eclipse.scada.core.data.message.SessionRejected ( errorReason );
}
示例13: decodeMessage
import org.apache.mina.core.buffer.IoBuffer; //導入方法依賴的package包/類
@Override
public org.eclipse.scada.core.data.message.SessionAccepted decodeMessage ( final BinaryContext _context, final IoBuffer _data ) throws Exception
{
// message code
{
final int messageCode = _data.getInt ();
if ( messageCode != MESSAGE_CODE )
{
throw new IllegalStateException ( String.format ( "Expected messageCode %s but found %s", MESSAGE_CODE, messageCode ) );
}
}
final byte numberOfFields = _data.get ();
// decode attributes
java.util.Map<String, String> properties = null;
logger.trace ( "Decoding {} fields", numberOfFields );
for ( int i = 0; i < numberOfFields; i++ )
{
final byte fieldNumber = _data.get ();
switch ( fieldNumber )
{
case 1:
{
properties = _context.decodeProperties ( _data );
}
break;
default:
logger.warn ( "Received unknown field number: {}", fieldNumber );
break;
}
}
// create object
return new org.eclipse.scada.core.data.message.SessionAccepted ( properties );
}
示例14: decode
import org.apache.mina.core.buffer.IoBuffer; //導入方法依賴的package包/類
@Override
public MessageDecoderResult decode(IoSession session, IoBuffer buf, ProtocolDecoderOutput out) throws Exception {
CjyTcpMessage message = new CjyTcpMessage();
logger.info("收到采集儀消息" + buf.getHexDump());
buf.mark();
//幀起始符 0x68
buf.get();
// 獲取設備編碼
int address_i = buf.getInt();
message.setAddress(CommUtils.highAndLowAddressSwap(address_i));
//幀起始符 0x16
if ( buf.get() != 0x68){
return null;
}
//控製碼
byte control = buf.get();
message.setD7(control >> 7);
message.setD6(control >> 6);
//控製碼 , 協議簇
message.setCmd(control&0x0f);
//數據體長度
int length = buf.get();
message.setLength(length);
//數據體
byte[] data = MessageUtil.getBytes(buf, length);
message.setData(data);
//CRC
byte crc = (buf.get());
//結束標誌
int finished = buf.get();
if ( finished != 0x16 ){
return MessageDecoderResult.NOT_OK;
}
buf.reset();
//獲取校驗位前字節
byte[] cpData = MessageUtil.getBytes(buf, 8 + length);
int t = 0;
for( int i =0; i< cpData.length; i ++){
t += cpData[i];
}
int crc_cal = (t%256) ;
logger.info("獲取的CRC值" + (crc & 0xFF) + ",計算的crc值:" + crc_cal + ",address:" + message.getAddress());
//如果校驗碼校驗不通過,則為無效消息
if ( (crc & 0xFF) != (crc_cal & 0xFF)){
return MessageDecoderResult.NOT_OK;
}
buf.get();
buf.get();
out.write(message);
return MessageDecoderResult.OK;
}
示例15: decodeMessage
import org.apache.mina.core.buffer.IoBuffer; //導入方法依賴的package包/類
@Override
public org.eclipse.scada.core.data.message.RespondCallbacks decodeMessage ( final BinaryContext _context, final IoBuffer _data ) throws Exception
{
// message code
{
final int messageCode = _data.getInt ();
if ( messageCode != MESSAGE_CODE )
{
throw new IllegalStateException ( String.format ( "Expected messageCode %s but found %s", MESSAGE_CODE, messageCode ) );
}
}
final byte numberOfFields = _data.get ();
// decode attributes
org.eclipse.scada.core.data.Response response = null;
java.util.List<org.eclipse.scada.core.data.CallbackResponse> callbacks = null;
org.eclipse.scada.core.data.ErrorInformation errorInformation = null;
logger.trace ( "Decoding {} fields", numberOfFields );
for ( int i = 0; i < numberOfFields; i++ )
{
final byte fieldNumber = _data.get ();
switch ( fieldNumber )
{
case 1:
{
response = org.eclipse.scada.core.protocol.ngp.codec.Structures.decodeResponse ( _context, _data, false );
}
break;
case 2:
{
callbacks = org.eclipse.scada.core.protocol.ngp.codec.Structures.decodeListCallbackResponse ( _context, _data, true );
}
break;
case 3:
{
errorInformation = org.eclipse.scada.core.protocol.ngp.codec.Structures.decodeErrorInformation ( _context, _data, true );
}
break;
default:
logger.warn ( "Received unknown field number: {}", fieldNumber );
break;
}
}
// create object
return new org.eclipse.scada.core.data.message.RespondCallbacks ( response, callbacks, errorInformation );
}