Writes a single byte as raw character data into the specified buffer. - Java java.nio

Java examples for java.nio:ByteBuffer Int

Description

Writes a single byte as raw character data into the specified buffer.

Demo Code

/*//from   w ww  .j  a  va 2 s .c om
 * Copyright The Sett Ltd, 2005 to 2014.
 *
 * 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.
 */
//package com.java2s;
import java.nio.ByteBuffer;

public class Main {
    /**
     * Writes a single byte as raw character data into the specified buffer. The buffer is increased in size using the
     * supplied buffer pool, if needed.
     *
     * @param  buffer The byte buffer to write to.
     * @param  value  The value to write.
     *
     * @return The byte buffer with the value written to it. This may be a different buffer to the one passed in if the
     *         buffer had to be copied in order to increase its size.
     */
    public static ByteBuffer putByteAsString(ByteBuffer buffer, byte value) {
        buffer.put(value);

        return buffer;
    }
}

Related Tutorials