// Path: mbus-java/src/main/java/com/groupon/messagebus/api/exceptions/InvalidDestinationException.java
// @SuppressWarnings("serial")
// public class InvalidDestinationException extends RuntimeException{
//     public InvalidDestinationException(Exception e){
//         super(e);
//     }
// 
//     public InvalidDestinationException(String msg) {
//         super(msg);
//     }
// }
// 
// Path: mbus-java/src/main/java/com/groupon/messagebus/api/exceptions/MessageBusException.java
// @SuppressWarnings("serial")
// public class MessageBusException extends Exception {
//     public MessageBusException(Exception e){
//         super(e);
//     }
// 
//     public MessageBusException(String message){
//         super(message);
//     }
// }
// 
// Path: mbus-java/src/main/java/com/groupon/messagebus/api/exceptions/SendFailedException.java
// public class SendFailedException extends MessageBusException{
//     public SendFailedException(String message) {
//         super(message);
//     }
// 
//     public SendFailedException(Exception e) {
//         super(e);
//     }
// }
// 
// Path: mbus-java/src/main/java/com/groupon/messagebus/client/Utils.java
// public class Utils{
// 
//     private static int MESSAGE_LOG_MAX_LENGTH = 100;
//     private static TDeserializer deserializer = new TDeserializer();
//     private static TSerializer serializer = new TSerializer();
//     private static Logger log = Logger.getLogger(Utils.class);
//     private final static String charset = "US-ASCII";
// 
//     public static final String NULL_STRING = "null";
// 
//     
//     static String encode( String clearText){
//         String ret = "";
//         try {
//             byte[] bytes = clearText.getBytes(charset);
//             ret = new String(Base64.encodeBase64(bytes), charset);
//         } catch (UnsupportedEncodingException e) {
//             log.error("Failed to encode message. Non alphanumeric char?");
//             ret = clearText;
//         }
//         
//         return ret;
//     }
//     
//     static String decode( String codedText){
//         String ret = "";
//         try {
//             byte[] bytes = codedText.getBytes(charset);
//             
//             ret = new String(Base64.decodeBase64(bytes), charset);
//         } catch (UnsupportedEncodingException e) {
//             log.error("Failed to encode message. Non alphanumeric char?");
//             ret = codedText;
//         }
//         
//         return ret;
//     }
//     public static Message getMessageFromBytes(byte[] bytes) {
//         try {
//             MessageInternal messageInternal = new MessageInternal();
//             bytes = Base64.decodeBase64(bytes);
//             synchronized(deserializer){
//                 deserializer.deserialize(messageInternal, bytes);
//             }
//             return new Message(messageInternal);
//         } catch (Exception e) {
//             throw new RuntimeException("Failed to read thrift message correctly.", e);
//         }
//     }
// 
//     
//     public static byte[] getThriftDataAsBytes(Message message) throws TException, UnsupportedEncodingException {
//         byte[] bytes = null;
//         synchronized(serializer){
//             bytes = serializer.serialize(message.getMessageInternal());
//         }
//         
//         bytes = Base64.encodeBase64(bytes);
//         return bytes;
//         
//     }
// 
// 
//     public static String getMessageInternalForLogging(MessageInternal messageInternal) {
//         String str = messageInternal.toString();
//         if (str.length() > MESSAGE_LOG_MAX_LENGTH)
//             str = str.substring(0, MESSAGE_LOG_MAX_LENGTH -1);
//         
//         return str;
//     }
//     
//     public static void sleep(long millis) {
//         try {
//             Thread.sleep(millis);
//         } catch (InterruptedException ie) {
//             log.error("Error occurred while resting...", ie);
//         }
//     }
//     
// }


