Puts a string into the buffer at the specified index, using the character set to encode the string as bytes.

@param fieldSize
the width in bytes of the prefixed length field
@param v
the string
@param cs
the character set

@return the buffer
501416
public WrappedByteBuffer putPrefixedString(int fieldSize, String v, Charset cs) {
        if (fieldSize == 0) {
            return this;
        }
        boolean utf16 = cs.name().startsWith("UTF-16");

        if (utf16 && (fieldSize == 1)) {
            throw new IllegalArgumentException("fieldSize is not even for UTF-16 character set");
        }

        java.nio.ByteBuffer strBuf = cs.encode(v);
        _autoExpand(fieldSize + strBuf.limit());

        int len = strBuf.remaining();
        switch (fieldSize) {
        case 1:
            put((byte) len);
            break;
        case 2:
            putShort((short) len);
            break;
        case 4:
            putInt(len);
            break;
        default:
            throw new IllegalArgumentException("Illegal argument, field size should be 1,2 or 4 and fieldSize is: " + fieldSize);
        }

        _buf.put(strBuf);
        return this;
    }
557867
protected JavascriptVarBuilder encodeRow(final FacesContext context, final String rowKey,
                final JavascriptVarBuilder jsData, final JavascriptVarBuilder jsRowStyle,
                final JavascriptVarBuilder jsStyle, final JavascriptVarBuilder jsReadOnly, final Sheet sheet,
                final int rowIndex) throws IOException {
        // encode rowStyle (if any)
        final String rowStyleClass = sheet.getRowStyleClass();
        if (rowStyleClass == null) {
            jsRowStyle.appendArrayValue("null", false);
        }
        else {
            jsRowStyle.appendArrayValue(rowStyleClass, true);
        }

        // data is array of array of data
        final JavascriptVarBuilder jsRow = new JavascriptVarBuilder(null, false);
        int renderCol = 0;
        for (int col = 0; col < sheet.getColumns().size(); col++) {
            final SheetColumn column = sheet.getColumns().get(col);
            if (!column.isRendered()) {
                continue;
            }

            // render data value
            final String value = sheet.getRenderValueForCell(context, rowKey, col);
            jsRow.appendArrayValue(value, true);

            // custom style
            final String styleClass = column.getStyleClass();
            if (styleClass != null) {
                jsStyle.appendRowColProperty(rowIndex, renderCol, styleClass, true);
            }

            // read only per cell
            final boolean readOnly = column.isReadonlyCell();
            if (readOnly) {
                jsReadOnly.appendRowColProperty(rowIndex, renderCol, "true", true);
            }
            renderCol++;
        }
        // close row and append to jsData
        jsData.appendArrayValue(jsRow.closeVar().toString(), false);
        return jsData;
    }
608110
public static int cusparseCsrmvEx_bufferSize(
        cusparseHandle handle, 
        int alg, 
        int transA, 
        int m, 
        int n, 
        int nnz, 
        Pointer alpha, 
        int alphatype, 
        cusparseMatDescr descrA, 
        Pointer csrValA, 
        int csrValAtype, 
        Pointer csrRowPtrA, 
        Pointer csrColIndA, 
        Pointer x, 
        int xtype, 
        Pointer beta, 
        int betatype, 
        Pointer y, 
        int ytype, 
        int executiontype, 
        long[] bufferSizeInBytes)
    {
        return checkResult(cusparseCsrmvEx_bufferSizeNative(handle, alg, transA, m, n, nnz, alpha, alphatype, descrA, csrValA, csrValAtype, csrRowPtrA, csrColIndA, x, xtype, beta, betatype, y, ytype, executiontype, bufferSizeInBytes));
    }
