code: static public final String arrayToRLEString(int[] a) {
          StringBuilder buffer = new StringBuilder();
  
          appendInt(buffer, a.length);
          int runValue = a[0];
          int runLength = 1;
          for (int i=1; i<a.length; ++i) {
              int s = a[i];
              if (s == runValue && runLength < 0xFFFF) {
                  ++runLength;
              } else {
                  encodeRun(buffer, runValue, runLength);
                  runValue = s;
                  runLength = 1;
              }
          }
          encodeRun(buffer, runValue, runLength);
          return buffer.toString();
      }
docs: Construct a string representing an int array.  Use run-length encoding.
  A character represents itself, unless it is the ESCAPE character.  Then
  the following notations are possible:
  ESCAPE ESCAPE   ESCAPE literal
  ESCAPE n c      n instances of character c
  Since an encoded run occupies 3 characters, we only encode runs of 4 or
  more characters.  Thus we have n > 0 and n != ESCAPE and n <= 0xFFFF.
  If we encounter a run where n == ESCAPE, we represent this as:
  c ESCAPE n-1 c
  The ESCAPE value is chosen so as not to collide with commonly
  seen values.