Encodes the <i>modified UTF-8</i> bytes corresponding to string {@code s} into the
byte array {@code dst}, starting at the given {@code offset}.
9538
public static void encode(byte[] dst, int offset, String s) {
        final int length = s.length();
        for (int i = 0; i < length; i++) {
            char ch = s.charAt(i);
            if (ch != 0 && ch <= 127) { // U+0000 uses two bytes.
                dst[offset++] = (byte) ch;
            } else if (ch <= 2047) {
                dst[offset++] = (byte) (0xc0 | (0x1f & (ch >> 6)));
                dst[offset++] = (byte) (0x80 | (0x3f & ch));
            } else {
                dst[offset++] = (byte) (0xe0 | (0x0f & (ch >> 12)));
                dst[offset++] = (byte) (0x80 | (0x3f & (ch >> 6)));
                dst[offset++] = (byte) (0x80 | (0x3f & ch));
            }
        }
    }
1359311
public static byte[] decode( String s )
    {   
        byte[] bytes = s.getBytes();
        return decode( bytes, 0, bytes.length );
    }
857430
private static final String encode(String s) {
    try {
      return URLEncoder.encode(s, UTF_8);
    } catch (UnsupportedEncodingException e) {
      throw new Error("JVM unable to handle UTF-8");
    }
  }
1169263
@Override
    public int encode ( byte[] dst, int dstIndex ) {
        int start = dstIndex;
        SMBUtil.writeInt2(this.ciphers != null ? this.ciphers.length : 0, dst, dstIndex);
        dstIndex += 2;

        if ( this.ciphers != null ) {
            for ( int cipher : this.ciphers ) {
                SMBUtil.writeInt2(cipher, dst, dstIndex);
                dstIndex += 2;
            }
        }
        return dstIndex - start;
    }
185889
public static char bytesToChar(byte[] bytes, int offset) {
        char result = 0x0;
        for (int i = offset; i < offset + 2; ++i) {
            result = (char) ((result) << 8);
            result |= (bytes[i] & 0x00FF);
        }
        return result;
    }
1290405
@Override
    public int encode ( byte[] dst, int dstIndex ) {
        int start = dstIndex;

        System.arraycopy(this.sourceKey, 0, dst, dstIndex, 24);
        dstIndex += 24;

        SMBUtil.writeInt4(this.chunks.length, dst, dstIndex);
        dstIndex += 4;

        dstIndex += 4; // Reserved

        for ( SrvCopychunk chk : this.chunks ) {
            dstIndex += chk.encode(dst, dstIndex);
        }
        return dstIndex - start;
    }
535001
@Override
    public int encode ( byte[] dst, int dstIndex ) {
        int start = dstIndex;

        SMBUtil.writeInt2(this.hashAlgos != null ? this.hashAlgos.length : 0, dst, dstIndex);
        SMBUtil.writeInt2(this.salt != null ? this.salt.length : 0, dst, dstIndex + 2);
        dstIndex += 4;

        if ( this.hashAlgos != null ) {
            for ( int hashAlgo : this.hashAlgos ) {
                SMBUtil.writeInt2(hashAlgo, dst, dstIndex);
                dstIndex += 2;
            }
        }

        if ( this.salt != null ) {
            System.arraycopy(this.salt, 0, dst, dstIndex, this.salt.length);
            dstIndex += this.salt.length;
        }

        return dstIndex - start;
    }
7651
@Override
    public int encode ( byte[] dst, int dstIndex ) {
        int start = dstIndex;
        SMBUtil.writeInt8(this.allocationSize, dst, dstIndex);
        dstIndex += 8;
        SMBUtil.writeInt8(this.endOfFile, dst, dstIndex);
        dstIndex += 8;
        SMBUtil.writeInt4(this.numberOfLinks, dst, dstIndex);
        dstIndex += 4;
        dst[ dstIndex++ ] = (byte) ( this.deletePending ? 1 : 0 );
        dst[ dstIndex++ ] = (byte) ( this.directory ? 1 : 0 );
        return dstIndex - start;
    }
1126303
public static byte[] toBigEndianUtf16Bytes(char[] chars, int offset, int length) {
        byte[] result = new byte[length * 2];
        int end = offset + length;
        int resultIndex = 0;
        for (int i = offset; i < end; ++i) {
            char ch = chars[i];
            result[resultIndex++] = (byte) (ch >> 8);
            result[resultIndex++] = (byte) ch;
        }
        return result;
    }
878402
private static int offsetOf65KUtf8Bytes(String str, int startIndex, int endIndex) {
    // This implementation is based off of Utf8.encodedLength
    int utf8Length = 0;
    int i = startIndex;
    for (; i < endIndex; i++) {
      char c = str.charAt(i);
      utf8Length++;
      if (c < 0x800) {
        utf8Length += (0x7f - c) >>> 31; // branch free!
      } else {
        utf8Length += Character.isSurrogate(c) ? 1 : 2;
      }
      if (utf8Length == MAX_CONSTANT_STRING_LENGTH) {
        return i + 1;
      } else if (utf8Length > MAX_CONSTANT_STRING_LENGTH) {
        return i;
      }
    }
    return endIndex;
  }
