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;
}
{
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;
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货