当前位置: 首页>>代码示例>>Java>>正文


Java IoBuffer.wrap方法代码示例

本文整理汇总了Java中org.apache.mina.core.buffer.IoBuffer.wrap方法的典型用法代码示例。如果您正苦于以下问题:Java IoBuffer.wrap方法的具体用法?Java IoBuffer.wrap怎么用?Java IoBuffer.wrap使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.mina.core.buffer.IoBuffer的用法示例。


在下文中一共展示了IoBuffer.wrap方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: encode

import org.apache.mina.core.buffer.IoBuffer; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public void encode( IoSession session, Object message, ProtocolEncoderOutput out ) throws Exception
{
    ByteBuffer buffer = encoder.encodeMessage( ( Message ) message );

    IoBuffer ioBuffer = IoBuffer.wrap( buffer );

    if ( IS_DEBUG )
    {
        byte[] dumpBuffer = new byte[buffer.limit()];
        buffer.get( dumpBuffer );
        buffer.flip();
        CODEC_LOG.debug( "Encoded message \n " + message + "\n : " + Strings.dumpBytes( dumpBuffer ) );
    }

    out.write( ioBuffer );
}
 
开发者ID:apache,项目名称:directory-ldap-api,代码行数:21,代码来源:LdapProtocolEncoder.java

示例2: getNextBuffer

