本文整理匯總了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 );
}
示例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;
}
示例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 ();
}
示例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 ) );
}
示例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 );
}
示例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 );
}
示例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 ) );
}
示例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;
}
}
示例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);
}
}
示例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 );
}
示例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));
}
示例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));
}
示例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));
}
示例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);
}
示例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 );
}