本文整理汇总了Java中org.apache.commons.lang.ArrayUtils.subarray方法的典型用法代码示例。如果您正苦于以下问题:Java ArrayUtils.subarray方法的具体用法?Java ArrayUtils.subarray怎么用?Java ArrayUtils.subarray使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.lang.ArrayUtils
的用法示例。
在下文中一共展示了ArrayUtils.subarray方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: fetchData
import org.apache.commons.lang.ArrayUtils; //导入方法依赖的package包/类
public byte[] fetchData(String blobKey, long startIndex, long l) {
CountingInputStream inputStream = new CountingInputStream(getInputStream(blobKey));
byte[] bytes = new byte[(int) l];
try {
int readSize = inputStream.read(bytes, (int) startIndex, (int) l);
if (readSize < l) {
bytes = ArrayUtils.subarray(bytes, 0, readSize - 1);
}
} catch (IOException e) {
LOGGER.warn("Failed to read bytes", e);
} finally {
try {
inputStream.close();
} catch (IOException ignored) {
LOGGER.warn("Exception while closing inputStream", ignored);
}
}
return bytes;
}
示例2: execute
import org.apache.commons.lang.ArrayUtils; //导入方法依赖的package包/类
boolean execute(CommandSender sender, String label, String[] strs) {
strs = (String[]) ArrayUtils.subarray(strs, cmd.label().split("\\.").length-1, strs.length);
CommandContext ctx = new CommandContext(sender, label, strs);
if (this.args != null) {
for (int i = 0; i < this.args.length; i++) {
if (strs.length <= i) {
break;
}
if (!ctx.bindParamater(this.args[i], strs[i])) {
sender.sendMessage(cmd.usage());
return false;
}
}
if (strs.length < this.args.length) {
for (int i = strs.length; i < this.args.length; i++) {
if (this.args[strs.length].required()) {
sender.sendMessage(cmd.usage());
return false;
}
}
}
}
try {
return (boolean) this.m.invoke(this.o, ctx);
} catch (Exception e) {
e.printStackTrace();
sender.sendMessage(cmd.usage());
return false;
}
}
示例3: encrypt
import org.apache.commons.lang.ArrayUtils; //导入方法依赖的package包/类
/**
* 内容加密
*
* @param encryptStr
* @param publicKey
* @return
* @throws Exception
*/
public static String encrypt(String content, String publicKey) throws Exception {
byte[] publicKeyBytes = Base64.decodeBase64(publicKey);
byte[] encryptBytes = content.getBytes("UTF-8");
if (encryptBytes.length <= ENCRYPT_BlOCK_SIZE) {
return Base64.encodeBase64String(encrypt(encryptBytes, publicKeyBytes));
} else {
byte[] buffer = null;
byte[] blockBytes = new byte[ENCRYPT_BlOCK_SIZE];
int index = ((encryptBytes.length - 1) / ENCRYPT_BlOCK_SIZE) + 1;
for (int i = 0; i < index; i++) {
if (i == (index - 1)) {
blockBytes = new byte[ENCRYPT_BlOCK_SIZE];
}
int startIndex = i * ENCRYPT_BlOCK_SIZE;
int endIndex = startIndex + ENCRYPT_BlOCK_SIZE;
blockBytes = ArrayUtils.subarray(encryptBytes, startIndex, endIndex);
if (buffer == null) {
buffer = encrypt(blockBytes, publicKeyBytes);
} else {
buffer = ArrayUtils.addAll(buffer, encrypt(blockBytes, publicKeyBytes));
}
}
return Base64.encodeBase64String(buffer);
}
}
示例4: decrypt
import org.apache.commons.lang.ArrayUtils; //导入方法依赖的package包/类
/**
* 内容解密
*
* @param decryptStr
* @param privateKey
* @return
* @throws Exception
*/
public static String decrypt(String content, String privateKey) throws Exception {
byte[] privateKeyBytes = Base64.decodeBase64(privateKey);
byte[] decryptBytes = Base64.decodeBase64(content);
if (decryptBytes.length <= DECRYPT_BLOCK_SIZE) {
return new String(decrypt(decryptBytes, privateKeyBytes), "UTF-8");
} else {
byte[] buffer = null;
int index = ((decryptBytes.length - 1) / DECRYPT_BLOCK_SIZE) + 1;
byte[] blockBytes = new byte[DECRYPT_BLOCK_SIZE];
for (int i = 0; i < index; i++) {
if (i == index - 1) {
blockBytes = new byte[DECRYPT_BLOCK_SIZE];
}
int startIndex = i * DECRYPT_BLOCK_SIZE;
int endIndex = startIndex + DECRYPT_BLOCK_SIZE;
blockBytes = ArrayUtils.subarray(decryptBytes, startIndex,
endIndex > decryptBytes.length ? decryptBytes.length : endIndex);
if (buffer == null) {
buffer = decrypt(blockBytes, privateKeyBytes);
} else {
buffer = ArrayUtils.addAll(buffer, decrypt(blockBytes, privateKeyBytes));
}
}
return new String(buffer, "UTF-8");
}
}
示例5: createKey
import org.apache.commons.lang.ArrayUtils; //导入方法依赖的package包/类
private Key createKey(String key, String principalName) {
byte[] keyBytes = decodeBase64(key);
byte[] principalBytes = getPrincipalWithoutEmailTail(principalName).getBytes(UTF_8);
if(principalBytes.length > MAX_KEY_SIZE_BYTES){
principalBytes = ArrayUtils.subarray(principalBytes, 0, MAX_KEY_SIZE_BYTES);
}
keyBytes = concatenateByteArrays(keyBytes,principalBytes);
return new SecretKeySpec(keyBytes, 0, keyBytes.length, ENCRYPTION_ALGORITHM);
}
示例6: getTrimedRefBases
import org.apache.commons.lang.ArrayUtils; //导入方法依赖的package包/类
private byte[] getTrimedRefBases(ActiveRegion originalRegion, ActiveRegion trimedRegion, byte[] originalRefBases) {
GenomeLoc originalLoc = originalRegion.getExtendedLoc();
GenomeLoc trimedLoc = trimedRegion.getExtendedLoc();
if(originalLoc.getStart() > trimedLoc.getStart() || originalLoc.getStop() < trimedLoc.getStop()) {
throw new PipelineException("Error !! implement error when get trimed ref base");
}
int startIdx = trimedLoc.getStart() - originalLoc.getStart();
int endIdx = originalRefBases.length + trimedLoc.getStop() - originalLoc.getStop();
return ArrayUtils.subarray(originalRefBases, startIdx, endIdx);
}
示例7: concatenateByteArrays
import org.apache.commons.lang.ArrayUtils; //导入方法依赖的package包/类
public static byte[] concatenateByteArrays(byte[] first, byte[] second){
byte[] keyBytes = ArrayUtils.subarray(first, 0, first.length - second.length);
return ArrayUtils.addAll(keyBytes, second);
}
示例8: execute
import org.apache.commons.lang.ArrayUtils; //导入方法依赖的package包/类
/**
* Executes the main method. This is public so that client distributions can test this method from their own
* packages.
*/
@VisibleForTesting
public void execute(String[] args, Runnable exitSuccessMethod, Runnable exitFailureMethod) {
Pair<String, Procedure<String[]>> commandEntry = getDeployCommand(args, exitFailureMethod);
LogUtil.FileLogger logAppender = LogUtil.getLogAppender(commandEntry.getOne());
StopWatch changeStopWatch = new StopWatch();
changeStopWatch.start();
LOG.info("Starting action at time [" + new Date() + "]");
boolean success = false;
Throwable processException = null;
try {
String[] argSubset = (String[]) ArrayUtils.subarray(args, 1, args.length);
commandEntry.getTwo().value(argSubset);
success = true;
} catch (Throwable t) {
processException = t;
} finally {
// We handle the exception and do system.exit in the finally block as we want a clean message to go out to users.
// If we just threw the runtime exception, then that would be the last thing that appears to users, which
// was confusing for users.
changeStopWatch.stop();
long runtimeSeconds = changeStopWatch.getTime() / 1000;
String successString = success ? "successfully" : "with errors";
LOG.info("");
LOG.info("Action completed {} at {}, took {} seconds.", successString, new Date(), runtimeSeconds);
LOG.info("");
if (processException != null) {
LOG.info("*** Exception stack trace ***", processException);
LOG.info("");
}
LOG.info("Detailed Log File is available at: {}", logAppender.getLogFile());
LOG.info("");
LOG.info("Exiting {}!", successString);
IOUtils.closeQuietly(logAppender);
if (processException != null) {
exitFailureMethod.run();
} else {
exitSuccessMethod.run();
}
}
}