當前位置: 首頁>>代碼示例>>Java>>正文


Java IoBuffer.setAutoExpand方法代碼示例

本文整理匯總了Java中org.apache.mina.core.buffer.IoBuffer.setAutoExpand方法的典型用法代碼示例。如果您正苦於以下問題:Java IoBuffer.setAutoExpand方法的具體用法?Java IoBuffer.setAutoExpand怎麽用?Java IoBuffer.setAutoExpand使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.mina.core.buffer.IoBuffer的用法示例。


在下文中一共展示了IoBuffer.setAutoExpand方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: encode

import org.apache.mina.core.buffer.IoBuffer; //導入方法依賴的package包/類
@Override
public void encode ( final IoSession session, final Object message, final ProtocolEncoderOutput output ) throws Exception
{
    final IoBuffer data = IoBuffer.allocate ( 0 );
    data.order ( ByteOrder.LITTLE_ENDIAN );
    data.setAutoExpand ( true );

    if ( message instanceof WriteRequestMessage )
    {
        encodeHeader ( data, (CommonMessage)message );
        encodeWriteRequest ( data, (WriteRequestMessage)message );
    }
    else if ( message instanceof CommonMessage )
    {
        encodeHeader ( data, (CommonMessage)message );
    }
    data.flip ();
    output.write ( data );
}
 
開發者ID:eclipse,項目名稱:neoscada,代碼行數:20,代碼來源:ArduinoCodec.java

示例2: encodeMessage

import org.apache.mina.core.buffer.IoBuffer; //導入方法依賴的package包/類
@Override
public DataMessage encodeMessage ( final Object message ) throws Exception
{
    if ( ! ( message instanceof Serializable ) )
    {
        if ( message != null )
        {
            throw new NotSerializableException ( message.getClass ().getName () );
        }
        else
        {
            throw new NotSerializableException ();
        }
    }

    final IoBuffer data = IoBuffer.allocate ( 64 );
    data.setAutoExpand ( true );
    data.putObject ( message );
    data.flip ();
    return new DataMessage ( data );
}
 
開發者ID:eclipse,項目名稱:neoscada,代碼行數:22,代碼來源:ObjectSerializationProtocol.java

示例3: encodeProperties

import org.apache.mina.core.buffer.IoBuffer; //導入方法依賴的package包/類
private IoBuffer encodeProperties ( final IoSession session, final Map<String, String> properties ) throws CharacterCodingException
{
    final IoBuffer data = IoBuffer.allocate ( 0 );
    data.setAutoExpand ( true );

    data.putInt ( properties.size () );

    final CharsetEncoder encoder = getCharsetEncoder ( session );

    for ( final Map.Entry<String, String> entry : properties.entrySet () )
    {
        final String key = entry.getKey ();
        final String value = entry.getValue ();

        data.putString ( key, encoder );
        data.put ( (byte)0x00 );
        data.putString ( value, encoder );
        data.put ( (byte)0x00 );
    }

    data.flip ();

    return data;
}
 
開發者ID:eclipse,項目名稱:neoscada,代碼行數:25,代碼來源:MessageChannelCodecFilter.java

示例4: sessionOpened

import org.apache.mina.core.buffer.IoBuffer; //導入方法依賴的package包/類
@Override
public void sessionOpened ( final NextFilter nextFilter, final IoSession session ) throws Exception
{
    logger.debug ( "Session opened: {}", session );

    final IoBuffer buffer = IoBuffer.allocate ( 1 );
    buffer.setAutoExpand ( true );

    buffer.put ( new byte[] { 0x11, (byte)0xE0, 0x00, 0x00, 0x00, 0x01, 0x00, (byte)0xC1, 2, 1, 0, (byte)0xC2, 2, 0, 1, (byte)0xC0, 1, 9 } );

    buffer.put ( 13, (byte) ( this.rack + 1 ) );
    buffer.put ( 14, this.slot );

    buffer.flip ();

    session.write ( buffer );
}
 
開發者ID:eclipse,項目名稱:neoscada,代碼行數:18,代碼來源:COTPFilter.java

示例5: encode

import org.apache.mina.core.buffer.IoBuffer; //導入方法依賴的package包/類
public void encode(IoSession session, Object message, ProtocolEncoderOutput out) throws Exception {
    if (!(message instanceof Serializable)) {
        throw new NotSerializableException();
    }

    IoBuffer buf = IoBuffer.allocate(64);
    buf.setAutoExpand(true);
    buf.putObject(message);

    int objectSize = buf.position() - 4;
    if (objectSize > maxObjectSize) {
        throw new IllegalArgumentException("The encoded object is too big: " + objectSize + " (> " + maxObjectSize
                + ')');
    }

    buf.flip();
    out.write(buf);
}
 
開發者ID:eclipse,項目名稱:neoscada,代碼行數:19,代碼來源:ObjectSerializationEncoder.java

示例6: createMessage

