List of usage examples for io.netty.util CharsetUtil US_ASCII
Charset US_ASCII
To view the source code for io.netty.util CharsetUtil US_ASCII.
Click Source Link
From source file:org.graylog2.inputs.transports.netty.LenientLineBasedFrameDecoderTest.java
License:Open Source License
@Test public void testDecodeWithoutStripAndEmitLastLine() throws Exception { EmbeddedChannel ch = new EmbeddedChannel(new LenientLineBasedFrameDecoder(8192, false, false, true)); ch.writeInbound(copiedBuffer("first\r\nsecond\nthird", CharsetUtil.US_ASCII)); ByteBuf buf1 = ch.readInbound();/*w ww. ja v a 2 s .c o m*/ assertEquals("first\r\n", buf1.toString(CharsetUtil.US_ASCII)); ByteBuf buf2 = ch.readInbound(); assertEquals("second\n", buf2.toString(CharsetUtil.US_ASCII)); // Close channel assertTrue(ch.finish()); ByteBuf buf3 = ch.readInbound(); assertEquals("third", buf3.toString(CharsetUtil.US_ASCII)); assertNull(ch.readInbound()); assertFalse(ch.finish()); ReferenceCountUtil.release(ch.readInbound()); buf1.release(); buf2.release(); buf3.release(); }
From source file:org.graylog2.inputs.transports.netty.LenientLineBasedFrameDecoderTest.java
License:Open Source License
@Test public void testTooLongLine1AndEmitLastLine() throws Exception { EmbeddedChannel ch = new EmbeddedChannel(new LenientLineBasedFrameDecoder(16, false, false, true)); try {/*from ww w .ja va2s .co m*/ ch.writeInbound(copiedBuffer("12345678901234567890\r\nfirst\nsecond", CharsetUtil.US_ASCII)); fail(); } catch (Exception e) { assertThat(e, is(instanceOf(TooLongFrameException.class))); } ByteBuf buf = ch.readInbound(); ByteBuf expectedBuf = copiedBuffer("first\n", CharsetUtil.US_ASCII); assertThat(buf, is(expectedBuf)); // Close channel assertTrue(ch.finish()); ByteBuf buf2 = ch.readInbound(); ByteBuf expectedBuf2 = copiedBuffer("second", CharsetUtil.US_ASCII); assertThat(buf2, is(expectedBuf2)); assertThat(ch.finish(), is(false)); buf.release(); expectedBuf.release(); buf2.release(); expectedBuf2.release(); }
From source file:org.graylog2.inputs.transports.netty.LenientLineBasedFrameDecoderTest.java
License:Open Source License
@Test public void testTooLongLine2AndEmitLastLine() throws Exception { EmbeddedChannel ch = new EmbeddedChannel(new LenientLineBasedFrameDecoder(16, false, false, true)); assertFalse(ch.writeInbound(copiedBuffer("12345678901234567", CharsetUtil.US_ASCII))); try {/* ww w. ja va2 s . co m*/ ch.writeInbound(copiedBuffer("890\r\nfirst\r\n", CharsetUtil.US_ASCII)); fail(); } catch (Exception e) { assertThat(e, is(instanceOf(TooLongFrameException.class))); } ByteBuf buf = ch.readInbound(); ByteBuf buf2 = copiedBuffer("first\r\n", CharsetUtil.US_ASCII); assertThat(buf, is(buf2)); assertThat(ch.finish(), is(false)); buf.release(); buf2.release(); }
From source file:org.graylog2.inputs.transports.netty.LenientLineBasedFrameDecoderTest.java
License:Open Source License
@Test public void testTooLongLineWithFailFastAndEmitLastLine() throws Exception { EmbeddedChannel ch = new EmbeddedChannel(new LenientLineBasedFrameDecoder(16, false, true, true)); try {/*from w ww.j a va 2 s .com*/ ch.writeInbound(copiedBuffer("12345678901234567", CharsetUtil.US_ASCII)); fail(); } catch (Exception e) { assertThat(e, is(instanceOf(TooLongFrameException.class))); } assertThat(ch.writeInbound(copiedBuffer("890", CharsetUtil.US_ASCII)), is(false)); assertThat(ch.writeInbound(copiedBuffer("123\r\nfirst\r\n", CharsetUtil.US_ASCII)), is(true)); ByteBuf buf = ch.readInbound(); ByteBuf buf2 = copiedBuffer("first\r\n", CharsetUtil.US_ASCII); assertThat(buf, is(buf2)); assertThat(ch.finish(), is(false)); buf.release(); buf2.release(); }
From source file:org.graylog2.inputs.transports.netty.LenientLineBasedFrameDecoderTest.java
License:Open Source License
@Test public void testDecodeSplitsCorrectlyAndEmitLastLine() throws Exception { EmbeddedChannel ch = new EmbeddedChannel(new LenientLineBasedFrameDecoder(8192, false, false, true)); assertTrue(ch.writeInbound(copiedBuffer("line\r\n.\r\n", CharsetUtil.US_ASCII))); ByteBuf buf = ch.readInbound();//from ww w.j a v a 2s .c o m assertEquals("line\r\n", buf.toString(CharsetUtil.US_ASCII)); ByteBuf buf2 = ch.readInbound(); assertEquals(".\r\n", buf2.toString(CharsetUtil.US_ASCII)); assertFalse(ch.finishAndReleaseAll()); buf.release(); buf2.release(); }
From source file:org.graylog2.inputs.transports.netty.LenientLineBasedFrameDecoderTest.java
License:Open Source License
@Test public void testFragmentedDecodeAndEmitLastLine() throws Exception { EmbeddedChannel ch = new EmbeddedChannel(new LenientLineBasedFrameDecoder(8192, false, false, true)); assertFalse(ch.writeInbound(copiedBuffer("huu", CharsetUtil.US_ASCII))); assertNull(ch.readInbound());//from w ww . java2s .c o m assertFalse(ch.writeInbound(copiedBuffer("haa\r", CharsetUtil.US_ASCII))); assertNull(ch.readInbound()); assertTrue(ch.writeInbound(copiedBuffer("\nhuuhaa\r\n", CharsetUtil.US_ASCII))); ByteBuf buf = ch.readInbound(); assertEquals("huuhaa\r\n", buf.toString(CharsetUtil.US_ASCII)); ByteBuf buf2 = ch.readInbound(); assertEquals("huuhaa\r\n", buf2.toString(CharsetUtil.US_ASCII)); assertFalse(ch.finishAndReleaseAll()); buf.release(); buf2.release(); }
From source file:org.graylog2.inputs.transports.netty.LenientLineBasedFrameDecoderTest.java
License:Open Source License
@Test public void testEmptyLineAndEmitLastLine() throws Exception { EmbeddedChannel ch = new EmbeddedChannel(new LenientLineBasedFrameDecoder(8192, true, false, true)); assertTrue(ch.writeInbound(copiedBuffer("\nabcna\r\n", CharsetUtil.US_ASCII))); ByteBuf buf = ch.readInbound();//from w ww. j a v a 2 s . c om assertEquals("", buf.toString(CharsetUtil.US_ASCII)); ByteBuf buf2 = ch.readInbound(); assertEquals("abcna", buf2.toString(CharsetUtil.US_ASCII)); assertFalse(ch.finishAndReleaseAll()); buf.release(); buf2.release(); }
From source file:org.hawkular.metrics.clients.ptrans.collectd.packet.CollectdPacketDecoder.java
License:Apache License
private String readStringPartContent(ByteBuf content, int length) { String string = content.toString(content.readerIndex(), length - 1 /* collectd strings are \0 terminated */, CharsetUtil.US_ASCII); content.skipBytes(length); // the previous call does not move the readerIndex return string; }
From source file:org.hawkular.metrics.clients.ptrans.collectd.packet.PacketDecodingTest.java
License:Apache License
static ByteBuf createStringPartBuffer(String value, PartType partType) { ByteBuf buffer = Unpooled.buffer();// www. ja v a2 s . com buffer.writeShort(partType.getId()); ByteBuf src = Unpooled.copiedBuffer(value, CharsetUtil.US_ASCII); buffer.writeShort(4 + src.readableBytes() + 1); buffer.writeBytes(src); buffer.writeByte(0); return buffer; }
From source file:org.hornetq.jms.example.XAReceiveExample.java
License:Apache License
@Override public boolean runExample() throws Exception { XAConnection connection = null; InitialContext initialContext = null; try {// ww w. j av a 2 s . c o m // Step 1. Create an initial context to perform the JNDI lookup. initialContext = getContext(0); // Step 2. Lookup on the queue Queue queue = (Queue) initialContext.lookup("/queue/exampleQueue"); // Step 3. Perform a lookup on the XA Connection Factory XAConnectionFactory cf = (XAConnectionFactory) initialContext.lookup("/XAConnectionFactory"); // Step 4.Create a JMS XAConnection connection = cf.createXAConnection(); // Step 5. Start the connection connection.start(); // Step 6. Create a JMS XASession XASession xaSession = connection.createXASession(); // Step 7. Create a normal session Session normalSession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); // Step 8. Create a normal Message Producer MessageProducer normalProducer = normalSession.createProducer(queue); // Step 9. Get the JMS Session Session session = xaSession.getSession(); // Step 10. Create a message consumer MessageConsumer xaConsumer = session.createConsumer(queue); // Step 11. Create two Text Messages TextMessage helloMessage = session.createTextMessage("hello"); TextMessage worldMessage = session.createTextMessage("world"); // Step 12. create a transaction Xid xid1 = new DummyXid("xa-example1".getBytes(CharsetUtil.US_ASCII), 1, UUIDGenerator.getInstance().generateStringUUID().getBytes()); // Step 13. Get the JMS XAResource XAResource xaRes = xaSession.getXAResource(); // Step 14. Begin the Transaction work xaRes.start(xid1, XAResource.TMNOFLAGS); // Step 15. Send two messages. normalProducer.send(helloMessage); normalProducer.send(worldMessage); // Step 16. Receive the message TextMessage rm1 = (TextMessage) xaConsumer.receive(); System.out.println("Message received: " + rm1.getText()); TextMessage rm2 = (TextMessage) xaConsumer.receive(); System.out.println("Message received: " + rm2.getText()); // Step 17. Stop the work xaRes.end(xid1, XAResource.TMSUCCESS); // Step 18. Prepare xaRes.prepare(xid1); // Step 19. Roll back the transaction xaRes.rollback(xid1); // Step 20. Create another transaction Xid xid2 = new DummyXid("xa-example2".getBytes(), 1, UUIDGenerator.getInstance().generateStringUUID().getBytes()); // Step 21. Start the transaction xaRes.start(xid2, XAResource.TMNOFLAGS); // Step 22. receive those messages again rm1 = (TextMessage) xaConsumer.receive(); System.out.println("Message received again: " + rm1.getText()); rm2 = (TextMessage) xaConsumer.receive(); System.out.println("Message received again: " + rm2.getText()); // Step 23. Stop the work xaRes.end(xid2, XAResource.TMSUCCESS); // Step 24. Prepare xaRes.prepare(xid2); // Step 25. Commit! xaRes.commit(xid2, false); // Step 26. Check no more messages are received. TextMessage rm3 = (TextMessage) xaConsumer.receive(2000); if (rm3 == null) { System.out.println("No message received after commit."); } else { result = false; } return result; } finally { // Step 27. Be sure to close our JMS resources! if (initialContext != null) { initialContext.close(); } if (connection != null) { connection.close(); } } }