def java_utf8_message_dispatcher(buffer): byte_array = [buffer.get_byte(i) for i in range(buffer.length)] byteArrayInputStream = ByteArrayInputStream(byte_array) dataInputStream = DataInputStream(byteArrayInputStream) while dataInputStream.available() > 0: try: yield dataInputStream.readUTF() except: pass
def run(self): print "connect to GS" sgs = Socket("127.0.0.1", 9011) i = DataInputStream(sgs.getInputStream()) print "connect to GeoEditor" sge = Socket("127.0.0.1", 2109) # o = DataOutputStream(sge.getOutputStream()) o = sge.getOutputStream() Thread.sleep(5000) GeoEditorListener.getInstance().getThread().addListener(self.vpl) print "gsge Ready" bufsize = 4096 lastpos = 0 buf = String("\0" * bufsize).getBytes() fc = 0 while True: if not i.available(): Thread.sleep(10) fc += 1 if fc % 500 == 0: o.flush() fc = 0 continue lastpos += i.read(buf, lastpos, bufsize - lastpos) while lastpos > 0 and lastpos > buf[0]: if buf[1] == 2: pass elif buf[1] == 1: x = self.list2num(buf[2:6]) y = self.list2num(buf[6:10]) z = self.list2num(buf[10:12]) if z > -15000: rx, ry = GeoUtil.getRegionXY(x, y) if (rx, ry) == (22, 22): bx, by = GeoUtil.getBlockXY(x, y) cx, cy = GeoUtil.getCellXY(x, y) o.write(struct.pack(">BBBBh", bx, by, cx, cy, z)) newpos = buf[0] + 1 if len(buf) - newpos < bufsize: buf = buf[newpos:] + String("\0" * bufsize).getBytes() else: buf = buf[newpos:] lastpos -= newpos
def run(self): print "connect to GS" sgs = Socket("127.0.0.1", 9011) i = DataInputStream(sgs.getInputStream()) print "connect to GeoEditor" sge = Socket("127.0.0.1", 2109) #o = DataOutputStream(sge.getOutputStream()) o = sge.getOutputStream() Thread.sleep(5000) GeoEditorListener.getInstance().getThread().addListener(self.vpl) print "gsge Ready" bufsize = 4096 lastpos = 0 buf = String("\0" * bufsize).getBytes() fc = 0 while True: if not i.available(): Thread.sleep(10) fc += 1 if fc % 500 == 0: o.flush() fc = 0 continue lastpos += i.read(buf, lastpos, bufsize - lastpos) while lastpos > 0 and lastpos > buf[0]: if buf[1] == 2: pass elif buf[1] == 1: x = self.list2num(buf[2:6]) y = self.list2num(buf[6:10]) z = self.list2num(buf[10:12]) if z > -15000: rx, ry = GeoUtil.getRegionXY(x, y) if (rx, ry) == (22, 22): bx, by = GeoUtil.getBlockXY(x, y) cx, cy = GeoUtil.getCellXY(x, y) o.write(struct.pack('>BBBBh', bx, by, cx, cy, z)) newpos = buf[0] + 1 if len(buf) - newpos < bufsize: buf = buf[newpos:] + String("\0" * bufsize).getBytes() else: buf = buf[newpos:] lastpos -= newpos