1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- package de.tudarmstadt.informatik.hostage.wrapper;
- import de.tudarmstadt.informatik.hostage.commons.HelperUtils;
- /**
- * Wrapper class for the payload of a network packet.
- *
- * @author Mihai Plasoianu
- * @author Wulf Pfeiffer
- */
- public class Packet {
- private byte[] payload;
- private String protocol;
- /**
- * Constructs Packet from byte[]
- *
- * @param payload
- * The byte[] payload
- */
- public Packet(byte[] payload, String protocol) {
- this.payload = payload;
- this.protocol = protocol;
- }
- /**
- * Constructs Packet from String
- *
- * @param payload
- * The String payload
- */
- public Packet(String payload, String protocol) {
- this.payload = payload.getBytes();
- this.protocol = protocol;
- }
- /**
- * Returns a byte[] representation of the payload.
- *
- * @return byte[] representation.
- */
- public byte[] getBytes() {
- return payload;
- }
- /**
- * Returns a String representation of the payload.
- * If the payload contains a ASCII character the whole
- * String will be represented as a String of a byte values.
- * E.g.: the byte[] {0x01, 0x4A, 0x03} would look like
- * the String "01, 4A, 03".
- * Otherwise a normal String will be created with the payload.
- *
- * @return String representation.
- */
- @Override
- public String toString() {
- if (protocol.equals("FTP")
- || protocol.equals("HTTP")
- || protocol.equals("HTTPS")) {
- return new String(payload);
- } else {
- return HelperUtils.bytesToHexString(payload);
- }
- }
- }
|