/** * Decodes the input base64 encoded String. * The resulting binary data is returned as an array of bytes. * * @param encodedString The base64 encoded String object. * * @return The decoded byte array. */ public static final byte[] decode(String encodedString) { char[] c = new char[encodedString.length()]; encodedString.getChars(0, encodedString.length(), c, 0); return decode(c); }
private String byte2String(byte[] value) { String text = null; if (Base64.isValidUTF8(value, false)){ try { text = new String(value, "UTF-8"); } catch (UnsupportedEncodingException uee) { throw new RuntimeException( "UTF-8 not supported by JVM" + uee); } } else { text = Base64.encode(value); } return text; }
int count = getByteCount(array[index]); if (count == 0){
/** * Write the DN to the outputStream. If the DN characters are unsafe, * the DN is encoded. * * @param dn the DN to write */ private void writeDN(String dn) throws IOException { writeLine(Base64.isLDIFSafe(dn)? "dn: "+dn: "dn:: "+ Base64.encode(dn)); return; }
/** * Encodes the specified String into a base64 encoded String object. * * @param inputString The String object to be encoded. * * @return a String containing the encoded value of the input. */ public static final String encode(String inputString) { try { return encode(inputString.getBytes("UTF-8")); } catch( UnsupportedEncodingException ue) { throw new RuntimeException( "US-ASCII String encoding not supported by JVM"); } }
if (com.novell.ldap.util.Base64.isValidUTF8(value, true)) { try { toReturn = new String(value, "UTF-8");
return( isLDIFSafe(str.getBytes("UTF-8"))); } catch( UnsupportedEncodingException ue) { throw new RuntimeException(
/** * Write attribute name and value into outputStream. * * <p>Check if attrVal starts with NUL, LF, CR, ' ', ':', or '<' * or contains any NUL, LF, or CR, and then write it out</p> */ private void writeAttribute(String attrName, String attrVal) throws IOException { if (attrVal != null) { writeLine( Base64.isLDIFSafe(attrVal)? attrName + ": " + attrVal : attrName + ":: " + Base64.encode(attrVal) ); } return; }
private void writeControls(Element e, LDAPControl[] controls) { for (int i=0; i< controls.length; i++){ Element el = doc.createElement("control"); el.setAttribute("NumericOID", controls[i].getID()); el.setAttribute("criticality", ""+controls[i].isCritical()); byte byteValue[] = controls[i].getValue(); if (byteValue!= null){ Element value = doc.createElement("controlValue"); value.setAttribute("xsi:type", "base64Binary"); Text text = doc.createTextNode( Base64.encode(byteValue)); value.appendChild(text); el.appendChild(value); } e.appendChild( el ); } }
private static String byteString(byte[] value) { String toReturn = null; if (com.novell.ldap.util.Base64.isValidUTF8(value, true)) { try { toReturn = new String(value, "UTF-8"); } catch (UnsupportedEncodingException e) { throw new RuntimeException( "Default JVM does not support UTF-8 encoding" + e); } } else { StringBuffer binary = new StringBuffer(); for (int i=0; i<value.length; i++){ //TODO repair binary output //Every octet needs to be escaped if (value[i] >=0) { //one character hex string binary.append("\\0"); binary.append(Integer.toHexString(value[i])); } else { //negative (eight character) hex string binary.append("\\"+ Integer.toHexString(value[i]).substring(6)); } } toReturn = binary.toString(); } return toReturn; }
protected void writeValue(java.io.Writer out) throws IOException { String values[] = getStringValueArray(); byte bytevalues[][] = getByteValueArray(); for(int i=0; i<values.length; i++){ newLine(2,out); if (Base64.isValidUTF8(bytevalues[i], false)){ out.write("<value>"); out.write(values[i]); out.write("</value>"); } else { out.write("<value xsi:type=\"xsd:base64Binary\">"); out.write(Base64.encode(bytevalues[i])); out.write("</value>"); } } }
/** * Write attribute name and value into outputStream. * * <p>Check if attribute value contains NON-SAFE-INIT-CHAR or * NON-SAFE-CHAR. if it does, it needs to be base64 encoded and then * write it out</p> */ private void writeAttribute(String attrName, byte[] attrVal) throws IOException { if (attrVal != null) { writeLine( (Base64.isLDIFSafe(attrVal) && isPrintable(attrVal))? attrName + ": " + new String(attrVal, "UTF-8"): attrName + ":: " + Base64.encode(attrVal) ); } return; }
private void writeControl(LDAPControl control, StringBuffer buff) throws java.io.IOException { buff.append("<control type=\""); buff.append(control.getID()); buff.append("\" criticality=\""+ control.isCritical()+ "\""); byte value[] = control.getValue(); if (value == null){ buff.append("/>"); } else { buff.append(">"); buff.append(ValueXMLhandler.newLine(2)); buff.append("<controlValue xsi:type=\"xsd:base64Binary\">"); buff.append(Base64.encode(value)); buff.append("</controlValue>"); buff.append(ValueXMLhandler.newLine(1)); buff.append("</control>"); } buff.append(ValueXMLhandler.newLine(0)); }
/** * 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; }
if (com.novell.ldap.util.Base64.isValidUTF8(value, true)) { try { toReturn = new String(value, "UTF-8");
protected void writeValue(StringBuffer buff){ String values[] = getStringValueArray(); byte bytevalues[][] = getByteValueArray(); for(int i=0; i<values.length; i++){ buff.append(ValueXMLhandler.newLine(2)); if (Base64.isValidUTF8(bytevalues[i], false)){ buff.append("<value>"); buff.append(values[i]); buff.append("</value>"); } else { buff.append("<value xsi:type=\"xsd:base64Binary\">"); buff.append(Base64.encode(bytevalues[i])); buff.append("</value>"); } } }
writeLine( Base64.isLDIFSafe(newRDN)? "newrdn: " + newRDN: "newrdn:: " + Base64.encode(newRDN)); writeLine( Base64.isLDIFSafe(newSuperior)? "newsuperior: " + newSuperior: "newsuperior:: " + Base64.encode(newSuperior));
/** * This method does DSML serialization of the instance. * * @param oout Outputstream where the serialzed data has to be written * * @throws IOException if write fails on OutputStream */ public void writeDSML(java.io.OutputStream oout) throws java.io.IOException { java.io.Writer out=new java.io.OutputStreamWriter(oout,"UTF-8"); out.write("<LDAPExtendedOperation>"); newLine(1,out); out.write("<requestName>"); out.write(getID()); out.write("</requestName>"); byte[] vals=getValue(); if( vals != null) { newLine(1,out); out.write("<requestValue xsi:type=\"xsd:base64Binary\">"); out.write(Base64.encode(vals)); out.write("</requestValue>"); } newLine(0,out); out.write("</LDAPExtendedOperation>"); out.close(); } /**
/** * 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; }
private void writeAttribute(Element attribute, LDAPAttribute attr) { attribute.setAttribute("name", attr.getName()); String values[] = attr.getStringValueArray(); byte bytevalues[][] = attr.getByteValueArray(); for(int i=0; i<values.length; i++){ Element value = doc.createElement("value"); if (Base64.isValidUTF8(bytevalues[i], false)){ value.appendChild(doc.createTextNode(values[i])); } else { value.setAttribute("xsi:type", "base64Binary"); value.appendChild(doc.createTextNode( Base64.encode(bytevalues[i]))); } attribute.appendChild(value); } }