public static byte[] toBytes(SpanPack[] pack) { if (pack == null) return null; try { DataOutputX dout = new DataOutputX(pack.length * 300); for (int i = 0; i < pack.length; i++) { dout.writePack(pack[i]); } return dout.toByteArray(); } catch (IOException e) { } return null; }
public byte[] getBytesKey() { try { DataOutputX out = new DataOutputX(); out.writeInt(objHash); out.writeText(counter); out.writeByte(timetype); return out.toByteArray(); } catch (Exception e) { throw new RuntimeException(e); } }
public void write(DataOutputX dout) throws IOException { dout.writeDecimal(time); dout.writeDecimal(objHash); dout.writeDecimal(service); dout.writeLong(txid); dout.writeBlob(profile); }
private void process(Socket socket) throws IOException { DataInputX in = null; DataOutputX out = null; try { in = new DataInputX(new BufferedInputStream(socket.getInputStream())); out = new DataOutputX(new BufferedOutputStream(socket.getOutputStream())); out.writeInt(NetCafe.TCP_AGENT); out.writeInt(objHash); out.flush(); while (objHash == Configure.getInstance().getObjHash()) { String cmd = in.readText(); Pack parameter = (Pack) in.readPack(); Pack res = ReqestHandlingProxy.process(cmd, parameter, in, out); if (res != null) { out.writeByte(TcpFlag.HasNEXT); out.writePack(res); } out.writeByte(TcpFlag.NoNEXT); out.flush(); } } finally { FileUtil.close(in); FileUtil.close(out); } }
static private boolean SendMTU(InetAddress IPAddress, int port, long pkid, int total, int num, int packetSize, byte[] data) throws IOException { Configure conf = Configure.getInstance(); DataOutputX out = new DataOutputX(); out.write(NetCafe.CAFE_MTU); out.writeInt(conf.getObjHash()); out.writeLong(pkid); out.writeShort(total); out.writeShort(num); out.writeBlob(data); return sendUdp(IPAddress, port, out.toByteArray()); } }
public void writeSimple(DataOutputX out) throws IOException { DataOutputX o = new DataOutputX(); writeInternal(o); out.writeBlob(o.toByteArray()); }
out = new DataOutputX(new BufferedOutputStream(socket.getOutputStream())); out.writeInt(NetCafe.TCP_AGENT_V2); out.writeInt(objHash); out.flush(); out.writeByte(TcpFlag.HasNEXT); byte[] obuff = new DataOutputX().writePack(res).toByteArray(); out.writeIntBytes(obuff); out.writeByte(TcpFlag.NoNEXT); out.flush();
public static List<byte[]> toBytesList(List<SpanPack> packs, int maxBytes) { if (packs == null) return null; try { List<byte[]> byteResultList = new ArrayList<byte[]>(); int maxLen = Math.max(maxBytes - 18000, 18000); int size = packs.size(); DataOutputX dout = new DataOutputX(Math.min(size * 500, maxBytes)); for (SpanPack pack : packs) { dout.writePack(pack); if (dout.getWriteSize() > maxLen) { byteResultList.add(dout.toByteArray()); dout = new DataOutputX(Math.min(size * 500, maxBytes)); } } if (dout.getWriteSize() > 0) { byteResultList.add(dout.toByteArray()); } return byteResultList; } catch (IOException e) { } return null; }
DataInputX in = tcp.getInput(); try { out.writeText(cmd); out.writeLong(session); if (param instanceof Value) { out.writeValue((Value) param); } else if (param instanceof Pack) { out.writePack((Pack) param); out.flush(); byte resFlag; while ((resFlag = in.readByte()) == TcpFlag.HasNEXT) {
private void sendList(int bufferCount, byte[] buffer) throws IOException { DataOutputX out = new DataOutputX(); out.write(NetCafe.CAFE_N); out.writeShort(bufferCount); out.write(buffer); UdpAgent.sendUdp(server, conf.net_collector_udp_port, out.toByteArray()); } }
private boolean write(List<byte[]> p) { try { DataOutputX buffer = new DataOutputX(); int bufferCount = 0; for (int i = 0; i < p.size(); i++) { byte[] b = p.get(i); if (b.length > conf.net_udp_packet_max_bytes) { UdpAgent.sendMTU(server, conf.net_collector_udp_port, b, conf.net_udp_packet_max_bytes); } else if (b.length + buffer.getWriteSize() > conf.net_udp_packet_max_bytes) { sendList(bufferCount, buffer.toByteArray()); buffer = new DataOutputX(); bufferCount = 0; } else { bufferCount++; buffer.write(b); } } if (buffer.getWriteSize() > 0) { sendList(bufferCount, buffer.toByteArray()); } return true; } catch (IOException e) { Logger.println("A123", "UDP", e); return false; } }
private static void passToNetDataProcessor(Pack pack, InetAddress addr) throws IOException { DataOutputX out = new DataOutputX(); out.write(NetCafe.CAFE); out.write(new DataOutputX().writePack(pack).toByteArray()); NetDataProcessor.add(out.toByteArray(), addr); }
public DataOutputX writeArray(long[] v) throws IOException { if (v == null) { writeShort(0); } else { writeShort(v.length); for (int i = 0; i < v.length; i++) { writeLong(v[i]); } } return this; }
public byte[] getBytes() throws IOException { DataOutputX out = new DataOutputX(); out.writeInt(log2m); out.writeInt(registerSet.size); for (int x : registerSet.readOnlyBits()) { out.writeInt(x); } return out.toByteArray(); }
out = new DataOutputX(new BufferedOutputStream(socket.getOutputStream())); out.writeInt(NetCafe.TCP_AGENT_REQ); out.writeInt(objHash); out.flush(); return true; } catch (Exception e) {
public DataOutputX writeShortBytes(byte[] b) throws IOException { this.writeShort(b.length); this.write(b); return this; }
public DataOutputX writeArray(int[] v) throws IOException { if (v == null) { writeShort(0); } else { writeShort(v.length); for (int i = 0; i < v.length; i++) { writeInt(v[i]); } } return this; }