import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.HashMap;
import java.util.Map;
import org.apache.log4j.Logger;
import com.groupon.messagebus.api.exceptions.InvalidDestinationException;
import com.groupon.messagebus.api.exceptions.MessageBusException;
import com.groupon.messagebus.api.exceptions.SendFailedException;
import com.groupon.messagebus.client.Utils;

    public void commit(String transaction) throws IOException {
        Map<String, String> headers = new HashMap<String, String>();
        headers.put("transaction", transaction);
        StompFrame frame = new StompFrame("COMMIT", headers);
        sendFrame(frame.format());
    }

    public void ack(String messageId) throws IOException {
        ack(messageId, null, null, null, null);
    }

    public void ack(String messageId, String receiptId) throws IOException {
        ack(messageId, null, null, null, receiptId);
    }

    public void ack(String messageId, String transaction,
            String subscriptionId, String connectionId, String receiptId)
            throws IOException {
        Map<String, String> headers = new HashMap<String, String>();
        headers.put("message-id", messageId);
        log.debug("acking message-id: " + messageId);
        if (transaction != null)
            headers.put("transaction", transaction);
        if (subscriptionId != null && !subscriptionId.equals(""))
            headers.put("subscription", subscriptionId);

        if (connectionId != null && !connectionId.equals(Utils.NULL_STRING))
            headers.put("connection-id", connectionId);

// Path: mbus-java/src/main/java/com/groupon/messagebus/api/exceptions/InvalidDestinationException.java
// @SuppressWarnings("serial")
// public class InvalidDestinationException extends RuntimeException{
//     public InvalidDestinationException(Exception e){
//         super(e);
//     }
// 
//     public InvalidDestinationException(String msg) {
//         super(msg);
//     }
// }
// 
// Path: mbus-java/src/main/java/com/groupon/messagebus/api/exceptions/MessageBusException.java
// @SuppressWarnings("serial")
// public class MessageBusException extends Exception {
//     public MessageBusException(Exception e){
//         super(e);
//     }
// 
//     public MessageBusException(String message){
//         super(message);
//     }
// }
// 
// Path: mbus-java/src/main/java/com/groupon/messagebus/api/exceptions/SendFailedException.java
// public class SendFailedException extends MessageBusException{
//     public SendFailedException(String message) {
//         super(message);
//     }
// 
//     public SendFailedException(Exception e) {
//         super(e);
//     }
// }
// 
// Path: mbus-java/src/main/java/com/groupon/messagebus/client/Utils.java
// public class Utils{
// 
//     private static int MESSAGE_LOG_MAX_LENGTH = 100;
//     private static TDeserializer deserializer = new TDeserializer();
//     private static TSerializer serializer = new TSerializer();
//     private static Logger log = Logger.getLogger(Utils.class);
//     private final static String charset = "US-ASCII";
// 
//     public static final String NULL_STRING = "null";
// 
//     
//     static String encode( String clearText){
//         String ret = "";
//         try {
//             byte[] bytes = clearText.getBytes(charset);
//             ret = new String(Base64.encodeBase64(bytes), charset);
//         } catch (UnsupportedEncodingException e) {
//             log.error("Failed to encode message. Non alphanumeric char?");
//             ret = clearText;
//         }
//         
//         return ret;
//     }
//     
//     static String decode( String codedText){
//         String ret = "";
//         try {
//             byte[] bytes = codedText.getBytes(charset);
//             
//             ret = new String(Base64.decodeBase64(bytes), charset);
//         } catch (UnsupportedEncodingException e) {
//             log.error("Failed to encode message. Non alphanumeric char?");
//             ret = codedText;
//         }
//         
//         return ret;
//     }
//     public static Message getMessageFromBytes(byte[] bytes) {
//         try {
//             MessageInternal messageInternal = new MessageInternal();
//             bytes = Base64.decodeBase64(bytes);
//             synchronized(deserializer){
//                 deserializer.deserialize(messageInternal, bytes);
//             }
//             return new Message(messageInternal);
//         } catch (Exception e) {
//             throw new RuntimeException("Failed to read thrift message correctly.", e);
//         }
//     }
// 
//     
//     public static byte[] getThriftDataAsBytes(Message message) throws TException, UnsupportedEncodingException {
//         byte[] bytes = null;
//         synchronized(serializer){
//             bytes = serializer.serialize(message.getMessageInternal());
//         }
//         
//         bytes = Base64.encodeBase64(bytes);
//         return bytes;
//         
//     }
// 
// 
//     public static String getMessageInternalForLogging(MessageInternal messageInternal) {
//         String str = messageInternal.toString();
//         if (str.length() > MESSAGE_LOG_MAX_LENGTH)
//             str = str.substring(0, MESSAGE_LOG_MAX_LENGTH -1);
//         
//         return str;
//     }
//     
//     public static void sleep(long millis) {
//         try {
//             Thread.sleep(millis);
//         } catch (InterruptedException ie) {
//             log.error("Error occurred while resting...", ie);
//         }
//     }
//     
// }


// Path: mbus-java/src/main/java/com/groupon/stomp/StompConnection.java
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.HashMap;
import java.util.Map;
import org.apache.log4j.Logger;
import com.groupon.messagebus.api.exceptions.InvalidDestinationException;
import com.groupon.messagebus.api.exceptions.MessageBusException;
import com.groupon.messagebus.api.exceptions.SendFailedException;
import com.groupon.messagebus.client.Utils;


    public void commit(String transaction) throws IOException {
        Map<String, String> headers = new HashMap<String, String>();
        headers.put("transaction", transaction);
        StompFrame frame = new StompFrame("COMMIT", headers);
        sendFrame(frame.format());
    }

    public void ack(String messageId) throws IOException {
        ack(messageId, null, null, null, null);
    }

    public void ack(String messageId, String receiptId) throws IOException {
        ack(messageId, null, null, null, receiptId);
    }

    public void ack(String messageId, String transaction,
            String subscriptionId, String connectionId, String receiptId)
            throws IOException {
        Map<String, String> headers = new HashMap<String, String>();
        headers.put("message-id", messageId);
        log.debug("acking message-id: " + messageId);
        if (transaction != null)
            headers.put("transaction", transaction);
        if (subscriptionId != null && !subscriptionId.equals(""))
            headers.put("subscription", subscriptionId);

        if (connectionId != null && !connectionId.equals(Utils.NULL_STRING))
            headers.put("connection-id", connectionId);

        if (receiptId != null && !receiptId.equals(Utils.NULL_STRING))