484958
public static <T extends Appendable> T toHexString(T dst, byte[] src) {
        return toHexString(dst, src, 0, src.length);
    }
248692
public final static void writeBytesRef(BytesRef src, BytesRef dst) {
    if (src == null) {
      Bytes.writeVInt(dst, 0);
      return;
    }
    Bytes.writeVInt(dst, src.length);
    System.arraycopy(src.bytes, src.offset, dst.bytes, dst.offset, src.length);
    dst.offset += src.length;
  }
753745
public byte[] getData(byte[] dst, int offset)
	{
		final int items = Math.min(data.length, dst.length - offset) / stringLength;
		final int end = items * stringLength;
		if (end == 0)
			logger.error("destination range has to be multiple of 14 bytes "
				+ "for KNX strings");
		for (int i = 0; i < end; ++i)
			dst[offset + i] = (byte) data[i];
		return dst;
	}

	/* (non-Javadoc)
	 * @see tuwien.auto.calimero.dptxlator.DPTXlator#getSubTypes()
	 */
	public final Map getSubTypes()
	{
		return types;
	}

	/**
	 * @return the subtypes of the string translator type
	 * @see DPTXlator#getSubTypesStatic()
	 */
	protected static Map getSubTypesStatic()
	{
		return types;
	}

	private String fromDPT(int index)
	{
		final int offset = index * stringLength;
		final char[] output = new char[stringLength];
		int strlen = 0;
		for (int i = offset; i < (offset + stringLength) && data[i] != 0; ++i) {
			output[strlen] = (char) data[i];
			++strlen;
		}
		return new String(output, 0, strlen);
	}

	private void toDPT(byte[] buf, int offset)
	{
		// check character set, default to ASCII 7 bit encoding
		int rangeMax = 0x7f;
		if (dpt.equals(DPT_STRING_8859_1))
			rangeMax = 0xff;
		final int items = (buf.length - offset) / stringLength;
		if (items == 0) {
			logger.error("source range has to be multiple of 14 bytes for KNX strings");
			return;
		}
		data = new short[items * stringLength];
		// 7 bit encoded characters of ISO-8859-1 are equal to ASCII
		// the lower 256 characters of UCS correspond to ISO-8859-1
		for (int i = 0; i < data.length; ++i) {
			final short c = ubyte(buf[offset + i]);
			data[i] = c <= rangeMax ? c : replacement;
		}
	}
499875
public final String encode(byte[] bytes, int off, int len) {
    checkNotNull(bytes);
    checkPositionIndexes(off, off + len, bytes.length);
    CharOutput result = stringBuilderOutput(maxEncodedSize(len));
    ByteOutput byteOutput = encodingStream(result);
    try {
      for (int i = 0; i < len; i++) {
        byteOutput.write(bytes[off + i]);
      }
      byteOutput.close();
    } catch (IOException impossible) {
      throw new AssertionError("impossible");
    }
    return result.toString();
  }
1040520
public static void decodeUtf8To(String query, int offset, int length, MultiMap<String> map) {
        Utf8StringBuilder buffer = new Utf8StringBuilder();
        synchronized (map) {
            String key = null;
            String value = null;

            int end = offset + length;
            for (int i = offset; i < end; i++) {
                char c = query.charAt(i);
                switch (c) {
                    case '&':
                        value = buffer.toReplacedString();
                        buffer.reset();
                        if (key != null) {
                            map.add(key, value);
                        } else if (value != null && value.length() > 0) {
                            map.add(value, "");
                        }
                        key = null;
                        value = null;
                        break;

                    case '=':
                        if (key != null) {
                            buffer.append(c);
                            break;
                        }
                        key = buffer.toReplacedString();
                        buffer.reset();
                        break;

                    case '+':
                        buffer.append((byte) ' ');
                        break;

                    case '%':
                        if (i + 2 < end) {
                            char hi = query.charAt(++i);
                            char lo = query.charAt(++i);
                            buffer.append(decodeHexByte(hi, lo));
                        } else {
                            throw new Utf8Appendable.NotUtf8Exception("Incomplete % encoding");
                        }
                        break;

                    default:
                        buffer.append(c);
                        break;
                }
            }

            if (key != null) {
                value = buffer.toReplacedString();
                buffer.reset();
                map.add(key, value);
            } else if (buffer.length() > 0) {
                map.add(buffer.toReplacedString(), "");
            }
        }
    }
892157
public static String encode(byte[] in, int off, int len) {
        return inst.encode(in, off, len, null, 0).toString();
    }
1133236
public static void writeBytes(byte[] bytes, long value, int offset, int numBytes) {
        int shift = 0;
        for(int i = offset + numBytes - 1; i >= offset; i--) {
            bytes[i] = (byte) (0xFF & (value >> shift));
            shift += 8;
        }
    }