408830
public StrBuilder insert(int index, CharSequence csq) {
		if (null == csq) {
			csq = "null";
		}
		int len = csq.length();
		moveDataAfterIndex(index, csq.length());
		if (csq instanceof String) {
			((String) csq).getChars(0, len, this.value, index);
		} else if (csq instanceof StringBuilder) {
			((StringBuilder) csq).getChars(0, len, this.value, index);
		} else if (csq instanceof StringBuffer) {
			((StringBuffer) csq).getChars(0, len, this.value, index);
		} else if (csq instanceof StrBuilder) {
			((StrBuilder) csq).getChars(0, len, this.value, index);
		} else {
			for (int i = 0, j = this.position; i < len; i++, j++) {
				this.value[j] = csq.charAt(i);
			}
		}
		this.position = Math.max(this.position, index) + len;
		return this;
	}
105338
final private ByteBuffer stringToByteBuffer(CharSequence s) {
        bb.clear();
        final int len = s.length();
        for (int i = 0; i < len; i++) {
            if (bb.remaining() < 3) {
                ByteBuffer n = ByteBuffer.allocate(bb.capacity() << 1);
                bb.flip();
                n.put(bb);
                bb = n;
            }
            char c = s.charAt(i);
            if (c < 0x80) {
                bb.put((byte) c);
            } else if (c < 0x800) {
                bb.put((byte) (0xc0 | (c >> 6)));
                bb.put((byte) (0x80 | (c & 0x3f)));
            } else {
                bb.put((byte) (0xe0 | (c >> 12)));
                bb.put((byte) (0x80 | ((c >> 6) & 0x3f)));
                bb.put((byte) (0x80 | (c & 0x3f)));
            }
        }
        bb.flip();
        return bb;
    }
789260
public static JSONValue parse(CharSequence cs) {
        ParseText p = new ParseText(cs);
        JSONValue result = parse(p);
        if (!p.skipSpaces().isExhausted())
            throw new JSONException(EXCESS_CHARS);
        return result;
    }
423808
protected void prepareBuffer(final String key, final long cas,
    final byte[] val, final Object... extraHeaders) {
    int extraLen = 0;
    int extraHeadersLength = extraHeaders.length;

    if (extraHeadersLength > 0) {
      extraLen = calculateExtraLength(extraHeaders);
    }

    final byte[] keyBytes = KeyUtil.getKeyBytes(key);
    int bufSize = MIN_RECV_PACKET + keyBytes.length + val.length;

    ByteBuffer bb = ByteBuffer.allocate(bufSize + extraLen);
    assert bb.order() == ByteOrder.BIG_ENDIAN;
    bb.put(REQ_MAGIC);
    bb.put(cmd);
    bb.putShort((short) keyBytes.length);
    bb.put((byte) extraLen);
    bb.put((byte) 0);
    bb.putShort(vbucket);
    bb.putInt(keyBytes.length + val.length + extraLen);
    bb.putInt(opaque);
    bb.putLong(cas);

    if (extraHeadersLength > 0) {
      addExtraHeaders(bb, extraHeaders);
    }

    bb.put(keyBytes);
    bb.put(val);

    bb.flip();
    setBuffer(bb);
  }
1024681
public static String longToHexBytes(final long v) {
    final long mask = 0XFFL;
    final StringBuilder sb = new StringBuilder();
    for (int i = 8; i-- > 0; ) {
      final String s = Long.toHexString((v >>> (i * 8)) & mask);
      sb.append(zeroPad(s, 2)).append(" ");
    }
    return sb.toString();
  }
1087070
function buf2str(buf) {
  var CHUNKSIZE=16384;
  if (buf.length < CHUNKSIZE) {
    return String.fromCharCode.apply(String, buf);
  }
  // special case for large strings, to avoid busting the stack.
  var result = '';
  for (var i = 0; i < buf.length; i += CHUNKSIZE) {
    result += String.fromCharCode.apply(String, buf.slice(i, i+CHUNKSIZE));
  }
  return result;
}
26523
public static ByteBuffer toByteBuffer(String s) {
        ByteBuffer buffer = ByteBuffer.allocateDirect(s.length());
        buffer.put(s.getBytes(UTF_8));
        buffer.flip();
        return buffer;
    }
