本文整理匯總了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);
}