package electrosphere.util;

import java.nio.ByteBuffer;
import java.nio.IntBuffer;
import java.util.concurrent.CopyOnWriteArrayList;

/**
 *
 * @author amaterasu
 */
public class BufferUtils {
    
    static ByteBuffer integerCompactor;
    
    static {
        integerCompactor = ByteBuffer.allocate(4);
    }
    
    public static int popIntFromByteQueue(CopyOnWriteArrayList<Byte> queue){
        int rVal = -1;
        integerCompactor.clear();
        integerCompactor.put(queue.remove(0));
        integerCompactor.put(queue.remove(0));
        integerCompactor.put(queue.remove(0));
        integerCompactor.put(queue.remove(0));
        integerCompactor.flip();
        rVal = integerCompactor.getInt();
        return rVal;
    }
}
