private static byte[] getHeaders(InputStream in, ArrayList<String> headers) throws IOException{
        int left = 0;
        byte[] buffer = new byte[2048];
        byte[] obuffer = new byte[2048];
        int read;
        while((read = in.read(buffer, left, buffer.length - left)) != -1){
            int idx = getNewlineInByteArray(buffer, 0, read + left);
            
            if(idx == -1 && read + left == buffer.length){
                throw new IOException("Header line > " + buffer.length);
            }
            
            int start = 0;
            while(idx != -1){
                if(idx == start){
                    start = idx + 2;
                    break;
                }else{
                    headers.add(new String(buffer, start, idx - start));
                }
                start = idx + 2;
                idx = getNewlineInByteArray(buffer, start, read + left);
            }
            left = read + left - start;
            System.arraycopy(buffer, start, obuffer, 0, left);
            byte[] h = buffer;
            buffer = obuffer;
            obuffer = h;
            if(idx + 2 == start){
                break;
            }
        }
        return Arrays.copyOfRange(buffer, 0, left);
    }