Java ByteBuffer Write writeString(ByteBuffer buf, String str)

Here you can find the source of writeString(ByteBuffer buf, String str)

Description

write String

License

Apache License

Declaration

public static void writeString(ByteBuffer buf, String str) 

Method Source Code


//package com.java2s;
/*//from   www  . ja va  2s  .c o  m
 * Copyright 2011 sonikhak <https://github.com/sonikhak>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import java.nio.ByteBuffer;

public class Main {
    public static void writeString(ByteBuffer buf, String str) {
        int len = str.length();
        buf.putShort((short) len);
        for (int i = 0; i < len; i++) {
            buf.putChar(str.charAt(i));
        }
    }
}

Related

  1. writeSign(ByteBuffer bb)
  2. writeSignedVarint(ByteBuffer buffer, int val)
  3. writeSize(final int s, ByteBuffer buffer)
  4. writeSlice(ByteBuffer src, int number, ByteBuffer dst)
  5. writeString(ByteBuffer buf, String s)
  6. writeString(ByteBuffer buf, String value)
  7. writeString(ByteBuffer buffer, String string)
  8. writeString(ByteBuffer byteBuffer, String str)
  9. writeString(final String text, final ByteBuffer out)