// Path: wasync/src/main/java/org/atmosphere/wasync/Event.java
// public enum Event {
// 
//     /**
//      * This event is fired when the connection is open. This event is only fired once.
//      */
//     OPEN,
// 
//     /**
//      * This event is fired when the connection gets closed. This event is only fired once.
//      */
//     CLOSE,
// 
//     /**
//      * This event is fired every time a new message is received.
//      */
//     MESSAGE,
// 
//     /**
//      * This event is fired every time the connection re-opened
//      */
//     REOPENED,
// 
//     /**
//      * This event is fired when unexpected error happens. This event is only fired once.
//      */
//     ERROR,
// 
//     /**
//      * This event is fire when the response's status is received. This event is only fired once.
//      */
//     STATUS,
// 
//     /**
//      * This event is fire when the response's headers is received. This event is only fired once.
//      */
//     HEADERS,
// 
//     /**
//      * This event is fire when the response's bytes are received.
//      */
//     MESSAGE_BYTES,
// 
//     /**
//      * This event is fire when the connection has been established. The Transport propagated is the one that worked.
//      * This event is only fired once.
//      */
//     TRANSPORT
// 
// }
// 
// Path: wasync/src/main/java/org/atmosphere/wasync/ReplayDecoder.java
// public interface ReplayDecoder<U, T> extends Decoder<U, Decoded<List<T>>> {
// 
//     /**
//      * Decode a String into a List of Objects. Each element of the List will be dispatched to the decoders that where
//      * added after an implementation of that interface.
//      *
//      *
//      * @param e Event
//      * @param s a object of type U
//      * @return a List of Object
//      */
//     @Override
//     public Decoded<List<T>> decode(Event e, U s);
// }


import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;
import org.atmosphere.wasync.Event;
import org.atmosphere.wasync.ReplayDecoder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
            if (skipFirstMessage.getAndSet(false)) return empty;
            Decoded<List<String>> messages = new Decoded<List<String>>(new LinkedList<String>());

            message = messagesBuffer.append(message).toString().replace(delimiter, charReplacement);
            messagesBuffer.setLength(0);

            if (message.indexOf(charReplacement) != -1) {
                String[] tokens = message.split(charReplacement);

                // Skip first.
                int pos = 1;
                int length = Integer.valueOf(tokens[0]);
                String m;
                while (pos < tokens.length) {
                    m = tokens[pos];
                    if (m.length() >= length) {
                    	messages.decoded().add(m.substring(0, length));
                        String t = m.substring(length);
                        if (t.length() > 0) {
                            length = Integer.valueOf(t);
                        }
                    } else {
                        if (pos != 1) {
                            messagesBuffer.append(length).append(delimiter).append(m);
                        } else {
                            messagesBuffer.append(message);
                        }
                        if (messages.decoded().size() > 0) {
                        	return messages;
                        } else {
// Path: wasync/src/main/java/org/atmosphere/wasync/Event.java
// public enum Event {
// 
//     /**
//      * This event is fired when the connection is open. This event is only fired once.
//      */
//     OPEN,
// 
//     /**
//      * This event is fired when the connection gets closed. This event is only fired once.
//      */
//     CLOSE,
// 
//     /**
//      * This event is fired every time a new message is received.
//      */
//     MESSAGE,
// 
//     /**
//      * This event is fired every time the connection re-opened
//      */
//     REOPENED,
// 
//     /**
//      * This event is fired when unexpected error happens. This event is only fired once.
//      */
//     ERROR,
// 
//     /**
//      * This event is fire when the response's status is received. This event is only fired once.
//      */
//     STATUS,
// 
//     /**
//      * This event is fire when the response's headers is received. This event is only fired once.
//      */
//     HEADERS,
// 
//     /**
//      * This event is fire when the response's bytes are received.
//      */
//     MESSAGE_BYTES,
// 
//     /**
//      * This event is fire when the connection has been established. The Transport propagated is the one that worked.
//      * This event is only fired once.
//      */
//     TRANSPORT
// 
// }
// 
// Path: wasync/src/main/java/org/atmosphere/wasync/ReplayDecoder.java
// public interface ReplayDecoder<U, T> extends Decoder<U, Decoded<List<T>>> {
// 
//     /**
//      * Decode a String into a List of Objects. Each element of the List will be dispatched to the decoders that where
//      * added after an implementation of that interface.
//      *
//      *
//      * @param e Event
//      * @param s a object of type U
//      * @return a List of Object
//      */
//     @Override
//     public Decoded<List<T>> decode(Event e, U s);
// }


// Path: wasync/src/main/java/org/atmosphere/wasync/decoder/TrackMessageSizeDecoder.java
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;
import org.atmosphere.wasync.Event;
import org.atmosphere.wasync.ReplayDecoder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

            if (skipFirstMessage.getAndSet(false)) return empty;
            Decoded<List<String>> messages = new Decoded<List<String>>(new LinkedList<String>());

            message = messagesBuffer.append(message).toString().replace(delimiter, charReplacement);
            messagesBuffer.setLength(0);

            if (message.indexOf(charReplacement) != -1) {
                String[] tokens = message.split(charReplacement);

                // Skip first.
                int pos = 1;
                int length = Integer.valueOf(tokens[0]);
                String m;
                while (pos < tokens.length) {
                    m = tokens[pos];
                    if (m.length() >= length) {
                    	messages.decoded().add(m.substring(0, length));
                        String t = m.substring(length);
                        if (t.length() > 0) {
                            length = Integer.valueOf(t);
                        }
                    } else {
                        if (pos != 1) {
                            messagesBuffer.append(length).append(delimiter).append(m);
                        } else {
                            messagesBuffer.append(message);
                        }
                        if (messages.decoded().size() > 0) {
                        	return messages;
                        } else {
                        	return new Decoded<List<String>>(new LinkedList<String>(), Decoded.ACTION.ABORT);