| | |
| | | * |
| | | * |
| | | * Copyright 2009-2010 Sun Microsystems, Inc. |
| | | * Portions copyright 2011 ForgeRock AS |
| | | */ |
| | | |
| | | package com.forgerock.opendj.util; |
| | |
| | | import static org.forgerock.opendj.ldap.CoreMessages.ERR_HEX_DECODE_INVALID_LENGTH; |
| | | |
| | | import java.lang.reflect.InvocationTargetException; |
| | | import java.nio.ByteBuffer; |
| | | import java.nio.CharBuffer; |
| | | import java.nio.charset.Charset; |
| | | import java.text.ParseException; |
| | | import java.util.*; |
| | | import java.util.concurrent.Executors; |
| | |
| | | */ |
| | | public static final String EOL = System.getProperty("line.separator"); |
| | | |
| | | /** |
| | | * A zero-length byte array. |
| | | */ |
| | | public static final byte[] EMPTY_BYTES = new byte[0]; |
| | | |
| | | // The name of the time zone for universal coordinated time (UTC). |
| | | private static final String TIME_ZONE_UTC = "UTC"; |
| | | |
| | |
| | | |
| | | /** |
| | | * Construct a byte array containing the UTF-8 encoding of the provided |
| | | * character array. |
| | | * |
| | | * @param chars |
| | | * The character array to convert to a UTF-8 byte array. |
| | | * @return A byte array containing the UTF-8 encoding of the provided |
| | | * character array. |
| | | */ |
| | | public static byte[] getBytes(final char[] chars) |
| | | { |
| | | final Charset utf8 = Charset.forName("UTF-8"); |
| | | final ByteBuffer buffer = utf8.encode(CharBuffer.wrap(chars)); |
| | | final byte[] bytes = new byte[buffer.remaining()]; |
| | | buffer.get(bytes); |
| | | return bytes; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Construct a byte array containing the UTF-8 encoding of the provided |
| | | * string. This is significantly faster than calling |
| | | * {@link String#getBytes(String)} for ASCII strings. |
| | | * |
| | |
| | | |
| | | |
| | | /** |
| | | * Returns a copy of the provided byte array. |
| | | * |
| | | * @param bytes |
| | | * The byte array to be copied. |
| | | * @return A copy of the provided byte array. |
| | | */ |
| | | public static byte[] copyOfBytes(final byte[] bytes) |
| | | { |
| | | return Arrays.copyOf(bytes, bytes.length); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Retrieves the printable ASCII representation of the provided byte. |
| | | * |
| | | * @param b |