public static int readBytesToInt(InputStream ba,int len) throws IOException
    {
        byte[] buf=new byte[len];
        readIntoBuf(ba,buf);
        return bytesToInt(buf);
    }
    public static void readIntoBuf(InputStream is,byte[] buf)throws IOException
    {
        int count=0;
        int totalread=0;
        int needread=buf.length;
        do
        {
            count = is.read(buf,totalread,needread-totalread);
            if(count>0)
                totalread+=count;
            if(count<0)
                break;;
        }
        while(totalread<needread);
    }
    public static int bytesToInt(byte[] buf)
    {
        return bytesToInt(buf,0,buf.length);
    }
    public static int bytesToInt(byte[] buf,int off,int len)
    {
        int ret=0;
        for(int i=len-1;i>=0;i--)
        {
            ret = ret<<8 ;
            if(buf[off+i]>=0)
                ret += buf[off + i];
            else
               ret+=buf[off+i]+256;
        }
        return ret;
    }