/** * 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"); } }
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; }
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 ); } }
/** * 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; }
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>"); } } }
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>"); } } }
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); } }
/** * 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 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)); }
/** * 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(); } /**
private void writeAttribute(LDAPAttribute attr, StringBuffer buff) throws java.io.IOException { buff.append(ValueXMLhandler.newLine(1)); buff.append("<attr name=\""); buff.append(attr.getName()); buff.append("\">"); String values[] = attr.getStringValueArray(); byte bytevalues[][] = attr.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>"); } } buff.append(ValueXMLhandler.newLine(1)); buff.append("</attr>"); }
private void writeAttribute(LDAPAttribute attr, StringBuffer buff) throws java.io.IOException { buff.append(ValueXMLhandler.newLine(2)); buff.append("<attr name=\""); buff.append(attr.getName()); buff.append("\">"); String values[] = attr.getStringValueArray(); byte bytevalues[][] = attr.getByteValueArray(); for(int i=0; i<values.length; i++){ buff.append(ValueXMLhandler.newLine(3)); if (Base64.isValidUTF8(bytevalues[i], false)){ buff.append("<value><![CDATA["); buff.append(values[i]); buff.append("]]></value>"); } else { buff.append("<value xsi:type=\"xsd:base64Binary\"><![CDATA["); buff.append(Base64.encode(bytevalues[i])); buff.append("]]></value>"); } } buff.append(ValueXMLhandler.newLine(2)); buff.append("</attr>"); }
private void writeAttribute(LDAPAttribute attr, StringBuffer buff) throws java.io.IOException { buff.append(ValueXMLhandler.newLine(1)); buff.append("<attr name=\""); buff.append(attr.getName()); buff.append("\">"); String values[] = attr.getStringValueArray(); byte bytevalues[][] = attr.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>"); } } buff.append(ValueXMLhandler.newLine(1)); buff.append("</attr>"); }
/** * 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; }
/** * Writes a control in DSML. * <p>Used by writeResult and by the searchResponse case in writeMessage. * @param controls Controls to be written * @param indent Size of indentation for writting. */ private void writeControls(LDAPControl[] controls, int indent) throws IOException { for(int i=0; i<controls.length; i++){ newLine(indent); out.write("<control type=\""); out.write(controls[i].getID()); out.write("\" criticality=\""+controls[i].isCritical()+ "\""); byte value[] = controls[i].getValue(); if (value == null){ out.write(" / >"); } else { out.write(">"); newLine(indent+1); out.write("<controlValue xsi:type=\"xsd:base64Binary\">"); out.write(Base64.encode(value)); out.write("</controlValue>"); newLine(indent); out.write("</control>"); } } return; }
private void writeAttribute(LDAPAttribute attr,java.io.Writer out) throws java.io.IOException { newLine(2,out); out.write("<attr name=\""); out.write(attr.getName()); out.write("\">"); String values[] = attr.getStringValueArray(); byte bytevalues[][] = attr.getByteValueArray(); for(int i=0; i<values.length; i++){ newLine(3,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>"); } } newLine(2,out); out.write("</attr>"); }
private void writeAttribute(LDAPAttribute attr,java.io.Writer out) throws java.io.IOException { newLine(1,out); out.write("<attr name=\""); out.write(attr.getName()); out.write("\">"); String values[] = attr.getStringValueArray(); byte bytevalues[][] = attr.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>"); } } newLine(1,out); out.write("</attr>"); }
/** * Used to write an attribute and its values. * @param attr Attribute to be written. */ private void writeAttribute(LDAPAttribute attr) throws IOException { newLine(3); out.write("<attr name=\""); out.write(attr.getName()); out.write("\">"); String values[] = attr.getStringValueArray(); byte bytevalues[][] = attr.getByteValueArray(); for(int i=0; i<values.length; i++){ newLine(4); if (Base64.isValidUTF8(bytevalues[i],true) && this.isXMLSafe(bytevalues[i])){ out.write("<value>"); String xmlvalue = makeAttributeSafe(values[i]); out.write(xmlvalue); out.write("</value>"); } else { out.write("<value xsi:type=\"xsd:base64Binary\">"); out.write(Base64.encode(bytevalues[i])); out.write("</value>"); } } newLine(3); out.write("</attr>"); return; }
private void writeExtendedRequestEntry( LDAPExtendedRequest request, LDAPControl[] controls, String requestID) throws IOException, LDAPLocalException { checkState(false); newLine(2); out.write("<requestName>"); out.write(request.getExtendedOperation().getID()); out.write("</requestName>"); byte[] vals=request.getExtendedOperation().getValue(); if( vals != null) { newLine(2); out.write("<requestValue xsi:type=\"xsd:base64Binary\">"); out.write(Base64.encode(vals)); out.write("</requestValue>"); } // added this fix for OCT' 04 NDK if( (controls !=null) && (controls.length != 0)) { writeControls(controls, 3); } newLine(1); out.write("</extendedRequest>"); return; }
/** * Write control line(s). * * @param ctrls LDAPControl array object */ private void writeControls(LDAPControl[] ctrls) throws IOException { for ( int i = 0; i < ctrls.length; i++ ) { // get control value byte[] cVal = ctrls[i].getValue(); // write control value writeLine( (cVal != null && cVal.length > 0)? "control: " + ctrls[i].getID() + " " + ctrls[i].isCritical() + ":: " + Base64.encode(cVal): "control: " + ctrls[i].getID() + " " + ctrls[i].isCritical() ); } return; }