ByteArray.java 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package de.tudarmstadt.informatik.hostage.wrapper;
  2. /**
  3. * Wrapper class to use a byte array as an Object.
  4. * @author Mihai Plasoianu
  5. *
  6. */
  7. public class ByteArray {
  8. private final byte[] array;
  9. /**
  10. * Constructor without parameters. Sets the internal array to null.
  11. */
  12. public ByteArray() {
  13. this.array = null;
  14. }
  15. /**
  16. * Constructor with a byte arrays as parameter. Sets the internal array to the given.
  17. * @param array The byte array that should be wrapped.
  18. */
  19. public ByteArray(byte[] array) {
  20. this.array = array;
  21. }
  22. /**
  23. * Constructor with a String as parameter. Sets the internal array to a byte array representation of the string.
  24. * @param string
  25. */
  26. public ByteArray(String string) {
  27. this.array = string.getBytes();
  28. }
  29. /**
  30. * Returns the byte array.
  31. * @return The byte array
  32. */
  33. public byte[] get() {
  34. return array;
  35. }
  36. /**
  37. * Determines size of the array.
  38. * @return Size of the array
  39. */
  40. public int size() {
  41. return array.length;
  42. }
  43. @Override
  44. public String toString() {
  45. return new String(array);
  46. }
  47. }