Java Byte Array Create toBytes(Object objValue)

Here you can find the source of toBytes(Object objValue)

Description

to Bytes

License

Open Source License

Parameter

Parameter Description
objValue Object

Return

long

Declaration

public static byte[] toBytes(Object objValue) 

Method Source Code

//package com.java2s;
/*//from   w  ww  .  ja  va  2 s . c  om
 * Copyright 2005-2020 GreenTube Team All rights reserved.
 * Support: Huxg
 * License: CND team license
 */

public class Main {
    /**
     *
     *
     * @param objValue Object
     *
     * @return long
     */
    public static byte[] toBytes(Object objValue) {
        if (objValue != null) {
            if (objValue instanceof byte[]) {
                return (byte[]) objValue;
            } else {
                return objValue.toString().getBytes();
            }
        } else
            return null;
    }

    /**
     * 
     *
     * @param objValue Object
     *
     * @return String
     */
    public static String toString(Object objValue) {
        if (objValue != null)
            return objValue.toString();
        else
            return null;
    }
}

Related

  1. toBytes(long value)
  2. toBytes(long value)
  3. toBytes(long value)
  4. toBytes(long value, int numBytes)
  5. toBytes(long... values)
  6. toBytes(Object value)
  7. toBytes(short s)
  8. toBytes(short s)
  9. toBytes(short sVal, byte[] bytes, boolean bigEndian)