42117
public static ByteBuffer bytes(String s, Charset charset)
	    {
	        return ByteBuffer.wrap(s.getBytes(charset));
	    }
803210
public void toBinFile(final OutputStream out) throws IOException {
		final Charset cs = Charset.forName("UTF-8");
		final String header = String.format("%d %d\n", vocab.size(), layerSize);
		out.write(header.getBytes(cs));

		final double[] vector = new double[layerSize];
		final ByteBuffer buffer = ByteBuffer.allocate(4 * layerSize);
		buffer.order(ByteOrder.LITTLE_ENDIAN);	// The C version uses this byte order.
		for(int i = 0; i < vocab.size(); ++i) {
			out.write(String.format("%s ", vocab.get(i)).getBytes(cs));

			vectors.position(i * layerSize);
			vectors.get(vector);
			buffer.clear();
			for(int j = 0; j < layerSize; ++j)
				buffer.putFloat((float)vector[j]);
			out.write(buffer.array());

			out.write('\n');
		}

		out.flush();
	}

	/**
	 * @return {@link Word2VecModel} from the lines of the file in the text output format of the
	 * Word2Vec C open source project.
	 */
	@VisibleForTesting
	static Word2VecModel fromTextFile(String filename, List<String> lines) throws IOException {
		List<String> vocab = Lists.newArrayList();
		List<Double> vectors = Lists.newArrayList();
		int vocabSize = Integer.parseInt(lines.get(0).split(" ")[0]);
		int layerSize = Integer.parseInt(lines.get(0).split(" ")[1]);

		Preconditions.checkArgument(
				vocabSize == lines.size() - 1,
				"For file '%s', vocab size is %s, but there are %s word vectors in the file",
				filename,
				vocabSize,
				lines.size() - 1
		);

		for (int n = 1; n < lines.size(); n++) {
			String[] values = lines.get(n).split(" ");
			vocab.add(values[0]);

			// Sanity check
			Preconditions.checkArgument(
					layerSize == values.length - 1,
					"For file '%s', on line %s, layer size is %s, but found %s values in the word vector",
					filename,
					n,
					layerSize,
					values.length - 1
			);

			for (int d = 1; d < values.length; d++) {
				vectors.add(Double.parseDouble(values[d]));
			}
		}

		Word2VecModelThrift thrift = new Word2VecModelThrift()
				.setLayerSize(layerSize)
				.setVocab(vocab)
				.setVectors(vectors);
		return fromThrift(thrift);
	}

	/** @return {@link Word2VecTrainerBuilder} for training a model */
	public static Word2VecTrainerBuilder trainer() {
		return new Word2VecTrainerBuilder();
	}
}
407337
function encodeString(value) {
    let buffer = new ByteBuffer();
    if (value === null) {
        return buffer;
    }
    return buffer.writeVString(value);
}
1191774
function serializeStringFields(fields) {
  let length = 0;
  fields.forEach((field) => {
    length += (field.length + 4);
  });
  let buffer = new Buffer(4 + length);
  let offset = base_serializers.uint32(length, buffer, 0);

  fields.forEach((field) => {
    offset = base_serializers.string(field, buffer, offset);
  });
  return buffer;
}
572893
public WrappedByteBuffer put(byte[] v, int offset, int length) {
        _autoExpand(length);
        for (int i = 0; i < length; i++) {
            _buf.put(v[offset + i]);
        }
        return this;
    }
123704
public void serialize(StringBuilder buf) {
    for (CSSClass clss : store.values()) {
      clss.appendCSSDefinition(buf);
    }
  }
223064
public static void putVarLong(long v, ByteBuffer sink) {
    while (true) {
      int bits = ((int) v) & 0x7f;
      v >>>= 7;
      if (v == 0) {
        sink.put((byte) bits);
        return;
      }
      sink.put((byte) (bits | 0x80));
    }
  }