Java Byte Array to String by Charset getRowId(final byte[] rowId, final Charset charset, final boolean base64encodeValues)

Here you can find the source of getRowId(final byte[] rowId, final Charset charset, final boolean base64encodeValues)

Description

get Row Id

License

Apache License

Parameter

Parameter Description
rowId the row id to get the string from
charset the charset that was used to encode the cell's row
base64encodeValues whether or not to base64 encode the returned string

Return

the String representation of the cell's row

Declaration

public static String getRowId(final byte[] rowId, final Charset charset, final boolean base64encodeValues) 

Method Source Code

//package com.java2s;
/**/*from  www .  j  av  a 2 s  .c o m*/
 * Copyright (C) 2016 Hurence (support@hurence.com)
 *
 * 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;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.Base64;

public class Main {
    /**
     * @param rowId the row id to get the string from
     * @param charset the charset that was used to encode the cell's row
     * @param base64encodeValues whether or not to base64 encode the returned string
     *
     * @return the String representation of the cell's row
     */
    public static String getRowId(final byte[] rowId, final Charset charset, final boolean base64encodeValues) {
        if (base64encodeValues) {
            ByteBuffer cellRowBuffer = ByteBuffer.wrap(rowId);
            ByteBuffer base64Buffer = Base64.getEncoder().encode(cellRowBuffer);
            return new String(base64Buffer.array(), StandardCharsets.UTF_8);
        } else {
            return new String(rowId, charset);
        }
    }
}

Related

  1. getChars(byte[] data, String charset)
  2. getContentAsString(byte[] content, Charset charset)
  3. getMaxBytes(String string, int maxBytes, Charset charSet)
  4. getNumberOfBytesPerCharacter(final String charsetName)
  5. getPrefixWithMaxBytes(String string, int maxBytes, Charset charSet)
  6. getString(@Nonnull byte[] b, @Nonnegative int bufferSize, @Nonnegative int offset, @Nonnull Charset charset)
  7. getString(byte[] bytes, String charset)
  8. getString(byte[] bytesIn, Charset cs)
  9. identify(byte[] bytes, CharsetDecoder decoder)