Java XML Hex readHexString(ByteBuffer buf)

Here you can find the source of readHexString(ByteBuffer buf)

Description

read Hex String

License

Apache License

Declaration

public static String readHexString(ByteBuffer buf) 

Method Source Code


//package com.java2s;
/*/*  w w w .j  a  v  a  2s  .  co  m*/
 * Copyright (C) 2015 Oleg Akimov
 *
 * 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 javax.xml.bind.DatatypeConverter;

import java.nio.ByteBuffer;

public class Main {
    public static String readHexString(ByteBuffer buf) {
        return readHexString(buf, 0);
    }

    public static String readHexString(ByteBuffer buf, int length) {
        byte[] block = new byte[length == 0 ? buf.remaining() : length];
        buf.get(block);
        return DatatypeConverter.printHexBinary(block).toUpperCase();
    }
}

Related

  1. hexStringToBytes(String text)
  2. hexToBytes(final String s)
  3. hexToString(String str)
  4. printHexBinary(byte[] in)
  5. printHexBinary(final byte[] deviceMessage)
  6. sha1Hex(final String text)
  7. sha1Hex(String data)
  8. sha1Hex(String message)
  9. stringToHex(String str)