android - java.io.StreamCorruptedException:Wrong format:56 -
during time, develop android application, use object[input/output]stream send/receive message.the following code send method:
public void sendmsg(message msg) { try { if(connectedfalg) { outputstream.reset(); outputstream.writeobject(msg); outputstream.flush(); } } catch (ioexception e) { // todo auto-generated catch block e.printstacktrace(); } }
at same time, there thread receive message time, code following:
while(true) { try { message msg = (message) inputstream.readobject(); buffermanager.instance.addreceivequeue(msg); } catch (optionaldataexception e) { // todo auto-generated catch block e.printstacktrace(); } catch (ioexception e) { // todo auto-generated catch block e.printstacktrace(); } catch (classnotfoundexception e) { // todo auto-generated catch block e.printstacktrace(); } }
in project, have 3 ball, 1 ball target ball, others controlled mobile phone accelerate sensor.at first send state of no.1 ball, , send no.2 ball or target ball, have exception.like:
java.io.streamcorruptedexception:wrong format:56 05-15 21:53:02.220: w/system.err(5923): @ java.io.objectinputstream.corruptstream(objectinputstream.java:676) 05-15 21:53:02.230: w/system.err(5923): @ java.io.objectinputstream.readnonprimitivecontent(objectinputstream.java:789)
and times have problem:
05-16 15:42:28.380: w/system.err(14690): java.io.utfdataformatexception: bad byte @ 122
05-16 15:42:28.380: w/system.err(14690): @ java.nio.charset.modifiedutf8.decode(modifiedutf8.java:60) 05-16 15:42:28.380: w/system.err(14690): @ java.io.datainputstream.decodeutf(datainputstream.java:179) 05-16 15:42:28.380: w/system.err(14690): @ java.io.datainputstream.decodeutf(datainputstream.java:173) 05-16 15:42:28.380: w/system.err(14690): @ java.io.datainputstream.readutf(datainputstream.java:169) 05-16 15:42:28.380: w/system.err(14690): @ java.io.objectinputstream.readfielddescriptors(objectinputstream.java:895) 05-16 15:42:28.380: w/system.err(14690): @ java.io.objectinputstream.readclassdescriptor(objectinputstream.java:1719) 05-16 15:42:28.380: w/system.err(14690): @ java.io.objectinputstream.readnewclassdesc(objectinputstream.java:1631) 05-16 15:42:28.380: w/system.err(14690): @ java.io.objectinputstream.readclassdesc(objectinputstream.java:658) 05-16 15:42:28.380: w/system.err(14690): @ java.io.objectinputstream.readnewobject(objectinputstream.java:1781) 05-16 15:42:28.380: w/system.err(14690): @ java.io.objectinputstream.readnonprimitivecontent(objectinputstream.java:762) 05-16 15:42:28.380: w/system.err(14690): @ java.io.objectinputstream.readobject(objectinputstream.java:1981) 05-16 15:42:28.380: w/system.err(14690): @ java.io.objectinputstream.readobject(objectinputstream.java:1938)
this project https://github.com/aresxiao/datastreamengine/tree/dev
if 2 ball collide, call collisioncalculate() method,the method following:
public boolean collisioncalculate(float ballatempxy[],abstractball balla,abstractball ballb) { value bvalue = kvstoreinmemory.instance.getversionvalue(new key(ballb.getballid())).getvalue(); float[] bloc = bvalue.getloc(); float bax = ballatempxy[0] - bloc[0]; float bay = ballatempxy[1] - bloc[1]; float mvba = mould(new float[]{bax, bay}); if(mvba > (balla.getradius() + ballb.getradius())){ return false; } float[] bv = bvalue.getv(); float vb = (float)math.sqrt(bv[0] * bv[0] + bv[1] * bv[1]); float vbcollx = 0; float vbcolly = 0; //垂直方向的xy分速度 float vbverticalx=0; float vbverticaly=0; if(balla.getvmin() < vb) { float bangle=angle ( new float[]{bv[0],bv[1]}, new float[]{bax,bay} ); float vbcoll=vb * (float)math.cos(bangle); vbcollx = (vbcoll/mvba) * bax; vbcolly = (vbcoll/mvba) * bay; vbverticalx = bv[0] - vbcollx; vbverticaly = bv[1] - vbcolly; } value avalue = kvstoreinmemory.instance.getversionvalue(new key(balla.getballid())).getvalue(); float[] av = avalue.getv(); float va = (float)math.sqrt(av[0] * av[0] + av[1] * av[1]); //平行方向的xy分速度 float vacollx = 0; float vacolly = 0; //垂直方向的xy分速度 float vaverticalx = 0; float vaverticaly = 0; if(balla.getvmin() < va) { float aangle=angle ( new float[]{av[0],av[1]}, new float[]{bax,bay} ); float vacoll=va*(float)math.cos(aangle); vacollx=(vacoll/mvba)*bax; vacolly=(vacoll/mvba)*bay; vaverticalx = av[0]-vacollx; vaverticaly = av[1]-vacolly; } av[0] = vaverticalx + vbcollx; av[1] = vaverticaly + vbcolly; avalue.setv(av[0], av[1]); registercontrollerfactory.instance.getregistercontroller().write(new key(balla.getballid()), avalue); system.out.println("write balla "+balla.getballid()); bv[0] = vbverticalx + vacollx; bv[1] = vbverticaly + vacolly; bvalue.setv(bv[0], bv[1]); registercontrollerfactory.instance.getregistercontroller().write(new key(ballb.getballid()), bvalue); system.out.println("write ballb "+ballb.getballid()); return true; }
Comments
Post a Comment