Java ByteBuffer Put serializeNullableString(ByteBuffer outputBuffer, String value)

Here you can find the source of serializeNullableString(ByteBuffer outputBuffer, String value)

Description

Serializes a nullable string into byte buffer

License

Open Source License

Parameter

Parameter Description
outputBuffer The output buffer to serialize the value to
value The value to serialize

Declaration

public static void serializeNullableString(ByteBuffer outputBuffer, String value) 

Method Source Code

//package com.java2s;
/**/*w  w w. j  av  a 2 s.  c om*/
 * Copyright 2016 LinkedIn Corp. All rights reserved.
 *
 * 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.
 */

import java.nio.ByteBuffer;

public class Main {
    /**
     * Serializes a nullable string into byte buffer
     *
     * @param outputBuffer The output buffer to serialize the value to
     * @param value The value to serialize
     */
    public static void serializeNullableString(ByteBuffer outputBuffer, String value) {
        if (value == null) {
            outputBuffer.putInt(0);
        } else {
            outputBuffer.putInt(value.length());
            outputBuffer.put(value.getBytes());
        }
    }
}

Related

  1. readFully(InputStream is, ByteBuffer buffer, int nrBytes)
  2. readInto(ByteBuffer buf, InputStream inputStream)
  3. readNextLine(InputStream in, ByteBuffer buff, boolean acceptEOF, boolean requireCR)
  4. readPackedLong(ByteBuffer input)
  5. readToByteBuffer(InputStream inStream)
  6. serializeObject(Object obj, ByteBuffer buffer, ByteArrayOutputStream baos, boolean markEndOfHeader)
  7. setBit(ByteBuffer input, int pos)
  8. skipBlank(ByteBuffer input)
  9. toByteArrayInputStream(ByteBuffer buffer)