import org.apache.mina.core.buffer.IoBuffer; //導入方法依賴的package包/類
protected IoBuffer createMessage ( final IoSession session, final byte command, final boolean longMessage )
{
    final IoBuffer data = IoBuffer.allocate ( 3 );
    data.setAutoExpand ( true );

    if ( Sessions.isLittleEndian ( session ) )
    {
        data.order ( ByteOrder.LITTLE_ENDIAN );
    }

    data.put ( (byte)0x12 );
    data.put ( (byte)0x02 );
    data.put ( command );
    if ( longMessage )
    {
        data.putShort ( (short)0 );
    }
    return data;
}
 
開發者ID:eclipse,項目名稱:neoscada,代碼行數:20,代碼來源:ProtocolEncoderImpl.java

示例7: writeMessage

import org.apache.mina.core.buffer.IoBuffer; //導入方法依賴的package包/類
private IoBuffer writeMessage(Message message) {
	//----------------消息協議格式-------------------------
	// packetLength | moduleId | cmd   |  body
	//       int       short     short    byte[]

	IoBuffer buffer = IoBuffer.allocate(CodecContext.WRITE_CAPACITY);
	buffer.setAutoExpand(true);

	//消息內容長度,先占個坑
	buffer.putInt(0);
	short moduleId = message.getModule();
	short cmd = message.getCmd();
	//寫入module類型
	buffer.putShort(moduleId);
	//寫入cmd類型
	buffer.putShort(cmd);

	//寫入具體消息的內容
	byte[] body = wrapMessageBody(moduleId, cmd, message);
	buffer.put(body);
	//回到buff字節數組頭部
	buffer.flip();
	//消息元信息,兩個short,共4個字節
	final int METE_SIZE = 4;
	//重新寫入包體長度
	buffer.putInt(buffer.limit() - METE_SIZE);
	buffer.rewind();

	return buffer;
}
 
開發者ID:kingston-csj,項目名稱:jforgame,代碼行數:31,代碼來源:MessageEncoder.java

示例8: encode

import org.apache.mina.core.buffer.IoBuffer; //導入方法依賴的package包/類
@Override
public void encode ( final IoSession session, final Object message, final ProtocolEncoderOutput out ) throws Exception
{
    logger.debug ( "Encoding: {}", message );
    final Pdu request = (Pdu)message;

    final IoBuffer buffer = IoBuffer.allocate ( request.getData ().remaining () + 3 );
    buffer.setAutoExpand ( true );

    final IoBuffer pdu = request.getData ();

    // put slave id
    buffer.put ( request.getUnitIdentifier () );
    // put data
    buffer.put ( pdu );

    // make and put crc
    final int crc = Checksum.crc16 ( buffer.array (), 0, pdu.limit () + 1 ); // including slave address
    buffer.order ( ByteOrder.LITTLE_ENDIAN );
    buffer.putShort ( (short)crc );

    buffer.flip ();

    logger.trace ( "Encoded to: {}", buffer );

    out.write ( buffer );
}
 
開發者ID:eclipse,項目名稱:neoscada,代碼行數:28,代碼來源:ModbusRtuEncoder.java

示例9: encode

import org.apache.mina.core.buffer.IoBuffer; //導入方法依賴的package包/類
@Override
public void encode ( final IoSession session, final Object message, final ProtocolEncoderOutput out ) throws Exception
{
    logger.debug ( "Encoding: {}", message );
    final Pdu request = (Pdu)message;

    final IoBuffer buffer = IoBuffer.allocate ( request.getData ().remaining () + 7 );
    buffer.setAutoExpand ( true );

    final IoBuffer pdu = request.getData ();

    // put transaction identifier
    buffer.putUnsignedShort ( request.getTransactionId () );
    // put modbus protocol identifier (always 0)
    buffer.putUnsignedShort ( 0 );
    // put length, including slave id
    buffer.putUnsignedShort ( request.getData ().remaining () + 1 );
    // put slave id
    buffer.put ( request.getUnitIdentifier () );
    // put data
    buffer.put ( pdu );

    buffer.flip ();

    logger.trace ( "Encoded to: {}", buffer );

    out.write ( buffer );
}
 
開發者ID:eclipse,項目名稱:neoscada,代碼行數:29,代碼來源:ModbusTcpEncoder.java

示例10: getSessionBuffer

import org.apache.mina.core.buffer.IoBuffer; //導入方法依賴的package包/類
/**
 * Get the session buffer and create one of necessary
 * 
 * @param session
 *            the session
 * @return the session buffer
 */
private IoBuffer getSessionBuffer ( final IoSession session )
{
    IoBuffer buffer = (IoBuffer)session.getAttribute ( SESSION_BUFFER_ATTR );
    if ( buffer == null )
    {
        buffer = IoBuffer.allocate ( 0 );
        buffer.setAutoExpand ( true );
        session.setAttribute ( SESSION_BUFFER_ATTR, buffer );
    }
    return buffer;
}
 
