Unsupported library that attempts to punch holes through NAT
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

Dummy.java 1.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /*
  2. * This file is part of JSTUN.
  3. *
  4. * Copyright (c) 2005 Thomas King <king@t-king.de> - All rights
  5. * reserved.
  6. *
  7. * This software is licensed under either the GNU Public License (GPL),
  8. * or the Apache 2.0 license. Copies of both license agreements are
  9. * included in this distribution.
  10. */
  11. package de.javawi.jstun.attribute;
  12. import de.javawi.jstun.util.Utility;
  13. import de.javawi.jstun.util.UtilityException;
  14. public class Dummy extends MessageAttribute {
  15. int lengthValue;
  16. public Dummy() {
  17. super(MessageAttributeType.Dummy);
  18. }
  19. public void setLengthValue(int length) {
  20. this.lengthValue = length;
  21. }
  22. public byte[] getBytes() throws UtilityException {
  23. byte[] result = new byte[lengthValue + 4];
  24. // message attribute header
  25. // type
  26. System.arraycopy(Utility.integerToTwoBytes(typeToInteger(type)), 0, result, 0, 2);
  27. // length
  28. System.arraycopy(Utility.integerToTwoBytes(lengthValue), 0, result, 2, 2);
  29. return result;
  30. }
  31. public static Dummy parse(byte[] data) {
  32. Dummy dummy = new Dummy();
  33. dummy.setLengthValue(data.length);
  34. return dummy;
  35. }
  36. }