// 接收byte响应
public static RecevEntity getRetVo(byte[] data)
{
ByteBuffer buf = ByteBuffer.wrap(data);
buf.order(ConstantSelf.AgentMsgByteSet);
SelfQryRspVO uvo = new SelfQryRspVO();
{
byte[] cisdn = new byte[21];
buf.get(cisdn);
uvo.setIsdn(new String(cisdn, ConstantSelf.AgentMsgEncoding).toString().trim());
uvo.setDwseq(buf.getInt());
uvo.setBuflen(buf.getInt());
uvo.setResult(buf.getInt());
}
}
// 打包发送byte数据
public static byte[] getBytes(int msgFlag, int type,String fileName)
{
// 发送的消息总长度
int msgtotallen = 4 +
1 +
256;
ByteBuffer buf = ByteBuffer.allocate(msgtotallen);
// 设置字节序
buf.order(ByteOrder.LITTLE_ENDIAN);
try
{
buf.putInt(msgFlag);
buf.put((byte)type);
byte[] bmdn = new byte[256];
byte[] smdn = fileName.getBytes("GBK");
System.arraycopy(smdn, 0, bmdn, 0, smdn.length);
buf.put(bmdn);
}
catch(Exception ex)
{
uniportal_logger.error(ex.toString());
}
return buf.array();
}
// 打印为十六进制可读字符串
public static String bytesToHex(final byte[] bytes)
{
if(bytes == null)
{
return "";
}
StringBuffer strBuffer = new StringBuffer(bytes.length * 3);
for(int i = 0;i < bytes.length;i++)
{
strBuffer.append(Integer.toHexString(bytes[i] & 0xff));
strBuffer.append(" ");
}
return strBuffer.toString();
}