Source for gnu.javax.net.ssl.provider.MaxFragmentLength

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