/** * Adds a byte-formatted value to the attribute. * * @param attrBytes Value of the attribute as raw bytes. * * <P> Note: If attrBytes represents a string it should be UTF-8 encoded. * * @throws IllegalArgumentException if attrBytes is null */ public void addValue(byte[] attrBytes) { if( attrBytes == null) { throw new IllegalArgumentException("Attribute value cannot be null"); } this.add(attrBytes); return; }
/** * Replaces all values with the specified value. This protected method is * used by sub-classes of LDAPSchemaElement because the value cannot be set * with a contructor. */ protected void setValue(String value){ values = null; try { this.add( value.getBytes( "UTF-8" ) ); } catch( UnsupportedEncodingException ue ) { throw new RuntimeException( ue.toString()); } return; }
/** * Constructs an attribute with a byte-formatted value. * * @param attrName Name of the attribute.<br><br> * @param attrBytes Value of the attribute as raw bytes. * * <P> Note: If attrBytes represents a string it should be UTF-8 encoded. * * @throws IllegalArgumentException if attrName or attrBytes is null */ public LDAPAttribute( String attrName, byte[] attrBytes ) { this( attrName ); if( attrBytes == null) { throw new IllegalArgumentException("Attribute value cannot be null"); } // Make our own copy of the byte array to prevent app from changing it byte[] tmp = new byte[attrBytes.length]; System.arraycopy( attrBytes, 0, tmp, 0, attrBytes.length ); this.add( tmp); return; }
/** * Adds a string value to the attribute. * * @param attrString Value of the attribute as a String. * * @throws IllegalArgumentException if attrString is null */ public void addValue(String attrString) { if( attrString == null) { throw new IllegalArgumentException("Attribute value cannot be null"); } try { this.add( attrString.getBytes( "UTF-8" ) ); } catch( UnsupportedEncodingException ue ) { throw new RuntimeException( ue.toString()); } return; }
/** * Constructs an attribute with a single string value. * * @param attrName Name of the attribute.<br><br> * @param attrString Value of the attribute as a string. * * @throws IllegalArgumentException if attrName or attrString is null */ public LDAPAttribute(String attrName, String attrString) { this( attrName ); if( attrString == null) { throw new IllegalArgumentException("Attribute value cannot be null"); } try { this.add( attrString.getBytes( "UTF-8" ) ); } catch( UnsupportedEncodingException e ){ throw new RuntimeException( e.toString()); } return; }
/** * Constructs an attribute with an array of string values. * * @param attrName Name of the attribute.<br><br> * @param attrStrings Array of values as strings. * * @throws IllegalArgumentException if attrName, attrStrings, or a member * of attrStrings is null */ public LDAPAttribute(String attrName, String[] attrStrings) { this( attrName ); if( attrStrings == null) { throw new IllegalArgumentException("Attribute values array cannot be null"); } for( int i = 0, u = attrStrings.length; i < u; i++) { try { if( attrStrings[ i ] == null) { throw new IllegalArgumentException("Attribute value " + "at array index " + i + " cannot be null"); } this.add( attrStrings[ i ].getBytes( "UTF-8" ) ); } catch( UnsupportedEncodingException e ){ throw new RuntimeException( e.toString()); } } return; }
/** * Adds a base64 encoded value to the attribute. * The value will be decoded and stored as bytes. String * data encoded as a base64 value must be UTF-8 characters. * * @param attrString The base64 value of the attribute as a String. * * @throws IllegalArgumentException if attrString is null */ public void addBase64Value(String attrString) { if( attrString == null) { throw new IllegalArgumentException("Attribute value cannot be null"); } this.add( Base64.decode(attrString)); return; }
/** * Adds a base64 encoded value to the attribute. * The value will be decoded and stored as bytes. Character * data encoded as a base64 value must be UTF-8 characters. * * @param attrChars The base64 value of the attribute as an array of * characters. * * @throws IllegalArgumentException if attrString is null */ public void addBase64Value(char[] attrChars) { if( attrChars == null) { throw new IllegalArgumentException("Attribute value cannot be null"); } this.add( Base64.decode(attrChars)); return; }
/** * Adds a base64 encoded value to the attribute. * The value will be decoded and stored as bytes. Character * data encoded as a base64 value must be UTF-8 characters. * * @param attrString The base64 value of the attribute as a StringBuffer. * @param start The start index of base64 encoded part, inclusive. * @param end The end index of base encoded part, exclusive. * * @throws IllegalArgumentException if attrString is null */ public void addBase64Value(StringBuffer attrString, int start, int end) { if( attrString == null) { throw new IllegalArgumentException("Attribute value cannot be null"); } this.add( Base64.decode(attrString, start, end)); return; }
offset += len; this.add( data); } catch( UnsupportedEncodingException ue ) { throw new RuntimeException( ue.toString());