001/* 002 * Copyright 2008-2024 Ping Identity Corporation 003 * All Rights Reserved. 004 */ 005/* 006 * Copyright 2008-2024 Ping Identity Corporation 007 * 008 * Licensed under the Apache License, Version 2.0 (the "License"); 009 * you may not use this file except in compliance with the License. 010 * You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, software 015 * distributed under the License is distributed on an "AS IS" BASIS, 016 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 017 * See the License for the specific language governing permissions and 018 * limitations under the License. 019 */ 020/* 021 * Copyright (C) 2008-2024 Ping Identity Corporation 022 * 023 * This program is free software; you can redistribute it and/or modify 024 * it under the terms of the GNU General Public License (GPLv2 only) 025 * or the terms of the GNU Lesser General Public License (LGPLv2.1 only) 026 * as published by the Free Software Foundation. 027 * 028 * This program is distributed in the hope that it will be useful, 029 * but WITHOUT ANY WARRANTY; without even the implied warranty of 030 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 031 * GNU General Public License for more details. 032 * 033 * You should have received a copy of the GNU General Public License 034 * along with this program; if not, see <http://www.gnu.org/licenses>. 035 */ 036package com.unboundid.util; 037 038 039 040import java.io.Serializable; 041 042import com.unboundid.asn1.ASN1OctetString; 043 044 045 046/** 047 * This interface defines a set of methods for treating a value as either a 048 * string or byte array. 049 */ 050@NotExtensible() 051@ThreadSafety(level=ThreadSafetyLevel.INTERFACE_THREADSAFE) 052public interface ByteString 053 extends Serializable 054{ 055 /** 056 * Retrieves a byte array containing the binary value for this byte string. 057 * 058 * @return A byte array containing the binary value for this byte string. 059 */ 060 @NotNull() 061 byte[] getValue(); 062 063 064 065 /** 066 * Retrieves the value for this byte string as a {@code String}. 067 * 068 * @return The value for this byte string as a {@code String}. 069 */ 070 @NotNull() 071 String stringValue(); 072 073 074 075 /** 076 * Appends the value of this byte string to the provided buffer. It must not 077 * use the {@link ByteStringBuffer#append(ByteString)} method, since that 078 * method relies on this method. 079 * 080 * @param buffer The buffer to which the value should be appended. 081 */ 082 void appendValueTo(@NotNull ByteStringBuffer buffer); 083 084 085 086 /** 087 * Converts this byte string to an ASN.1 octet string. 088 * 089 * @return An ASN.1 octet string with the value of this byte string. 090 */ 091 @NotNull() 092 ASN1OctetString toASN1OctetString(); 093}