code: static public final short[] RLEStringToShortArray(String s) {
          int length = ((s.charAt(0)) << 16) | (s.charAt(1));
          short[] array = new short[length];
          int ai = 0;
          for (int i=2; i<s.length(); ++i) {
              char c = s.charAt(i);
              if (c == ESCAPE) {
                  c = s.charAt(++i);
                  if (c == ESCAPE) {
                      array[ai++] = (short) c;
                  } else {
                      int runLength = c;
                      short runValue = (short) s.charAt(++i);
                      for (int j=0; j<runLength; ++j) array[ai++] = runValue;
                  }
              }
              else {
                  array[ai++] = (short) c;
              }
          }
  
          if (ai != length)
              throw new IllegalStateException("Bad run-length encoded short array");
  
          return array;
      }
docs: Construct an array of shorts from a run-length encoded string.