private static final void encodeRun(StringBuffer buffer,short value,int length){
  if (length < 4) {
    for (int j=0; j < length; ++j) {
      if (value == (int)ESCAPE)       buffer.append(ESCAPE);
      buffer.append((char)value);
    }
  }
 else {
    if (length == (int)ESCAPE) {
      if (value == (int)ESCAPE)       buffer.append(ESCAPE);
      buffer.append((char)value);
      --length;
    }
    buffer.append(ESCAPE);
    buffer.append((char)length);
    buffer.append((char)value);
  }
}

private static final void encodeRun ( StringBuffer buffer , short value , int length ) { if ( length < 4 ) { for ( int j = 0 ; j < length ; ++ j ) { if ( value == ( int ) ESCAPE ) buffer . append ( ESCAPE ) ; buffer . append ( ( char ) value ) ; } } else { if ( length == ( int ) ESCAPE ) { if ( value == ( int ) ESCAPE ) buffer . append ( ESCAPE ) ; buffer . append ( ( char ) value ) ; -- length ; } buffer . append ( ESCAPE ) ; buffer . append ( ( char ) length ) ; buffer . append ( ( char ) value ) ; } }
encode a run , possibly a degenerate run ( of < 4 values ) .
