Converts a char into a byte array.

@param c
a char
@param bo
a ByteOrder
@return byte array
519942
public static byte[] toByteArray(char c, ByteOrder bo) {
    return ByteBuffer.allocate(2).order(bo).putChar(c).array();
  }
1075755
public static byte[] toByteArray(InputStream is) throws IOException {
		ByteArrayOutputStream bao = new ByteArrayOutputStream();
		IO.copyAndCloseBoth(is, bao);
		return bao.toByteArray();
	}
488654
private static byte[] bufferToArray(final ByteBuffer body) {
    if (body.position() > 0) {
      body.flip();
    }
    final int length = body.limit();
    final byte[] bytes = new byte[length];
    System.arraycopy(body.array(), 0, bytes, 0, length);
    return bytes;
  }
364762
function chars_to_bytes(ac) {
        var retval = []
        for (var i = 0; i < ac.length; i++) {
            retval = retval.concat(str_to_bytes(ac[i]))
        }
        return retval
    }
1043968
public static byte[] getBytes(Object o)
    {
        if (o != null)
        {
            return getBytes(o, o.getClass());
        }

        return null;
    }
567791
public static byte[] toBytes(ByteBuffer bb) {
    int length = bb.limit();
    byte [] result = new byte[length];
    System.arraycopy(bb.array(), bb.arrayOffset(), result, 0, length);
    return result;
  }
354791
public static byte[] toBytes(char[] chars) {
        final CharBuffer charBuffer = CharBuffer.wrap(chars);
        final ByteBuffer byteBuffer = Charset.forName("UTF-8").encode(charBuffer);
        final byte[] bytes = Arrays.copyOfRange(byteBuffer.array(), byteBuffer.position(), byteBuffer.limit());
        Arrays.fill(charBuffer.array(), '\u0000'); // clear sensitive data
        Arrays.fill(byteBuffer.array(), (byte) 0); // clear sensitive data
        return bytes;
    }
285322
private char[] encode(byte[] data) {
        char[] out = new char[((data.length + 2) / 3) * 4];
        char[] alphabet = SESSION_ID_ALPHABET;
        //
        // 3 bytes encode to 4 chars.  Output is always an even
        // multiple of 4 characters.
        //
        for (int i = 0, index = 0; i < data.length; i += 3, index += 4) {
            boolean quad = false;
            boolean trip = false;

            int val = (0xFF & (int) data[i]);
            val <<= 8;
            if ((i + 1) < data.length) {
                val |= (0xFF & (int) data[i + 1]);
                trip = true;
            }
            val <<= 8;
            if ((i + 2) < data.length) {
                val |= (0xFF & (int) data[i + 2]);
                quad = true;
            }
            out[index + 3] = alphabet[(quad ? (val & 0x3F) : 63)];
            val >>= 6;
            out[index + 2] = alphabet[(trip ? (val & 0x3F) : 63)];
            val >>= 6;
            out[index + 1] = alphabet[val & 0x3F];
            val >>= 6;
            out[index] = alphabet[val & 0x3F];
        }
        return out;
    }
1149757
public static byte[] toByteArray(final ByteString bs) {
    return bs == null || bs.isEmpty() ? null : bs.toByteArray();
  }
749980
private static long byteArrayToLong(byte[] ba, int offset) {
		long l = 0;

		for (int i = 0; i < SIZE_OF_LONG; ++i) {
			l |= (ba[offset + SIZE_OF_LONG - 1 - i] & 0xffL) << (i << 3);
		}

		return l;
	}
1196716
private static final String toSimpleString(byte[] b) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0, len = b.length; i < len; i++) {
            sb.append((char) (b[i] & 0xff));
        }
        String str = sb.toString();
        return str;
    }
134819
public static char[] bytesToCharArrayUTFNIO(byte[] buffer) {
        ByteBuffer byteBuffer = ByteBuffer.wrap(buffer);
        CharBuffer charBuffer = Charset.forName(ENCODING).decode(byteBuffer);
        try {
            return charBufferToChars(charBuffer);
        } finally {
            eraseCharBuffer(charBuffer);
        }
    }
41026
@VisibleForTesting
	static byte[] ascii8To6bitBin(byte[] toDecBytes) {

		byte[] convertedBytes = new byte[toDecBytes.length];
		int sum = 0;
		int _6bitBin = 0;

		for (int i = 0; i < toDecBytes.length; i++) {
			sum = 0;
			_6bitBin = 0;

			if (toDecBytes[i] < 48) {
				throw new AisParseException(AisParseException.INVALID_CHARACTER + " "
				        + (char) toDecBytes[i]);
			} else {
				if (toDecBytes[i] > 119) {
					throw new AisParseException(AisParseException.INVALID_CHARACTER + " "
					        + (char) toDecBytes[i]);
				} else {
					if (toDecBytes[i] > 87) {
						if (toDecBytes[i] < 96) {
							throw new AisParseException(AisParseException.INVALID_CHARACTER + " "
							        + (char) toDecBytes[i]);
						} else {
							sum = toDecBytes[i] + 40;
						}
					} else {
						sum = toDecBytes[i] + 40;
					}
					if (sum != 0) {
						if (sum > 128) {
							sum += 32;
						} else {
							sum += 40;
						}
						_6bitBin = sum & 0x3F;
						convertedBytes[i] = (byte) _6bitBin;
					}
				}
			}
		}

		return convertedBytes;
	}
40640
final byte[] decodeChecked(CharSequence chars)
      throws DecodingException {
    chars = padding().trimTrailingFrom(chars);
    byte[] tmp = new byte[maxDecodedSize(chars.length())];
    int len = decodeTo(tmp, chars);
    return extract(tmp, len);
  }
893090
public static String byteArrayToString(byte[] b) {
       final int l = b.length/2;
       if (l*2 != b.length) throw new IllegalArgumentException();
       StringBuffer result = new StringBuffer(l);
       int o = 0;
       for (int i = 0; i < l; i++)
       {
           int i1 = b[o++] & 0xff;
           int i2 = b[o++] & 0xff;
           i2 = i2 << 8;
           i1 = i1 | i2;
           result.append((char)i1);
       }
       return (result.toString());
    }
1177543
public static byte[] toBytes(BaseBo bo) {
        if (bo == null) {
            return null;
        }
        String clazz = bo.getClass().getName();
        Map<String, Object> data = new HashMap<>();
        data.put(FIELD_CLASSNAME, clazz);
        data.put(FIELD_BODATA, bo.toBytes());
        return SerializationUtils.toByteArray(data);
    }
791394
byte[] convertToBytes(int char1) {
        if (directTextToByte)
            return PdfEncodings.convertToBytes((char)char1, null);
        if (specialMap != null) {
            if (specialMap.containsKey(char1))
                return new byte[]{(byte)specialMap.get(char1)};
            else
                return new byte[0];
        }
        return PdfEncodings.convertToBytes((char)char1, encoding);
    }