MaxFragmentLength.java 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. package gnu.javax.net.ssl.provider;
  2. import gnu.javax.net.ssl.provider.Extension.Value;
  3. import java.nio.ByteBuffer;
  4. /**
  5. * Extension value
  6. * @author csm
  7. */
  8. public class MaxFragmentLength extends Value
  9. {
  10. public static final MaxFragmentLength LEN_2_9 = new MaxFragmentLength(1, 1 << 9);
  11. public static final MaxFragmentLength LEN_2_10 = new MaxFragmentLength(2, 1 << 10);
  12. public static final MaxFragmentLength LEN_2_11 = new MaxFragmentLength(3, 1 << 11);
  13. public static final MaxFragmentLength LEN_2_12 = new MaxFragmentLength(4, 1 << 12);
  14. private final int value;
  15. private final int length;
  16. private MaxFragmentLength(int value, int length)
  17. {
  18. this.value = value;
  19. this.length = length;
  20. }
  21. public ByteBuffer buffer()
  22. {
  23. return ByteBuffer.allocate(1).put(0, (byte) value);
  24. }
  25. public int length()
  26. {
  27. return 1;
  28. }
  29. public int getValue()
  30. {
  31. return value;
  32. }
  33. public int maxLength()
  34. {
  35. return length;
  36. }
  37. public String toString()
  38. {
  39. return toString(null);
  40. }
  41. public String toString(String prefix)
  42. {
  43. String s = "max_fragment_length = ";
  44. if (prefix != null)
  45. s = prefix + s;
  46. return s + maxLength() + ";";
  47. }
  48. }