001 /*
002 * Copyright 2008-2014 UnboundID Corp.
003 * All Rights Reserved.
004 */
005 /*
006 * Copyright (C) 2008-2014 UnboundID Corp.
007 *
008 * This program is free software; you can redistribute it and/or modify
009 * it under the terms of the GNU General Public License (GPLv2 only)
010 * or the terms of the GNU Lesser General Public License (LGPLv2.1 only)
011 * as published by the Free Software Foundation.
012 *
013 * This program is distributed in the hope that it will be useful,
014 * but WITHOUT ANY WARRANTY; without even the implied warranty of
015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
016 * GNU General Public License for more details.
017 *
018 * You should have received a copy of the GNU General Public License
019 * along with this program; if not, see <http://www.gnu.org/licenses>.
020 */
021 package com.unboundid.util;
022
023
024
025 import com.unboundid.asn1.ASN1OctetString;
026
027
028
029 /**
030 * This class provides a mechanism for creating {@code ByteString} values.
031 */
032 public final class ByteStringFactory
033 {
034 /**
035 * A pre-allocated ASN.1 octet string with no value.
036 */
037 private static final ASN1OctetString EMPTY_VALUE = new ASN1OctetString();
038
039
040
041 /**
042 * Prevent this class from being instantiated.
043 */
044 private ByteStringFactory()
045 {
046 // No implementation required.
047 }
048
049
050
051 /**
052 * Creates a new byte string with no value.
053 *
054 * @return The created byte string.
055 */
056 public static ByteString create()
057 {
058 return EMPTY_VALUE;
059 }
060
061
062
063 /**
064 * Creates a new byte string with the provided value.
065 *
066 * @param value The value to use for the byte string.
067 *
068 * @return The created byte string.
069 */
070 public static ByteString create(final byte[] value)
071 {
072 return new ASN1OctetString(value);
073 }
074
075
076
077 /**
078 * Creates a new byte string with the provided value.
079 *
080 * @param value The byte array containing the data to use for the value.
081 * It must not be {@code null}.
082 * @param offset The position in the array at which the value begins. It
083 * must be greater than or equal to zero and less or equal to
084 * the end of the array.
085 * @param length The number of bytes contained in the value. It must be
086 * greater than or equal to zero, and the sum of the offset
087 * and the length must be less than or equal to the end of the
088 * array.
089 *
090 * @return The created byte string.
091 */
092 public static ByteString create(final byte[] value, final int offset,
093 final int length)
094 {
095 return new ASN1OctetString(value, offset, length);
096 }
097
098
099
100 /**
101 * Creates a new byte string with the provided value.
102 *
103 * @param value The value to use for the byte string.
104 *
105 * @return The created byte string.
106 */
107 public static ByteString create(final String value)
108 {
109 return new ASN1OctetString(value);
110 }
111 }