循环读取输入流的出现java.lang.NegativeArraySizeException怎么处理?

likeshare likeshare 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
public class recv {
public static void main(String[] args) {
recv atestprocesse=new recv();
}
public recv() {
ServerSocket serversocket=null;
Socket so=null;
OutputStream output=null;
InputStream input=null;
SGIP_Command command=null;
try {
serversocket=new ServerSocket(8809);
System.out.println("等待接收");
so=serversocket.accept();
System.out.println("接收完毕");
System.out.println("New connection accepted "
+ so.getInetAddress() + ":" + so.getPort());
command=new SGIP_Command();

SGIP_Command tmpCMD=null;
Deliver deliver=null;
DeliverResp deliverresp = null;

Report report=null;
ReportResp reportresp=null;

Userrpt userrpt = null;
UserrptResp userrptresp = null;

Bind active=null;
Unbind term=null;
BindResp resp=null;
UnbindResp Unresp=null;
boolean loop=true;
while(loop)
{
input=new DataInputStream(so.getInputStream());
output=new DataOutputStream(so.getOutputStream());
tmpCMD=command.read(input);//接收sgip消息
System.out.println( tmpCMD.getTotalLength());
switch (command.getCommandID())
{
case SGIP_Command.ID_SGIP_BIND :
{
active=(Bind)tmpCMD;//强制转换
int result=active.readbody();//解包
System.out.println(tmpCMD.getTotalLength());
System.out.println(tmpCMD.getCommandID());
System.out.println(tmpCMD.getSeqno_1());
System.out.println(tmpCMD.getSeqno_2());
System.out.println(tmpCMD.getSeqno_3());
System.out.println(active.GetLoginType());
System.out.println(active.GetLoginName());
System.out.println(active.GetLoginPassword());
resp=new BindResp(352101,//node id 3+CP_id
0);//result
resp.SetResult(1);
resp.write(output);
System.out.println("resp完成");
break;
}


这是部分代码,测试的时候每次下发短息的回复报告都是出现
等待接收
接收完毕
New connection accepted /192.168.0.119:2973
61
61
1
3027352101
321161427
1
2
resp完成
java.lang.NegativeArraySizeException
应该是数据流到最后-1标志结尾,但是程序还是读取导致的,我处理了,还是不行,不知道怎么办?
...全文
评论 15
收藏 已收藏
分享
返回顶部
likeshare
Java 51,407 成员 86,127 内容