1 package au.com.loftinspace.tcpreflector.packet;
2
3 import java.net.InetSocketAddress;
4
5 /***
6 * Wraps a single distinct TCP packet
7 * @author Jeremy Mawson
8 */
9 public class Packet {
10
11 private byte[] bytes;
12 private InetSocketAddress fromAddress;
13 private InetSocketAddress toAddress;
14
15 public Packet(byte[] bytes, int bytesRead, InetSocketAddress fromAddress, InetSocketAddress toAddress) {
16 this.fromAddress = fromAddress;
17 this.toAddress = toAddress;
18
19 if (bytesRead < 0) {
20 bytesRead = 0;
21 }
22 if (bytesRead > bytes.length) {
23 bytesRead = bytes.length;
24 }
25 this.bytes = new byte[bytesRead];
26 System.arraycopy(bytes, 0, this.bytes, 0, bytesRead);
27 }
28
29 public byte[] getBytes() {
30 return bytes;
31 }
32
33 public InetSocketAddress getFromAddress() {
34 return fromAddress;
35 }
36
37 public InetSocketAddress getToAddress() {
38 return toAddress;
39 }
40
41 public int hashCode() {
42 return (new String(bytes)).hashCode();
43 }
44
45 public int getSize() {
46 return bytes.length;
47 }
48 }