use of java.lang.StringBuffer in project OpenAM by OpenRock.
the class MergeClientConfig method main.
public static void main(String[] args) {
try {
StringBuffer file1 = getInputStringBuffer(args[0], false);
StringBuffer file2 = getInputStringBuffer(args[1], true);
writeToFile(file1, file2, args[2]);
} catch (Exception ex) {
ex.printStackTrace();
}
}
use of java.lang.StringBuffer in project OpenAM by OpenRock.
the class MergeClientConfig method getInputStringBuffer.
/**
* Returns input file as StringBuffer.
* @param filename Name of the file.
* @param skipCopyright if false, keep copyright notice in the beginning
* of the input file. if true, remove the copyright notice.
* @return StringBuffer
*/
private static StringBuffer getInputStringBuffer(String filename, boolean skipCopyright) throws Exception {
StringBuffer buff = new StringBuffer(20480);
BufferedReader br = null;
try {
br = new BufferedReader(new InputStreamReader(new FileInputStream(filename)));
while (true) {
String line = br.readLine();
if (line == null) {
break;
}
if (skipCopyright && line.startsWith("#")) {
continue;
}
// done skipping the copyright in the beginning of the file
skipCopyright = false;
buff.append(line).append("\n");
}
} finally {
if (br != null) {
try {
br.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
return buff;
}
use of java.lang.StringBuffer in project opennms by OpenNMS.
the class SimpleNode method dumpOidNamesSymbolTable.
// end writeOIDS
/**
* Dump the oidNames symbol tables - primarily debugging routine
*/
public void dumpOidNamesSymbolTable() {
StringBuffer sb = new StringBuffer();
OidValues oidValues = null;
String key = null;
String oidName = null;
sb.append("Symbol Table oidNames for text OID/OidValues\n");
for (Enumeration e = oidNames.keys(); e.hasMoreElements(); ) {
key = (String) e.nextElement();
oidValues = (OidValues) oidNames.get(key);
sb.append(key + "/" + oidValues.toString()).append("\n");
}
if (printDebug) {
System.out.println(sb.toString());
}
}
use of java.lang.StringBuffer in project Payara by payara.
the class LoggerJDK14 method toString.
/**
* Prepare a printable version of this instance.
* @return the String representation of this object
*/
public String toString() {
// NOI18N
StringBuffer buf = new StringBuffer("LoggerJDK14: ");
// NOI18N
buf.append(" name: ");
// NOI18N
buf.append(getName());
// NOI18N
buf.append(", super: ");
// NOI18N
buf.append(super.toString());
// NOI18N
buf.append(", logging level: ");
// NOI18N
buf.append(getLevel());
return buf.toString();
}
use of java.lang.StringBuffer in project Payara by payara.
the class LDAPRealm method findAndBind.
/**
* Supports mode=find-bind. See class documentation.
*/
public String[] findAndBind(String _username, char[] _password) throws LoginException {
// do search for user, substituting %s for username
_username = RFC2254Encode(_username);
StringBuffer sb = new StringBuffer(getProperty(PARAM_SEARCH_FILTER));
substitute(sb, SUBST_SUBJECT_NAME, _username);
String userid = sb.toString();
// attempt to bind as the user
DirContext ctx = null;
String srcFilter = null;
String[] grpList = null;
String dynFilter = null;
String dynMember = getProperty(PARAM_DYNAMIC_GRP_TARGET);
try {
ctx = new InitialDirContext(getLdapBindProps());
String realUserDN = userSearch(ctx, getProperty(PARAM_USERDN), userid);
if (realUserDN == null) {
String msg = sm.getString("ldaprealm.usernotfound", _username);
throw new LoginException(msg);
}
boolean bindSuccessful = bindAsUser(realUserDN, _password);
if (bindSuccessful == false) {
String msg = sm.getString("ldaprealm.bindfailed", realUserDN);
throw new LoginException(msg);
}
// search groups using above connection, substituting %d (and %s)
sb = new StringBuffer(getProperty(PARAM_GRP_SEARCH_FILTER));
StringBuffer dynSb = new StringBuffer(getProperty(PARAM_DYNAMIC_GRP_FILTER));
substitute(sb, SUBST_SUBJECT_NAME, _username);
substitute(sb, SUBST_SUBJECT_DN, realUserDN);
substitute(dynSb, SUBST_SUBJECT_NAME, _username);
substitute(dynSb, SUBST_SUBJECT_DN, realUserDN);
srcFilter = sb.toString();
dynFilter = dynSb.toString();
ArrayList groupsList = new ArrayList();
groupsList.addAll(groupSearch(ctx, getProperty(PARAM_GRPDN), srcFilter, getProperty(PARAM_GRP_TARGET)));
// search filter is constructed internally as
// as a groupofURLS
groupsList.addAll(dynamicGroupSearch(ctx, getProperty(PARAM_GRPDN), dynMember, dynFilter, getProperty(PARAM_GRP_TARGET)));
grpList = new String[groupsList.size()];
groupsList.toArray(grpList);
} catch (Exception e) {
LoginException le = new LoginException(e.toString());
le.initCause(e);
_logger.log(Level.SEVERE, "ldaprealm.exception", le);
throw le;
} finally {
if (ctx != null) {
try {
ctx.close();
} catch (NamingException e) {
}
}
}
if (_logger.isLoggable(Level.FINE)) {
_logger.log(Level.FINE, "LDAP:Group search filter: " + srcFilter);
StringBuffer gb = new StringBuffer();
gb.append("Group memberships found: ");
if (grpList.length > 0) {
for (int i = 0; i < grpList.length; i++) {
gb.append(" " + grpList[i]);
}
} else {
gb.append("(null)");
}
if (_logger.isLoggable(Level.FINE)) {
_logger.log(Level.FINE, "LDAP: " + gb.toString());
}
}
grpList = addAssignGroups(grpList);
grpList = this.addMappedGroupNames(grpList);
setGroupNames(_username, grpList);
if (_logger.isLoggable(Level.FINE)) {
_logger.log(Level.FINE, "LDAP: login succeeded for: " + _username);
}
return grpList;
}
Aggregations