開發者ID:eclipse,項目名稱:neoscada,代碼行數:19,代碼來源:TPKTFilter.java

示例11: encodeCloseMessage

import org.apache.mina.core.buffer.IoBuffer; //導入方法依賴的package包/類
private Frame encodeCloseMessage ( final IoSession session, final CloseMessage message ) throws CharacterCodingException
{
    final IoBuffer data = IoBuffer.allocate ( 0 );
    data.setAutoExpand ( true );
    data.putString ( message.getMessage (), getCharsetEncoder ( session ) );
    data.put ( (byte)0x00 );
    data.putInt ( message.getCode () );

    data.flip ();

    return new Frame ( FrameType.CLOSE, data );
}
 
開發者ID:eclipse,項目名稱:neoscada,代碼行數:13,代碼來源:MessageChannelCodecFilter.java

示例12: writeObject

import org.apache.mina.core.buffer.IoBuffer; //導入方法依賴的package包/類
public void writeObject(Object obj) throws IOException {
    IoBuffer buf = IoBuffer.allocate(64, false);
    buf.setAutoExpand(true);
    buf.putObject(obj);

    int objectSize = buf.position() - 4;
    if (objectSize > maxObjectSize) {
        throw new IllegalArgumentException("The encoded object is too big: " + objectSize + " (> " + maxObjectSize
                + ')');
    }

    out.write(buf.array(), 0, buf.position());
}
 
開發者ID:eclipse,項目名稱:neoscada,代碼行數:14,代碼來源:ObjectSerializationOutputStream.java

示例13: encode

import org.apache.mina.core.buffer.IoBuffer; //導入方法依賴的package包/類
/**
 * 基本信息編碼
 * */
@Override
public void encode(IoSession session, BaseMessage message,ProtocolEncoderOutput outPut) throws Exception {
	
	
	IoBuffer buffer = IoBuffer.allocate(1024);
	//創建自動縮小的Buffer  Buffer會保持在上麵設置的1024*1024*1,但是一旦需求超過會自動增加容量
	buffer.setAutoExpand(true);
	//傳入數據類型
	buffer.putInt(message.getDataType());
	//存儲的業務數據
	StringBean bean = (StringBean) message.getData();
	//文件名
	byte[] byteStr = bean.getFileName().getBytes(BeanUtil.charset);
	
	//傳入文件名長度
	buffer.putInt(byteStr.length);
	//傳入文件名
	//CharSequence charSequrnce = "你好";
	//CharsetEncoder encoder = Charset.forName("UTF-8").newEncoder();
	//buffer.putString(charSequrnce, encoder);
	buffer.put(byteStr);
	//打包,歸0數組指針
	buffer.flip();
	//發送
	outPut.write(buffer);
	log.debug("編碼完成");
	//自動調整一下buffer的內存空間
	buffer.shrink();
}
 
開發者ID:Xvms,項目名稱:xvms,代碼行數:33,代碼來源:StringProtocolEncoder.java

示例14: encode

import org.apache.mina.core.buffer.IoBuffer; //導入方法依賴的package包/類
/**
 * 基本信息編碼
 * */
@Override
public void encode(IoSession session, BaseMessage message,ProtocolEncoderOutput outPut) throws Exception {
	
	IoBuffer buffer = IoBuffer.allocate(1024*1024*1);
	//創建自動縮小的Buffer  Buffer會保持在上麵設置的1024*1024*1,但是一旦需求超過會自動增加容量
	buffer.setAutoExpand(true);
	//傳入數據類型
	buffer.putInt(message.getDataType());
	//存儲的業務數據
	FileBean bean = (FileBean) message.getData();
	//文件名
	byte[] byteStr = bean.getFileName().getBytes(BeanUtil.charset);
	
	//傳入文件名長度
	buffer.putInt(byteStr.length);
	//文件大小
	
	buffer.putInt(bean.getFileSize());
	//傳入文件名
	buffer.put(byteStr);
	//傳入文件內容
	buffer.put(bean.getFileContent());
	//打包,歸0數組指針
	buffer.flip();
	//發送
	outPut.write(buffer);
	System.out.println("編碼完成!");
	buffer.shrink();
}
 
開發者ID:Xvms,項目名稱:xvms,代碼行數:33,代碼來源:FileProtocolEncoder.java

示例15: storeRemainingInSession

import org.apache.mina.core.buffer.IoBuffer; //導入方法依賴的package包/類
private void storeRemainingInSession(IoBuffer buf, IoSession session) {
	IoBuffer remainingBuf = IoBuffer.allocate(buf.capacity());
	remainingBuf.setAutoExpand(true);
	remainingBuf.order(buf.order());
	remainingBuf.put(buf);
	session.setAttribute(BUFFER, remainingBuf);
}
 
開發者ID:dianbaer,項目名稱:grain,代碼行數:8,代碼來源:MinaDecoder.java


注:本文中的org.apache.mina.core.buffer.IoBuffer.setAutoExpand方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。