Example usage for io.netty.util CharsetUtil ISO_8859_1

List of usage examples for io.netty.util CharsetUtil ISO_8859_1

Introduction

In this page you can find the example usage for io.netty.util CharsetUtil ISO_8859_1.

Prototype

Charset ISO_8859_1

To view the source code for io.netty.util CharsetUtil ISO_8859_1.

Click Source Link

Document

ISO Latin Alphabet No.

Usage

From source file:org.graylog2.inputs.transports.netty.LenientDelimiterBasedFrameDecoderTest.java

License:Open Source License

@Test
public void testFailFastTooLongFrameRecovery() throws Exception {
    EmbeddedChannel ch = new EmbeddedChannel(
            new LenientDelimiterBasedFrameDecoder(1, Delimiters.nulDelimiter()));

    for (int i = 0; i < 2; i++) {
        try {/*from  w w  w  .  jav a 2s  .c  o  m*/
            assertTrue(ch.writeInbound(Unpooled.wrappedBuffer(new byte[] { 1, 2 })));
            fail(DecoderException.class.getSimpleName() + " must be raised.");
        } catch (TooLongFrameException e) {
            // Expected
        }

        ch.writeInbound(Unpooled.wrappedBuffer(new byte[] { 0, 'A', 0 }));
        ByteBuf buf = ch.readInbound();
        assertEquals("A", buf.toString(CharsetUtil.ISO_8859_1));

        buf.release();
    }
}

From source file:org.hornetq.jms.example.XAHeuristicExample.java

License:Apache License

@Override
public boolean runExample() throws Exception {
    XAConnection connection = null;
    InitialContext initialContext = null;
    try {//  w  w  w  .ja  va 2s .co  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 Consumer
        MessageConsumer normalConsumer = normalSession.createConsumer(queue);
        normalConsumer.setMessageListener(new SimpleMessageListener());

        // Step 9. Get the JMS Session
        Session session = xaSession.getSession();

        // Step 10. Create a message producer
        MessageProducer producer = session.createProducer(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.ISO_8859_1), 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. do work, sending hello message.
        producer.send(helloMessage);

        System.out.println("Sent message " + helloMessage.getText());

        // Step 16. Stop the work for xid1
        xaRes.end(xid1, XAResource.TMSUCCESS);

        // Step 17. Prepare xid1
        xaRes.prepare(xid1);

        // Step 18. Check none should be received
        checkNoMessageReceived();

        // Step 19. Create another transaction.
        Xid xid2 = new DummyXid("xa-example2".getBytes(), 1,
                UUIDGenerator.getInstance().generateStringUUID().getBytes());

        // Step 20. Begin the transaction work
        xaRes.start(xid2, XAResource.TMNOFLAGS);

        // Step 21. Send the second message
        producer.send(worldMessage);

        System.out.println("Sent message " + worldMessage.getText());

        // Step 22. Stop the work for xid2
        xaRes.end(xid2, XAResource.TMSUCCESS);

        // Step 23. prepare xid2
        xaRes.prepare(xid2);

        // Step 24. Again, no messages should be received!
        checkNoMessageReceived();

        // Step 25. Create JMX Connector to connect to the server's MBeanServer
        JMXConnector connector = JMXConnectorFactory.connect(new JMXServiceURL(JMX_URL),
                new HashMap<String, String>());

        // Step 26. Retrieve the MBeanServerConnection
        MBeanServerConnection mbsc = connector.getMBeanServerConnection();

        // Step 27. List the prepared transactions
        ObjectName serverObject = ObjectNameBuilder.DEFAULT.getHornetQServerObjectName();
        String[] infos = (String[]) mbsc.invoke(serverObject, "listPreparedTransactions", null, null);

        System.out.println("Prepared transactions: ");
        for (String i : infos) {
            System.out.println(i);
        }

        // Step 28. Roll back the first transaction
        mbsc.invoke(serverObject, "rollbackPreparedTransaction", new String[] { DummyXid.toBase64String(xid1) },
                new String[] { "java.lang.String" });

        // Step 29. Commit the second one
        mbsc.invoke(serverObject, "commitPreparedTransaction", new String[] { DummyXid.toBase64String(xid2) },
                new String[] { "java.lang.String" });

        Thread.sleep(2000);

        // Step 30. Check the result, only the 'world' message received
        checkMessageReceived("world");

        // Step 31. Check the prepared transaction again, should have none.
        infos = (String[]) mbsc.invoke(serverObject, "listPreparedTransactions", null, null);
        System.out.println("No. of prepared transactions now: " + infos.length);

        // Step 32. Close the JMX Connector
        connector.close();

        return result;
    } finally {
        // Step 32. Be sure to close our JMS resources!
        if (initialContext != null) {
            initialContext.close();
        }
        if (connection != null) {
            connection.close();
        }
    }
}

From source file:ratpack.session.clientside.internal.ClientSideSessionStore.java

License:Apache License

private String toBase64(ByteBuf byteBuf) {
    ByteBuf encoded = Base64.encode(byteBuf, false, Base64Dialect.STANDARD);
    try {//from  w  ww .j  a  v a 2  s  .c om
        return encoded.toString(CharsetUtil.ISO_8859_1);
    } finally {
        encoded.release();
    }
}

From source file:ratpack.session.clientside.internal.ClientSideSessionStore.java

License:Apache License

private ByteBuf fromBase64(ByteBufAllocator bufferAllocator, String string) {
    ByteBuf byteBuf = ByteBufUtil.encodeString(bufferAllocator, CharBuffer.wrap(string),
            CharsetUtil.ISO_8859_1);
    try {// w ww  .j  a v a  2  s. com
        return Base64.decode(byteBuf, Base64Dialect.STANDARD);
    } finally {
        byteBuf.release();
    }
}