Java ByteBuffer Write writeHexString(ByteBuffer buffer, String hex)

Here you can find the source of writeHexString(ByteBuffer buffer, String hex)

Description

write Hex String

License

Apache License

Declaration

public static void writeHexString(ByteBuffer buffer, String hex) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.nio.ByteBuffer;

public class Main {
    public static void writeHexString(ByteBuffer buffer, String hex) {
        byte[] bytes = hexStringToBytes(hex);
        for (int i = bytes.length - 1; i >= 0; i--) {
            buffer.put(bytes[i]);/*from   w w  w.j a v  a  2  s. c  o  m*/
        }
    }

    public static byte[] hexStringToBytes(String hex) {
        byte[] result = new byte[hex.length() / 2];
        for (int i = 0; i < result.length; i++) {
            result[i] = (byte) Integer.parseInt(hex.substring(i * 2, i * 2 + 2), 16);
        }
        return result;
    }
}

Related

  1. writeFully(WritableByteChannel bc, ByteBuffer buf)
  2. writeFully(WritableByteChannel channel, ByteBuffer[] srcs)
  3. writeHalf(final ByteBuffer buf, final int value)
  4. writeHeader(int type, ByteBuffer lengthBuffer, ByteBuffer buffer)
  5. writeHeaderAndLsd(ByteBuffer out, int width, int height, boolean hasGct, int gctSize)
  6. writeHexString(ByteBuffer buffer, String hexStr)
  7. writeImageDescriptor(ByteBuffer out, int imageLeft, int imageTop, int imageWidth, int imageHeight, boolean hasLct, int numColors)
  8. writeInt(ByteBuffer buf, int pos, int v)
  9. writeInt(ByteBuffer logBuf, int i)