當前位置: 首頁>>代碼示例>>Java>>正文


Java ArrayUtils.subarray方法代碼示例

本文整理匯總了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;
}
 
開發者ID:logistimo,項目名稱:logistimo-web-service,代碼行數:20,代碼來源:HDFSBlobStoreService.java

示例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;
	}
}
 
開發者ID:mcardy,項目名稱:MystiCraft,代碼行數:32,代碼來源:CommandManager.java

示例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);
	}
}
 
開發者ID:LuJiangLin,項目名稱:TestDemo1-github,代碼行數:38,代碼來源:PaymentUtils.java

示例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");
	}
}
 
開發者ID:LuJiangLin,項目名稱:TestDemo1-github,代碼行數:38,代碼來源:PaymentUtils.java

示例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);
}
 
開發者ID:daflockinger,項目名稱:poppynotes,代碼行數:11,代碼來源:NoteEncryptionServiceImpl.java

示例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);
}
 
開發者ID:PAA-NCIC,項目名稱:SparkSeq,代碼行數:11,代碼來源:HaplotypeCaller.java

示例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);
}
 
開發者ID:daflockinger,項目名稱:poppynotes,代碼行數:5,代碼來源:EncryptionUtils.java

示例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();
        }
    }
}
 
開發者ID:goldmansachs,項目名稱:obevo,代碼行數:50,代碼來源:Main.java


注:本文中的org.apache.commons.lang.ArrayUtils.subarray方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。