Java Byte Array from getBytes(byte[] buffer, int offset)

Here you can find the source of getBytes(byte[] buffer, int offset)

Description

get Bytes

License

Apache License

Declaration

public static byte[] getBytes(byte[] buffer, int offset) 

Method Source Code

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

import java.io.UnsupportedEncodingException;

public class Main {
    public static byte[] getBytes(byte[] buffer, int offset) {
        byte[] b = new byte[buffer.length - offset];
        System.arraycopy(buffer, offset, b, 0, buffer.length - offset);
        return b;
    }/*w  w w .j  av  a2  s.c om*/

    public static byte[] getBytes(byte[] buffer, int offset, int length) {
        byte[] b = new byte[length];
        System.arraycopy(buffer, offset, b, 0, length);
        return b;
    }

    public static byte[] getBytes(int value, byte[] dest) {
        int lastIndex = dest.length - 1;
        for (int i = lastIndex; i >= 0; i--) {
            dest[i] = (byte) (value & 0xff);
            value = value >> 8;
        }
        return dest;
    }

    public static byte[] getBytes(long value, byte[] dest) {
        int lastIndex = dest.length - 1;
        for (int i = lastIndex; i >= 0; i--) {
            dest[i] = (byte) (value & 0xff);
            value = value >> 8;
        }
        return dest;
    }

    public static byte[] getBytes(String s) {
        return s.getBytes();
    }

    public static byte[] getBytes(String s, String encoding) throws UnsupportedEncodingException {
        if (encoding != null) {
            return s.getBytes(encoding);
        }

        return s.getBytes();
    }
}

Related

  1. getBytes(byte value)
  2. getBytes(Class clazz)
  3. getBytes(Class clazz)
  4. getBytes(Class cls, String resourceName)
  5. getBytes(final InputStream is)