Here you can find the source of writeStringData(ByteBuffer buff, String s, int len)
Parameter | Description |
---|---|
buff | the target buffer (must be large enough) |
s | the string |
len | the number of characters |
public static void writeStringData(ByteBuffer buff, String s, int len)
//package com.java2s; /*/*from w w w .j ava 2 s . c om*/ * Copyright 2004-2014 H2 Group. Multiple-Licensed under the MPL 2.0, * and the EPL 1.0 (http://h2database.com/html/license.html). * Initial Developer: H2 Group */ import java.nio.ByteBuffer; public class Main { /** * Write characters from a string (without the length). * * @param buff the target buffer (must be large enough) * @param s the string * @param len the number of characters */ public static void writeStringData(ByteBuffer buff, String s, int len) { for (int i = 0; i < len; i++) { int c = s.charAt(i); if (c < 0x80) { buff.put((byte) c); } else if (c >= 0x800) { buff.put((byte) (0xe0 | (c >> 12))); buff.put((byte) (((c >> 6) & 0x3f))); buff.put((byte) (c & 0x3f)); } else { buff.put((byte) (0xc0 | (c >> 6))); buff.put((byte) (c & 0x3f)); } } } }