本文整理汇总了Java中org.apache.commons.lang.RandomStringUtils.randomAscii方法的典型用法代码示例。如果您正苦于以下问题:Java RandomStringUtils.randomAscii方法的具体用法?Java RandomStringUtils.randomAscii怎么用?Java RandomStringUtils.randomAscii使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.lang.RandomStringUtils
的用法示例。
在下文中一共展示了RandomStringUtils.randomAscii方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: replaceDefaultDBPassword
import org.apache.commons.lang.RandomStringUtils; //导入方法依赖的package包/类
public void replaceDefaultDBPassword() throws Exception {
try (Connection connection = getSQLConnection();
PreparedStatement changePasswordStatement = connection.prepareStatement("ALTER USER " + this.connectionParams.getLogin().toUpperCase() + " SET PASSWORD ?")) {
connection.setAutoCommit(false);
String newPassword = RandomStringUtils.randomAscii(32);
try {
// change password in DB
changePasswordStatement.setString(1, newPassword);
changePasswordStatement.execute();
// put password in keystore
this.connectionParams.updatePassword(newPassword);
connection.commit();
} catch (Exception ex) {
log.error("Error while changing DB password.", ex);
try {
connection.rollback();
} catch (Exception he) {
log.error("Error rolling back transaction", he);
}
throw ex;
}
EntityManagerFactory oldEmf = this.emf;
// reinitialize session factory
start(this.properties);
try {
oldEmf.close();
} catch (PersistenceException pe) {
// Ignore this
}
}
}
示例2: randomHeaders
import org.apache.commons.lang.RandomStringUtils; //导入方法依赖的package包/类
private static Header[] randomHeaders(final int maxNum, final int maxLen) {
int n = RNG.nextInt(maxNum) + 1;
Header[] ret = new Header[n];
for (int i = 0; i < n; i++) {
String name = "Random-" + RandomStringUtils.randomAlphabetic(RNG.nextInt(maxLen) + 1);
String value = RandomStringUtils.randomAscii(RNG.nextInt(maxLen) + 1);
ret[i] = new BasicHeader(name, value);
}
return ret;
}
示例3: HttpResponse
import org.apache.commons.lang.RandomStringUtils; //导入方法依赖的package包/类
public HttpResponse(final int maxNumberOfHeaders, final int maxLenghtOfHeader, final int maxLengthOfBody, final int pos) {
this.statusLine = new BasicStatusLine(PROTOCOL_VERSION, 200, "OK");
Header[] headers = randomHeaders(maxNumberOfHeaders, maxLenghtOfHeader);
headers[RNG.nextInt(headers.length)] = new BasicHeader("Position", Integer.toString(pos));
this.setHeaders(headers);
this.content = RandomStringUtils.randomAscii(RNG.nextInt(maxLengthOfBody) + 1);
byte[] body = Util.toByteArray(content);
this.addHeader("Content-Length", Integer.toString(body.length));
this.entity = new ByteArrayEntity(body, ContentType.DEFAULT_BINARY);
}