Java Code Examples for net.fs.utils.ByteShortConvert#toByteArray()
The following examples show how to use
net.fs.utils.ByteShortConvert#toByteArray() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DataMessage.java From finalspeed with GNU General Public License v2.0 | 6 votes |
public void create(int timeId) { this.timeId = timeId; dpData = new byte[this.length + 16 + 8]; ByteShortConvert.toByteArray(ver, dpData, 0); //add: ver ByteShortConvert.toByteArray(sType, dpData, 2); //add: service type ByteIntConvert.toByteArray(connectId, dpData, 4); //add: sequence ByteIntConvert.toByteArray(clientId, dpData, 8); //add: sequence ByteIntConvert.toByteArray(this.sequence, dpData, 12); //add: sequence ByteShortConvert.toByteArray((short) this.length, dpData, 16); //add:length ByteIntConvert.toByteArray(this.timeId, dpData, 18); //add: sequence System.arraycopy(this.data, 0, dpData, 22, this.length); dp = new DatagramPacket(dpData, dpData.length); dp.setAddress(dstAddress); dp.setPort(dstPort); }
Example 2
Source File: DataMessage.java From finalspeed-91yun with GNU General Public License v2.0 | 6 votes |
public void create(int timeId){ this.timeId=timeId; dpData=new byte[this.length+16+8]; ByteShortConvert.toByteArray(ver, dpData, 0); //add: ver ByteShortConvert.toByteArray(sType, dpData, 2); //add: service type ByteIntConvert.toByteArray(connectId, dpData, 4); //add: sequence ByteIntConvert.toByteArray(clientId, dpData, 8); //add: sequence ByteIntConvert.toByteArray(this.sequence, dpData, 12); //add: sequence ByteShortConvert.toByteArray((short) this.length, dpData, 16); //add:length ByteIntConvert.toByteArray(this.timeId, dpData, 18); //add: sequence System.arraycopy(this.data, 0, dpData, 22, this.length); dp=new DatagramPacket(dpData,dpData.length); dp.setAddress(dstAddress); dp.setPort(dstPort); }
Example 3
Source File: PingMessage.java From finalspeed-91yun with GNU General Public License v2.0 | 5 votes |
public PingMessage(int connectId,int clientId,int pingId,int downloadSpeed,int uploadSpeed){ ByteShortConvert.toByteArray(ver, dpData, 0); //add: ver ByteShortConvert.toByteArray(sType, dpData, 2); //add: service type ByteIntConvert.toByteArray(connectId, dpData, 4); //add: sequence ByteIntConvert.toByteArray(clientId, dpData, 8); //add: sequence ByteIntConvert.toByteArray(pingId, dpData, 12); //add: sequence ByteShortConvert.toByteArray((short) (downloadSpeed/1024), dpData, 16); ByteShortConvert.toByteArray((short) (uploadSpeed/1024), dpData, 18); dp=new DatagramPacket(dpData,dpData.length); }
Example 4
Source File: CloseMessage_Conn.java From finalspeed with GNU General Public License v2.0 | 5 votes |
public CloseMessage_Conn(int connectId, int clientId) { byte[] dpData = new byte[12]; this.clientId = clientId; this.connectId = connectId; ByteShortConvert.toByteArray(ver, dpData, 0); ByteShortConvert.toByteArray(sType, dpData, 2); ByteIntConvert.toByteArray(connectId, dpData, 4); ByteIntConvert.toByteArray(clientId, dpData, 8); dp = new DatagramPacket(dpData, dpData.length); }
Example 5
Source File: PingMessage.java From finalspeed with GNU General Public License v2.0 | 5 votes |
public PingMessage(int connectId, int clientId, int pingId, int downloadSpeed, int uploadSpeed) { ByteShortConvert.toByteArray(ver, dpData, 0); //add: ver ByteShortConvert.toByteArray(sType, dpData, 2); //add: service type ByteIntConvert.toByteArray(connectId, dpData, 4); //add: sequence ByteIntConvert.toByteArray(clientId, dpData, 8); //add: sequence ByteIntConvert.toByteArray(pingId, dpData, 12); //add: sequence ByteShortConvert.toByteArray((short) (downloadSpeed / 1024), dpData, 16); ByteShortConvert.toByteArray((short) (uploadSpeed / 1024), dpData, 18); dp = new DatagramPacket(dpData, dpData.length); }
Example 6
Source File: CloseMessage_Stream.java From finalspeed with GNU General Public License v2.0 | 5 votes |
public CloseMessage_Stream(int connectId, int clientId, int closeOffset) { byte[] dpData = new byte[16]; this.clientId = clientId; this.connectId = connectId; ByteShortConvert.toByteArray(ver, dpData, 0); //add: ver ByteShortConvert.toByteArray(sType, dpData, 2); //add: service type ByteIntConvert.toByteArray(connectId, dpData, 4); //add: sequence ByteIntConvert.toByteArray(clientId, dpData, 8); //add: sequence ByteIntConvert.toByteArray(closeOffset, dpData, 12); //add: sequence dp = new DatagramPacket(dpData, dpData.length); ////#MLog.println("vCloseMessageaaa"+clientId+"v"); }
Example 7
Source File: PingMessage2.java From finalspeed-91yun with GNU General Public License v2.0 | 5 votes |
public PingMessage2(int connectId,int clientId,int pingId){ ByteShortConvert.toByteArray(ver, dpData, 0); //add: ver ByteShortConvert.toByteArray(sType, dpData, 2); //add: service type ByteIntConvert.toByteArray(connectId, dpData, 4); //add: sequence ByteIntConvert.toByteArray(clientId, dpData, 8); //add: sequence ByteIntConvert.toByteArray(pingId, dpData, 12); //add: sequence dp=new DatagramPacket(dpData,dpData.length); }
Example 8
Source File: CloseMessage_Conn.java From finalspeed-91yun with GNU General Public License v2.0 | 5 votes |
public CloseMessage_Conn(int connectId,int clientId){ byte[] dpData=new byte[12]; this.clientId=clientId; this.connectId=connectId; ByteShortConvert.toByteArray(ver, dpData, 0); ByteShortConvert.toByteArray(sType, dpData, 2); ByteIntConvert.toByteArray(connectId, dpData, 4); ByteIntConvert.toByteArray(clientId, dpData, 8); dp=new DatagramPacket(dpData,dpData.length); }
Example 9
Source File: CloseMessage_Stream.java From finalspeed-91yun with GNU General Public License v2.0 | 5 votes |
public CloseMessage_Stream(int connectId,int clientId,int closeOffset){ byte[] dpData=new byte[16]; this.clientId=clientId; this.connectId=connectId; ByteShortConvert.toByteArray(ver, dpData, 0); //add: ver ByteShortConvert.toByteArray(sType, dpData, 2); //add: service type ByteIntConvert.toByteArray(connectId, dpData, 4); //add: sequence ByteIntConvert.toByteArray(clientId, dpData, 8); //add: sequence ByteIntConvert.toByteArray(closeOffset, dpData, 12); //add: sequence dp=new DatagramPacket(dpData,dpData.length); ////#MLog.println("vCloseMessageaaa"+clientId+"v"); }
Example 10
Source File: PingMessage2.java From NSS with Apache License 2.0 | 5 votes |
public PingMessage2(int connectId,int clientId,int pingId){ ByteShortConvert.toByteArray(ver, dpData, 0); //add: ver ByteShortConvert.toByteArray(sType, dpData, 2); //add: service type ByteIntConvert.toByteArray(connectId, dpData, 4); //add: sequence ByteIntConvert.toByteArray(clientId, dpData, 8); //add: sequence ByteIntConvert.toByteArray(pingId, dpData, 12); //add: sequence dp=new DatagramPacket(dpData,dpData.length); }
Example 11
Source File: PingMessage2.java From finalspeed with GNU General Public License v2.0 | 5 votes |
public PingMessage2(int connectId, int clientId, int pingId) { ByteShortConvert.toByteArray(ver, dpData, 0); //add: ver ByteShortConvert.toByteArray(sType, dpData, 2); //add: service type ByteIntConvert.toByteArray(connectId, dpData, 4); //add: sequence ByteIntConvert.toByteArray(clientId, dpData, 8); //add: sequence ByteIntConvert.toByteArray(pingId, dpData, 12); //add: sequence dp = new DatagramPacket(dpData, dpData.length); }
Example 12
Source File: CloseMessage_Conn.java From NSS with Apache License 2.0 | 5 votes |
public CloseMessage_Conn(int connectId,int clientId){ byte[] dpData=new byte[12]; this.clientId=clientId; this.connectId=connectId; ByteShortConvert.toByteArray(ver, dpData, 0); ByteShortConvert.toByteArray(sType, dpData, 2); ByteIntConvert.toByteArray(connectId, dpData, 4); ByteIntConvert.toByteArray(clientId, dpData, 8); dp=new DatagramPacket(dpData,dpData.length); }
Example 13
Source File: PingMessage.java From NSS with Apache License 2.0 | 5 votes |
public PingMessage(int connectId,int clientId,int pingId,int downloadSpeed,int uploadSpeed){ ByteShortConvert.toByteArray(ver, dpData, 0); //add: ver ByteShortConvert.toByteArray(sType, dpData, 2); //add: service type ByteIntConvert.toByteArray(connectId, dpData, 4); //add: sequence ByteIntConvert.toByteArray(clientId, dpData, 8); //add: sequence ByteIntConvert.toByteArray(pingId, dpData, 12); //add: sequence ByteShortConvert.toByteArray((short) (downloadSpeed/1024), dpData, 16); ByteShortConvert.toByteArray((short) (uploadSpeed/1024), dpData, 18); dp=new DatagramPacket(dpData,dpData.length); }
Example 14
Source File: CloseMessage_Stream.java From NSS with Apache License 2.0 | 5 votes |
public CloseMessage_Stream(int connectId,int clientId,int closeOffset){ byte[] dpData=new byte[16]; this.clientId=clientId; this.connectId=connectId; ByteShortConvert.toByteArray(ver, dpData, 0); //add: ver ByteShortConvert.toByteArray(sType, dpData, 2); //add: service type ByteIntConvert.toByteArray(connectId, dpData, 4); //add: sequence ByteIntConvert.toByteArray(clientId, dpData, 8); //add: sequence ByteIntConvert.toByteArray(closeOffset, dpData, 12); //add: sequence dp=new DatagramPacket(dpData,dpData.length); ////#MLog.println("vCloseMessageaaa"+clientId+"v"); }
Example 15
Source File: AckListMessage.java From finalspeed-91yun with GNU General Public License v2.0 | 4 votes |
@SuppressWarnings("unchecked") public AckListMessage(long connId,ArrayList ackList,int lastRead, HashMap<Integer, SendRecord> sendRecordTable,int timeId, int connectId,int clientId){ this.clientId=clientId; this.connectId=connectId; this.ackList=ackList; this.lastRead=lastRead; int len1=4+4+10+4*ackList.size(); dpData=new byte[len1+24+9]; sType=MessageType.sType_AckListMessage; ByteShortConvert.toByteArray(ver, dpData, 0); //add: ver ByteShortConvert.toByteArray(sType, dpData, 2); //add: service type ByteIntConvert.toByteArray(connectId, dpData, 4); //add: sequence ByteIntConvert.toByteArray(clientId, dpData, 8); //add: sequence ByteIntConvert.toByteArray(lastRead, dpData, 4+8); //dpData[8]=(byte) ackList.size(); ByteShortConvert.toByteArray((short) ackList.size(), dpData, 8+8); //add: service type for(int i=0;i<ackList.size();i++){ int sequence=(Integer)ackList.get(i); ByteIntConvert.toByteArray(sequence, dpData, 10+4*i+8); //add: sequence ////#MLog.println("发送确认 "+sequence); } int u1=timeId-2; ByteIntConvert.toByteArray(u1, dpData,len1+8); SendRecord r1=sendRecordTable.get(u1); int s1=0; if(r1!=null){ s1=r1.getSendSize(); } ByteIntConvert.toByteArray(s1, dpData, len1+4+8); int u2=timeId-1; ByteIntConvert.toByteArray(u2, dpData,len1+8+8); SendRecord r2=sendRecordTable.get(u2); int s2=0; if(r2!=null){ s2=r2.getSendSize(); } ByteIntConvert.toByteArray(s2, dpData, len1+12+8); int u3=timeId; ByteIntConvert.toByteArray(u3, dpData,len1+16+8); SendRecord r3=sendRecordTable.get(u3); int s3=0; if(r3!=null){ s3=r3.getSendSize(); } ByteIntConvert.toByteArray(s3, dpData, len1+20+8); dp=new DatagramPacket(dpData,dpData.length); }
Example 16
Source File: PacketUtils.java From NSS with Apache License 2.0 | 4 votes |
public static Packet buildIpV4( MacAddress srcAddress_mac, MacAddress dstAddrress_mac, IpV4Packet.Builder builder_ipv4){ org.pcap4j.packet.Packet.Builder builder=null; EtherType etherType=null; Packet p=null; if(ppp){ etherType= EtherType.PPPOE_SESSION_STAGE; UnknownPacket.Builder pppBuilder=new UnknownPacket.Builder(); byte[] ipData=builder_ipv4.build().getRawData(); byte[] lenb=new byte[2]; ByteShortConvert.toByteArray((short) (ipData.length+2), lenb, 0); byte[] pppHead=new byte[8]; System.arraycopy(pppHead_static, 0, pppHead, 0, pppHead.length); System.arraycopy(lenb, 0, pppHead, 4, 2); byte[] newData=new byte[pppHead.length+ipData.length]; System.arraycopy(pppHead, 0, newData, 0, pppHead.length); System.arraycopy(ipData, 0, newData, 8, ipData.length); pppBuilder.rawData(newData); builder=pppBuilder; }else { etherType= EtherType.IPV4; builder=builder_ipv4; } EthernetPacket.Builder etherBuilder = new EthernetPacket.Builder(); etherBuilder.dstAddr(dstAddrress_mac) .srcAddr(srcAddress_mac) .type(etherType) .payloadBuilder(builder) .paddingAtBuild(true); p = etherBuilder.build(); return p; }
Example 17
Source File: PacketUtils.java From finalspeed-91yun with GNU General Public License v2.0 | 4 votes |
public static Packet buildIpV4( MacAddress srcAddress_mac, MacAddress dstAddrress_mac, IpV4Packet.Builder builder_ipv4){ org.pcap4j.packet.Packet.Builder builder=null; EtherType etherType=null; Packet p=null; if(ppp){ etherType=EtherType.PPPOE_SESSION_STAGE; UnknownPacket.Builder pppBuilder=new UnknownPacket.Builder(); byte[] ipData=builder_ipv4.build().getRawData(); byte[] lenb=new byte[2]; ByteShortConvert.toByteArray((short) (ipData.length+2), lenb, 0); byte[] pppHead=new byte[8]; System.arraycopy(pppHead_static, 0, pppHead, 0, pppHead.length); System.arraycopy(lenb, 0, pppHead, 4, 2); byte[] newData=new byte[pppHead.length+ipData.length]; System.arraycopy(pppHead, 0, newData, 0, pppHead.length); System.arraycopy(ipData, 0, newData, 8, ipData.length); pppBuilder.rawData(newData); builder=pppBuilder; }else { etherType=EtherType.IPV4; builder=builder_ipv4; } EthernetPacket.Builder etherBuilder = new EthernetPacket.Builder(); etherBuilder.dstAddr(dstAddrress_mac) .srcAddr(srcAddress_mac) .type(etherType) .payloadBuilder(builder) .paddingAtBuild(true); p = etherBuilder.build(); return p; }
Example 18
Source File: PacketUtils.java From finalspeed with GNU General Public License v2.0 | 4 votes |
public static Packet buildIpV4( MacAddress srcAddress_mac, MacAddress dstAddrress_mac, IpV4Packet.Builder builder_ipv4) { org.pcap4j.packet.Packet.Builder builder; EtherType etherType; Packet p; if (ppp) { etherType = EtherType.PPPOE_SESSION_STAGE; UnknownPacket.Builder pppBuilder = new UnknownPacket.Builder(); byte[] ipData = builder_ipv4.build().getRawData(); byte[] lenb = new byte[2]; ByteShortConvert.toByteArray((short) (ipData.length + 2), lenb, 0); byte[] pppHead = new byte[8]; System.arraycopy(pppHead_static, 0, pppHead, 0, pppHead.length); System.arraycopy(lenb, 0, pppHead, 4, 2); byte[] newData = new byte[pppHead.length + ipData.length]; System.arraycopy(pppHead, 0, newData, 0, pppHead.length); System.arraycopy(ipData, 0, newData, 8, ipData.length); pppBuilder.rawData(newData); builder = pppBuilder; } else { etherType = EtherType.IPV4; builder = builder_ipv4; } EthernetPacket.Builder etherBuilder = new EthernetPacket.Builder(); etherBuilder.dstAddr(dstAddrress_mac) .srcAddr(srcAddress_mac) .type(etherType) .payloadBuilder(builder) .paddingAtBuild(true); p = etherBuilder.build(); return p; }
Example 19
Source File: AckListMessage.java From finalspeed with GNU General Public License v2.0 | 4 votes |
@SuppressWarnings("unchecked") public AckListMessage(long connId, ArrayList ackList, int lastRead, HashMap<Integer, SendRecord> sendRecordTable, int timeId, int connectId, int clientId) { this.clientId = clientId; this.connectId = connectId; this.ackList = ackList; this.lastRead = lastRead; int len1 = 4 + 4 + 10 + 4 * ackList.size(); dpData = new byte[len1 + 24 + 9]; sType = MessageType.sType_AckListMessage; ByteShortConvert.toByteArray(ver, dpData, 0); //add: ver ByteShortConvert.toByteArray(sType, dpData, 2); //add: service type ByteIntConvert.toByteArray(connectId, dpData, 4); //add: sequence ByteIntConvert.toByteArray(clientId, dpData, 8); //add: sequence ByteIntConvert.toByteArray(lastRead, dpData, 4 + 8); //dpData[8]=(byte) ackList.size(); ByteShortConvert.toByteArray((short) ackList.size(), dpData, 8 + 8); //add: service type for (int i = 0; i < ackList.size(); i++) { int sequence = (Integer) ackList.get(i); ByteIntConvert.toByteArray(sequence, dpData, 10 + 4 * i + 8); //add: sequence ////#MLog.println("发送确认 "+sequence); } int u1 = timeId - 2; ByteIntConvert.toByteArray(u1, dpData, len1 + 8); SendRecord r1 = sendRecordTable.get(u1); int s1 = 0; if (r1 != null) { s1 = r1.getSendSize(); } ByteIntConvert.toByteArray(s1, dpData, len1 + 4 + 8); int u2 = timeId - 1; ByteIntConvert.toByteArray(u2, dpData, len1 + 8 + 8); SendRecord r2 = sendRecordTable.get(u2); int s2 = 0; if (r2 != null) { s2 = r2.getSendSize(); } ByteIntConvert.toByteArray(s2, dpData, len1 + 12 + 8); ByteIntConvert.toByteArray(timeId, dpData, len1 + 16 + 8); SendRecord r3 = sendRecordTable.get(timeId); int s3 = 0; if (r3 != null) { s3 = r3.getSendSize(); } ByteIntConvert.toByteArray(s3, dpData, len1 + 20 + 8); dp = new DatagramPacket(dpData, dpData.length); }
Example 20
Source File: AckListMessage.java From NSS with Apache License 2.0 | 4 votes |
@SuppressWarnings("unchecked") public AckListMessage(long connId,ArrayList ackList,int lastRead, HashMap<Integer, SendRecord> sendRecordTable,int timeId, int connectId,int clientId){ this.clientId=clientId; this.connectId=connectId; this.ackList=ackList; this.lastRead=lastRead; int len1=4+4+10+4*ackList.size(); dpData=new byte[len1+24+9]; sType=MessageType.sType_AckListMessage; ByteShortConvert.toByteArray(ver, dpData, 0); //add: ver ByteShortConvert.toByteArray(sType, dpData, 2); //add: service type ByteIntConvert.toByteArray(connectId, dpData, 4); //add: sequence ByteIntConvert.toByteArray(clientId, dpData, 8); //add: sequence ByteIntConvert.toByteArray(lastRead, dpData, 4+8); //dpData[8]=(byte) ackList.size(); ByteShortConvert.toByteArray((short) ackList.size(), dpData, 8+8); //add: service type for(int i=0;i<ackList.size();i++){ int sequence=(Integer)ackList.get(i); ByteIntConvert.toByteArray(sequence, dpData, 10+4*i+8); //add: sequence ////#MLog.println("发送确认 "+sequence); } int u1=timeId-2; ByteIntConvert.toByteArray(u1, dpData,len1+8); SendRecord r1=sendRecordTable.get(u1); int s1=0; if(r1!=null){ s1=r1.getSendSize(); } ByteIntConvert.toByteArray(s1, dpData, len1+4+8); int u2=timeId-1; ByteIntConvert.toByteArray(u2, dpData,len1+8+8); SendRecord r2=sendRecordTable.get(u2); int s2=0; if(r2!=null){ s2=r2.getSendSize(); } ByteIntConvert.toByteArray(s2, dpData, len1+12+8); int u3=timeId; ByteIntConvert.toByteArray(u3, dpData,len1+16+8); SendRecord r3=sendRecordTable.get(u3); int s3=0; if(r3!=null){ s3=r3.getSendSize(); } ByteIntConvert.toByteArray(s3, dpData, len1+20+8); dp=new DatagramPacket(dpData,dpData.length); }