List of usage examples for io.netty.buffer UnpooledByteBufAllocator DEFAULT
UnpooledByteBufAllocator DEFAULT
To view the source code for io.netty.buffer UnpooledByteBufAllocator DEFAULT.
Click Source Link
From source file:io.netty.buffer.EmptyByteBufTest.java
License:Apache License
@Test public void testIsWritable() { EmptyByteBuf empty = new EmptyByteBuf(UnpooledByteBufAllocator.DEFAULT); Assert.assertFalse(empty.isWritable()); Assert.assertFalse(empty.isWritable(1)); }
From source file:io.netty.buffer.EmptyByteBufTest.java
License:Apache License
@Test public void testIsReadable() { EmptyByteBuf empty = new EmptyByteBuf(UnpooledByteBufAllocator.DEFAULT); Assert.assertFalse(empty.isReadable()); Assert.assertFalse(empty.isReadable(1)); }
From source file:io.netty.buffer.EmptyByteBufTest.java
License:Apache License
@Test public void testArray() { EmptyByteBuf empty = new EmptyByteBuf(UnpooledByteBufAllocator.DEFAULT); assertThat(empty.hasArray(), is(true)); assertThat(empty.array().length, is(0)); assertThat(empty.arrayOffset(), is(0)); }
From source file:io.netty.buffer.EmptyByteBufTest.java
License:Apache License
@Test public void testNioBuffer() { EmptyByteBuf empty = new EmptyByteBuf(UnpooledByteBufAllocator.DEFAULT); assertThat(empty.nioBufferCount(), is(1)); assertThat(empty.nioBuffer().position(), is(0)); assertThat(empty.nioBuffer().limit(), is(0)); assertThat(empty.nioBuffer(), is(sameInstance(empty.nioBuffer()))); assertThat(empty.nioBuffer(), is(sameInstance(empty.internalNioBuffer(0, 0)))); }
From source file:io.netty.buffer.EmptyByteBufTest.java
License:Apache License
@Test public void testMemoryAddress() { EmptyByteBuf empty = new EmptyByteBuf(UnpooledByteBufAllocator.DEFAULT); if (empty.hasMemoryAddress()) { assertThat(empty.memoryAddress(), is(not(0L))); } else {//from ww w . java 2s . c o m try { empty.memoryAddress(); fail(); } catch (UnsupportedOperationException ignored) { // Ignore. } } }
From source file:io.reactivex.netty.contexts.NoOpChannelHandlerContext.java
License:Apache License
@Override public ByteBufAllocator alloc() { return UnpooledByteBufAllocator.DEFAULT; }
From source file:io.reactivex.netty.protocol.http.websocket.WebSocketClientServerTest.java
License:Apache License
private static ByteBuf toByteBuf(String text) { byte[] bytes = text.getBytes(Charset.defaultCharset()); ByteBuf byteBuf = UnpooledByteBufAllocator.DEFAULT.buffer(bytes.length); return byteBuf.writeBytes(bytes); }
From source file:org.apache.activemq.artemis.core.message.impl.CoreMessage.java
License:Apache License
private ActiveMQBuffer getLargeMessageBuffer() throws ActiveMQException { ActiveMQBuffer buffer;// ww w .j a va 2 s . c o m LargeBodyEncoder encoder = getBodyEncoder(); encoder.open(); int bodySize = (int) encoder.getLargeBodySize(); buffer = new ChannelBufferWrapper(UnpooledByteBufAllocator.DEFAULT.heapBuffer(bodySize)); encoder.encode(buffer, bodySize); encoder.close(); return buffer; }
From source file:org.apache.activemq.artemis.core.protocol.stomp.StompSession.java
License:Apache License
@Override public int sendMessage(MessageReference ref, Message serverMessage, final ServerConsumer consumer, int deliveryCount) { ICoreMessage coreMessage = serverMessage.toCore(); LargeServerMessageImpl largeMessage = null; ICoreMessage newServerMessage = serverMessage.toCore(); try {// w ww .j a va 2s . c om StompSubscription subscription = subscriptions.get(consumer.getID()); StompFrame frame; ActiveMQBuffer buffer; if (coreMessage.isLargeMessage()) { LargeBodyEncoder encoder = coreMessage.getBodyEncoder(); encoder.open(); int bodySize = (int) encoder.getLargeBodySize(); buffer = new ChannelBufferWrapper(UnpooledByteBufAllocator.DEFAULT.heapBuffer(bodySize)); encoder.encode(buffer, bodySize); encoder.close(); } else { buffer = coreMessage.getReadOnlyBodyBuffer(); } if (serverMessage.getBooleanProperty(Message.HDR_LARGE_COMPRESSED)) { ActiveMQBuffer qbuff = buffer; int bytesToRead = qbuff.readerIndex(); Inflater inflater = new Inflater(); inflater.setInput(ByteUtil.getActiveArray(qbuff.readBytes(bytesToRead).toByteBuffer())); //get the real size of large message long sizeBody = newServerMessage.getLongProperty(Message.HDR_LARGE_BODY_SIZE); byte[] data = new byte[(int) sizeBody]; inflater.inflate(data); inflater.end(); qbuff.resetReaderIndex(); qbuff.resetWriterIndex(); qbuff.writeBytes(data); buffer = qbuff; } frame = connection.createStompMessage(newServerMessage, buffer, subscription, deliveryCount); int length = frame.getEncodedSize(); if (subscription.getAck().equals(Stomp.Headers.Subscribe.AckModeValues.AUTO)) { if (manager.send(connection, frame)) { final long messageID = newServerMessage.getMessageID(); final long consumerID = consumer.getID(); // this will be called after the delivery is complete // we can't call session.ack within the delivery // as it could dead lock. afterDeliveryTasks.offer(new PendingTask() { @Override public void run() throws Exception { //we ack and commit only if the send is successful session.acknowledge(consumerID, messageID); session.commit(); } }); } } else { messagesToAck.put(newServerMessage.getMessageID(), new Pair<>(consumer.getID(), length)); // Must send AFTER adding to messagesToAck - or could get acked from client BEFORE it's been added! manager.send(connection, frame); } return length; } catch (Exception e) { if (ActiveMQStompProtocolLogger.LOGGER.isDebugEnabled()) { ActiveMQStompProtocolLogger.LOGGER.debug(e); } return 0; } finally { if (largeMessage != null) { largeMessage.releaseResources(); largeMessage = null; } } }
From source file:org.apache.activemq.artemis.utils.ByteUtil.java
License:Apache License
public static byte[] longToBytes(long x) { ByteBuf buffer = UnpooledByteBufAllocator.DEFAULT.heapBuffer(8, 8); buffer.writeLong(x);//w w w . j a va 2s. c o m return buffer.array(); }