import org.apache.mina.core.buffer.IoBuffer; //导入方法依赖的package包/类
@Override
protected IoBuffer getNextBuffer(InputStream is) throws IOException {
    byte[] bytes = new byte[getWriteBufferSize()];

    int off = 0;
    int n = 0;
    while (off < bytes.length && (n = is.read(bytes, off, bytes.length - off)) != -1) {
        off += n;
    }

    if (n == -1 && off == 0) {
        return null;
    }

    IoBuffer buffer = IoBuffer.wrap(bytes, 0, off);

    return buffer;
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:19,代码来源:StreamWriteFilter.java

示例3: writeData

import org.apache.mina.core.buffer.IoBuffer; //导入方法依赖的package包/类
@Override
public void writeData ( final int blockAddress, byte[] data )
{
    if ( this.request.getType () != RequestType.HOLDING )
    {
        throw new IllegalStateException ( String.format ( "Modbus can only write data when the block is of type %s", RequestType.HOLDING ) );
    }
    if ( data.length == 2 )
    {
        final IoBuffer buffer = IoBuffer.wrap ( data );
        buffer.order ( this.dataOrder );
        final int value = buffer.getUnsignedShort ();
        this.slave.writeCommand ( new WriteSingleDataRequest ( this.transactionId.incrementAndGet (), this.slave.getSlaveAddress (), Constants.FUNCTION_CODE_WRITE_SINGLE_REGISTER, toWriteAddress ( blockAddress ), value ), this.request.getTimeout () );
    }
    else
    {
        data = ModbusProtocol.encodeData ( data, this.dataOrder ); // apply requested byte order
        this.slave.writeCommand ( new WriteMultiDataRequest ( this.transactionId.incrementAndGet (), this.slave.getSlaveAddress (), Constants.FUNCTION_CODE_WRITE_MULTIPLE_REGISTERS, toWriteAddress ( blockAddress ), data, data.length / 2 ), this.request.getTimeout () );
    }
    requestUpdate ();
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:22,代码来源:ModbusRequestBlock.java

示例4: sendInit

import org.apache.mina.core.buffer.IoBuffer; //导入方法依赖的package包/类
@SuppressWarnings ( "unused" )
private void sendInit ()
{
    final byte[] data = new byte[] { 0x32, 0x01, 0x00, 0x00, (byte)0xff, (byte)0xff, 0x00, 0x08, 0x00, 0x00, (byte)0xf0, 0x00, 0x00, 0x01, 0x00, 0x01, 0x03, (byte)0xc0 };
    final IoBuffer buffer = IoBuffer.wrap ( data );

    this.session.write ( new DataTPDU ( buffer ) );
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:9,代码来源:DaveHandler.java

示例5: WriteSingleDataRequest

import org.apache.mina.core.buffer.IoBuffer; //导入方法依赖的package包/类
public WriteSingleDataRequest ( final int transactionId, final byte unitIdentifier, final byte functionCode, final int address, final int value, final ByteOrder byteOrder )
{
    super ( transactionId, unitIdentifier, functionCode );
    this.address = address;

    this.value = new byte[2];
    final IoBuffer bb = IoBuffer.wrap ( this.value );
    bb.order ( byteOrder ).putUnsignedShort ( value );
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:10,代码来源:WriteSingleDataRequest.java

示例6: processAnalogWrite

import org.apache.mina.core.buffer.IoBuffer; //导入方法依赖的package包/类
private void processAnalogWrite ( final int startAddress, final int numRegisters, final byte[] rawData )
{
    final int[] regs = new int[numRegisters];
    final IoBuffer data = IoBuffer.wrap ( rawData );

    data.order ( this.order );

    for ( int i = 0; i < numRegisters; i++ )
    {
        regs[i] = data.getUnsignedShort ();
    }

    handleAnalogWrite ( startAddress, regs );
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:15,代码来源:AbstractDataSlave.java

示例7: makeReadReply

import org.apache.mina.core.buffer.IoBuffer; //导入方法依赖的package包/类
protected Object makeReadReply ( final BaseMessage baseMessage, final boolean[] data )
{
    final byte[] reply = new byte[data.length / 8 + 1];

    for ( int i = 0; i < data.length; i++ )
    {
        if ( data[i] )
        {
            reply[i / 8] = (byte) ( reply[i / 8] | 1 << i % 8 );
        }
    }

    return new ReadResponse ( baseMessage.getTransactionId (), baseMessage.getUnitIdentifier (), baseMessage.getFunctionCode (), IoBuffer.wrap ( reply ) );
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:15,代码来源:SlaveHost.java

示例8: deflate

import org.apache.mina.core.buffer.IoBuffer; //导入方法依赖的package包/类
/**
 * Compress the input. The result will be put in a new buffer.
 *  
 * @param inBuffer the buffer to be compressed. The contents are transferred
 * into a local byte array and the buffer is flipped and returned intact.
 * @return the buffer with the compressed data
 * @throws IOException if the compression of teh buffer failed for some reason
 * @throws IllegalStateException if the mode is not <code>MODE_DEFLATER</code>
 */
public IoBuffer deflate(IoBuffer inBuffer) throws IOException {
    if (mode == MODE_INFLATER) {
        throw new IllegalStateException("not initialized as DEFLATER");
    }

    byte[] inBytes = new byte[inBuffer.remaining()];
    inBuffer.get(inBytes).flip();

    // according to spec, destination buffer should be 0.1% larger
    // than source length plus 12 bytes. We add a single byte to safeguard
    // against rounds that round down to the smaller value
    int outLen = (int) Math.round(inBytes.length * 1.001) + 1 + 12;
    byte[] outBytes = new byte[outLen];

    synchronized (zStream) {
        zStream.next_in = inBytes;
        zStream.next_in_index = 0;
        zStream.avail_in = inBytes.length;
        zStream.next_out = outBytes;
        zStream.next_out_index = 0;
        zStream.avail_out = outBytes.length;

        int retval = zStream.deflate(JZlib.Z_SYNC_FLUSH);
        if (retval != JZlib.Z_OK) {
            outBytes = null;
            inBytes = null;
            throw new IOException("Compression failed with return value : " + retval);
        }

        IoBuffer outBuf = IoBuffer.wrap(outBytes, 0, zStream.next_out_index);

        return outBuf;
    }
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:44,代码来源:Zlib.java

示例9: writeRequest0

import org.apache.mina.core.buffer.IoBuffer; //导入方法依赖的package包/类
/**
 * Encodes a HTTP request and sends it to the proxy server.
 * 
 * @param nextFilter the next filter
 * @param request the http request
 */
private void writeRequest0(final NextFilter nextFilter, final HttpProxyRequest request) {
    try {
        String data = request.toHttpString();
        IoBuffer buf = IoBuffer.wrap(data.getBytes(getProxyIoSession().getCharsetName()));

        LOGGER.debug("   write:\n{}", data.replace("\r", "\\r").replace("\n", "\\n\n"));

        writeData(nextFilter, buf);

    } catch (UnsupportedEncodingException ex) {
        closeSession("Unable to send HTTP request: ", ex);
    }
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:20,代码来源:AbstractHttpLogicHandler.java

示例10: writeRegister

import org.apache.mina.core.buffer.IoBuffer; //导入方法依赖的package包/类
private void writeRegister ( final IoSession session, final WriteSingleDataRequest message )
{
    final IoBuffer buffer = IoBuffer.wrap ( message.getData () );
    final int rc = performWrite ( message.getAddress (), buffer );

    if ( rc != 0 )
    {
        sendReply ( session, makeError ( message, rc ) );
        return;
    }

    final WriteSingleDataResponse response = new WriteSingleDataResponse ( message.getTransactionId (), message.getUnitIdentifier (), message.getFunctionCode (), message.getAddress (), message.getData () );
    sendReply ( session, response );
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:15,代码来源:ModbusExport.java

示例11: testServerHandler

import org.apache.mina.core.buffer.IoBuffer; //导入方法依赖的package包/类
@Test
public void testServerHandler() throws Exception {
    List<DiscoveredCube> cubes = new ArrayList<>();
    MinaDiscoveryClient.DiscoveryServerHandler handler = new MinaDiscoveryClient.DiscoveryServerHandler(cubes);

    IoSession session = mock(IoSession.class);
    String host = randomAsciiOfLength(10);
    when(session.getRemoteAddress()).thenReturn(InetSocketAddress.createUnresolved(host, randomIntBetween(10000, 65000)));

    IoBuffer buffer = IoBuffer.wrap("1234567890abcdefgh".getBytes(UTF_8));
    handler.messageReceived(session, buffer);
    assertThat(cubes, hasSize(1));
    assertThat(cubes.get(0).id, is("90abcdefgh"));
    assertThat(cubes.get(0).host, is(host));
}
 
开发者ID:spinscale,项目名称:maxcube-java,代码行数:16,代码来源:MinaDiscoveryServerHandlerTest.java

示例12: testServerHandlerNoCubeFound

import org.apache.mina.core.buffer.IoBuffer; //导入方法依赖的package包/类
@Test
public void testServerHandlerNoCubeFound() throws Exception {
    List<DiscoveredCube> cubes = new ArrayList<>();
    MinaDiscoveryClient.DiscoveryServerHandler handler = new MinaDiscoveryClient.DiscoveryServerHandler(cubes);

    IoSession session = mock(IoSession.class);
    String host = randomAsciiOfLength(10);
    when(session.getRemoteAddress()).thenReturn(InetSocketAddress.createUnresolved(host, randomIntBetween(10000, 65000)));

    IoBuffer buffer = IoBuffer.wrap("nothingfound****".getBytes(UTF_8));
    handler.messageReceived(session, buffer);
    assertThat(cubes,  hasSize(0));
}
 
开发者ID:spinscale,项目名称:maxcube-java,代码行数:14,代码来源:MinaDiscoveryServerHandlerTest.java

示例13: testServerHandlerNotEnoughCharsReturned

import org.apache.mina.core.buffer.IoBuffer; //导入方法依赖的package包/类
@Test
public void testServerHandlerNotEnoughCharsReturned() throws Exception {
    List<DiscoveredCube> cubes = new ArrayList<>();
    MinaDiscoveryClient.DiscoveryServerHandler handler = new MinaDiscoveryClient.DiscoveryServerHandler(cubes);

    IoSession session = mock(IoSession.class);
    String host = randomAsciiOfLength(10);
    when(session.getRemoteAddress()).thenReturn(InetSocketAddress.createUnresolved(host, randomIntBetween(10000, 65000)));

    IoBuffer buffer = IoBuffer.wrap("a".getBytes(UTF_8));
    handler.messageReceived(session, buffer);
    assertThat(cubes,  hasSize(0));
}
 
开发者ID:spinscale,项目名称:maxcube-java,代码行数:14,代码来源:MinaDiscoveryServerHandlerTest.java

示例14: unmarshal

import org.apache.mina.core.buffer.IoBuffer; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 *
 * @see marshalsec.BlazeDSBase#unmarshal(byte[])
 */
@Override
public Object unmarshal ( byte[] data ) throws Exception {
    IoBuffer buf = IoBuffer.wrap(data);
    Input i = createInput(buf);
    return Deserializer.deserialize(i, Object.class);
}
 
开发者ID:mbechler,项目名称:marshalsec,代码行数:12,代码来源:Red5AMFBase.java

示例15: ByteRequest

import org.apache.mina.core.buffer.IoBuffer; //导入方法依赖的package包/类
public ByteRequest ( final byte area, final short block, final short start, final byte[] data )
{
    super ( AddressType.BYTE, area, block, start, (short)data.length );
    this.data = IoBuffer.wrap ( data );
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:6,代码来源:DaveWriteRequest.java


注:本文中的org.apache.mina.core.buffer.IoBuffer.wrap方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。