package fanch.multijeu.common.core;

import java.io.Serializable;
import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.Vector;

public class ByteVector  {

    protected byte[] mData;
    protected int mSize=16;
    protected int mAllocate=16;

    public ByteVector( int size)
    {
        mSize=size;
        mData = new byte[size];
        mAllocate=size;
    }

    public void resize(int n)
    {
        int size=mAllocate;
        while (size<n)
            size=size*2;
        mAllocate=size;
        byte[] old = mData;
        mData= new byte[n];
        mAllocate=n;
        System.arraycopy(old, 0, mData, 0, mSize);
    }

    public void add(byte[] t)
    {
        int tl = t.length;
        int n = tl+mSize;
        if(n>mAllocate)
            resize(n);
        System.arraycopy(t, 0, mData, mSize, tl);
        mSize+=tl;
    }

    public void add(byte[] t, int offset, int len)
    {
        int tl = len;
        int n = tl+mSize;
        if(n>mAllocate)
            resize(n);
        System.arraycopy(t, offset, mData, mSize, tl);
        mSize+=tl;
    }

    public void add(byte t)
    {
        if(mSize+1>mAllocate)
            resize(mSize+1);
        mData[mSize]=t;
        mSize++;
    }

    public byte[] toArray()
    {
        return Arrays.copyOfRange(mData, 0, mSize-1);
    }



}
