Java Byte Array Create toByteArray(final char[] array)

Here you can find the source of toByteArray(final char[] array)

Description

to Byte Array

License

Open Source License

Declaration

public static byte[] toByteArray(final char[] array) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    public static byte[] toByteArray(final char[] array) {
        return toByteArray(array, 0, array.length);
    }/*from   w  w w. j a v  a2  s. co m*/

    public static byte[] toByteArray(final char[] array, final int off, final int len) {
        return toByteArray(array, off, len, new byte[len], 0);
    }

    public static byte[] toByteArray(final char[] from, final int fromOff, final int len, final byte[] to,
            final int toOff) {
        final int end = fromOff + len;

        for (int i = fromOff, j = toOff; i < end; i++, j++) {
            to[j] = (byte) from[i];
        }

        return to;
    }

    public static byte[] toByteArray(final short[] array) {
        return toByteArray(array, 0, array.length);
    }

    public static byte[] toByteArray(final short[] array, final int off, final int len) {
        return toByteArray(array, off, len, new byte[len], 0);
    }

    public static byte[] toByteArray(final short[] from, final int fromOff, final int len, final byte[] to,
            final int toOff) {
        final int end = fromOff + len;

        for (int i = fromOff, j = toOff; i < end; i++, j++) {
            to[j] = (byte) from[i];
        }

        return to;
    }

    public static byte[] toByteArray(final int[] array) {
        return toByteArray(array, 0, array.length);
    }

    public static byte[] toByteArray(final int[] array, final int off, final int len) {
        return toByteArray(array, off, len, new byte[len], 0);
    }

    public static byte[] toByteArray(final int[] from, final int fromOff, final int len, final byte[] to,
            final int toOff) {
        final int end = fromOff + len;

        for (int i = fromOff, j = toOff; i < end; i++, j++) {
            to[j] = (byte) from[i];
        }

        return to;
    }

    public static byte[] toByteArray(final long[] array) {
        return toByteArray(array, 0, array.length);
    }

    public static byte[] toByteArray(final long[] array, final int off, final int len) {
        return toByteArray(array, off, len, new byte[len], 0);
    }

    public static byte[] toByteArray(final long[] from, final int fromOff, final int len, final byte[] to,
            final int toOff) {
        final int end = fromOff + len;

        for (int i = fromOff, j = toOff; i < end; i++, j++) {
            to[j] = (byte) from[i];
        }

        return to;
    }

    public static byte[] toByteArray(final float[] array) {
        return toByteArray(array, 0, array.length);
    }

    public static byte[] toByteArray(final float[] array, final int off, final int len) {
        return toByteArray(array, off, len, new byte[len], 0);
    }

    public static byte[] toByteArray(final float[] from, final int fromOff, final int len, final byte[] to,
            final int toOff) {
        final int end = fromOff + len;

        for (int i = fromOff, j = toOff; i < end; i++, j++) {
            to[j] = (byte) from[i];
        }

        return to;
    }

    public static byte[] toByteArray(final double[] array) {
        return toByteArray(array, 0, array.length);
    }

    public static byte[] toByteArray(final double[] array, final int off, final int len) {
        return toByteArray(array, off, len, new byte[len], 0);
    }

    public static byte[] toByteArray(final double[] from, final int fromOff, final int len, final byte[] to,
            final int toOff) {
        final int end = fromOff + len;

        for (int i = fromOff, j = toOff; i < end; i++, j++) {
            to[j] = (byte) from[i];
        }

        return to;
    }
}

Related

  1. toByteArray(CharSequence hexString)
  2. toByteArray(double[][] array)
  3. toByteArray(final byte[] bytes)
  4. toByteArray(final byte[][] array)
  5. toByteArray(final char[] array)
  6. toByteArray(final int i)
  7. toByteArray(final int i)
  8. toByteArray(final int i, final byte[] output, final int offset)
  9. toByteArray(final int value)