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


Java ArrayUtils.reverse方法代碼示例

本文整理匯總了Java中org.apache.commons.lang3.ArrayUtils.reverse方法的典型用法代碼示例。如果您正苦於以下問題:Java ArrayUtils.reverse方法的具體用法?Java ArrayUtils.reverse怎麽用?Java ArrayUtils.reverse使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.commons.lang3.ArrayUtils的用法示例。


在下文中一共展示了ArrayUtils.reverse方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: decodeToBit

import org.apache.commons.lang3.ArrayUtils; //導入方法依賴的package包/類
@Override
protected String decodeToBit(String data, int precision) {
  switch (data) {
    case "true":
      return "1";
    case "false":
      return "0";
  }

  StringBuilder sb = new StringBuilder();
  String oneByte;
  String result;
  byte[] decoded = Base64.decodeBase64(data);

  ArrayUtils.reverse(decoded);

  for (byte b : decoded) {
    oneByte = String.format("%8s", Integer.toBinaryString(b & 0xFF)).replace(' ', '0');
    sb.append(oneByte);
  }
  result = sb.toString();

  return result.substring(result.length() - precision);
}
 
開發者ID:HashDataInc,項目名稱:bireme,代碼行數:25,代碼來源:DebeziumPipeLine.java

示例2: setTarget

import org.apache.commons.lang3.ArrayUtils; //導入方法依賴的package包/類
@Override
public void setTarget(final String hostname) {
    final String simple;
    final String[] parts = StringUtils.split(hostname, '.');
    if(parts.length > 4) {
        ArrayUtils.reverse(parts);
        // Rewrite c.cyberduck.s3.amazonaws.com which does not match wildcard certificate *.s3.amazonaws.com
        simple = StringUtils.join(parts[3], ".", parts[2], ".", parts[1], ".", parts[0]);
        log.warn(String.format("Rewrite hostname target to %s", simple));
    }
    else {
        simple = hostname;
    }
    super.setTarget(simple);
}
 
開發者ID:iterate-ch,項目名稱:cyberduck,代碼行數:16,代碼來源:LaxHostnameDelegatingTrustManager.java

示例3: calculateHash

import org.apache.commons.lang3.ArrayUtils; //導入方法依賴的package包/類
/**
 * return the hash, as calculated from the other parameters.
 *
 * @return the hash, as calculated from the other parameters.
 */
private UInt256 calculateHash() {
	final ByteArrayOutputStream bout = new ByteArrayOutputStream();
	NetworkUtil.write(bout, nextConsensus.toByteArray());
	NetworkUtil.write(bout, consensusData.toByteArray());
	NetworkUtil.write(bout, index.toByteArray());
	NetworkUtil.write(bout, timestamp.toByteArray());
	NetworkUtil.write(bout, merkleRoot.toByteArray());
	final byte[] prevHashBa = prevHash.toByteArray();
	ArrayUtils.reverse(prevHashBa);
	NetworkUtil.write(bout, prevHashBa);
	NetworkUtil.write(bout, version.toByteArray());
	final byte[] hashDataBa = bout.toByteArray();
	ArrayUtils.reverse(hashDataBa);
	final byte[] hashBa = SHA256HashUtil.getDoubleSHA256Hash(hashDataBa);
	return new UInt256(hashBa);
}
 
開發者ID:coranos,項目名稱:neo-java,代碼行數:22,代碼來源:AbstractBlockBase.java

示例4: main

import org.apache.commons.lang3.ArrayUtils; //導入方法依賴的package包/類
public static void main(String[] args)
{
	String[] array = ArrayUtils.toArray("one", "two", "three");	
	System.out.println(ArrayUtils.toString(array));
	
	array = ArrayUtils.add(array, "four");
	System.out.println(ArrayUtils.toString(array));
	
	if(ArrayUtils.contains(array,"two"))
	{
		System.out.println("found \"two\" in the array.");
	}
	
	ArrayUtils.reverse(array);
	System.out.println(ArrayUtils.toString(array));
}
 
開發者ID:teiniker,項目名稱:teiniker-lectures-configurationmanagement,代碼行數:17,代碼來源:ArrayExample.java

示例5: canonicalStart

import org.apache.commons.lang3.ArrayUtils; //導入方法依賴的package包/類
public Contour[] canonicalStart(Contour[] points) {
	int jm = 0;
	for (int j = 1; j < points.length; j++) {
		if (points[j].x < points[jm].x || (points[j].x == points[jm].x && points[j].y < points[jm].y)) {
			jm = j;
		}
	}
	Contour[] result = ArrayUtils.addAll(Arrays.copyOfRange(points, jm, points.length),
			Arrays.copyOfRange(points, 0, jm));
	ArrayUtils.reverse(result);
	return result;
}
 
開發者ID:icaoweiwei,項目名稱:otf2ttf,代碼行數:13,代碼來源:CTQ.java

示例6: toByteArray

import org.apache.commons.lang3.ArrayUtils; //導入方法依賴的package包/類
/**
 * return the message as a byte array.
 *
 * @return the message as a byte array.
 * @throws IOException
 *             if an error occurs.
 * @throws UnsupportedEncodingException
 *             if an error occurs.
 */
public byte[] toByteArray() throws IOException, UnsupportedEncodingException {
	final byte[] magicBa = NetworkUtil.getIntByteArray(magic);
	ArrayUtils.reverse(magicBa);
	final UInt32 magicObj = new UInt32(magicBa);
	final byte[] checksumFull = SHA256HashUtil.getDoubleSHA256Hash(payloadBa);
	final byte[] checksum = new byte[4];
	System.arraycopy(checksumFull, 0, checksum, 0, 4);
	final ByteArrayOutputStream bout = new ByteArrayOutputStream();
	bout.write(magicObj.getBytesCopy());
	NetworkUtil.writeString(bout, 12, command);

	if (LOG.isTraceEnabled()) {
		LOG.trace("createMessage magic+command {}", Hex.encodeHexString(bout.toByteArray()));
	}
	final byte[] lengthBa = NetworkUtil.getIntByteArray(payloadBa.length);
	ArrayUtils.reverse(lengthBa);
	if (LOG.isTraceEnabled()) {
		LOG.trace("createMessage lengthBa {}", Hex.encodeHexString(lengthBa));
	}
	bout.write(lengthBa);
	if (LOG.isTraceEnabled()) {
		LOG.trace("createMessage magic+command+length {}", Hex.encodeHexString(bout.toByteArray()));
		LOG.trace("createMessage checksum {}", Hex.encodeHexString(checksum));
	}
	bout.write(checksum);
	if (LOG.isTraceEnabled()) {
		LOG.trace("createMessage magic+command+length+checksum {}", Hex.encodeHexString(bout.toByteArray()));
	}
	bout.write(payloadBa);
	if (LOG.isTraceEnabled()) {
		LOG.trace("createMessage payloadBa {}", Hex.encodeHexString(payloadBa));
		LOG.trace("createMessage magic+command+length+checksum+payload {}",
				Hex.encodeHexString(bout.toByteArray()));
	}
	return bout.toByteArray();
}
 
開發者ID:coranos,項目名稱:neo-java,代碼行數:46,代碼來源:Message.java

示例7: toObject

import org.apache.commons.lang3.ArrayUtils; //導入方法依賴的package包/類
@Override
public TransactionOutput toObject(final ByteBuffer bb) {
	bb.getLong();
	final byte[] assetIdBa = ModelUtil.getVariableLengthByteArray(bb);
	final byte[] valueBa = ModelUtil.getVariableLengthByteArray(bb);
	ArrayUtils.reverse(valueBa);
	final byte[] scriptHashBa = ModelUtil.getVariableLengthByteArray(bb);

	final UInt256 assetId = new UInt256(ByteBuffer.wrap(assetIdBa));
	final Fixed8 value = new Fixed8(ByteBuffer.wrap(valueBa));
	final UInt160 scriptHash = new UInt160(scriptHashBa);
	final TransactionOutput transactionOutput = new TransactionOutput(assetId, value, scriptHash);
	return transactionOutput;
}
 
開發者ID:coranos,項目名稱:neo-java,代碼行數:15,代碼來源:TransactionOutputFactory.java

示例8: toObject

import org.apache.commons.lang3.ArrayUtils; //導入方法依賴的package包/類
@Override
public TransactionOutput toObject(final Map<String, Object> map) {
	final byte[] assetIdBa = getBytes(map, "asset_id");
	final byte[] valueBa = getBytes(map, "value");
	ArrayUtils.reverse(valueBa);
	final byte[] scriptHashBa = getBytes(map, "script_hash");

	final UInt256 assetId = new UInt256(ByteBuffer.wrap(assetIdBa));
	final Fixed8 value = new Fixed8(ByteBuffer.wrap(valueBa));
	final UInt160 scriptHash = new UInt160(scriptHashBa);
	final TransactionOutput transactionOutput = new TransactionOutput(assetId, value, scriptHash);
	return transactionOutput;
}
 
開發者ID:coranos,項目名稱:neo-java,代碼行數:14,代碼來源:TransactionOutputMapToObject.java

示例9: decode

import org.apache.commons.lang3.ArrayUtils; //導入方法依賴的package包/類
/**
 * decodes a Base58 byte array.
 *
 * @param input
 *            the base58 string to use.
 * @return the decoded byte array.
 */
public static byte[] decode(final String input) {

	BigInteger bi = BigInteger.ZERO;

	for (int ix = 0; ix < input.length(); ix++) {
		final char c = input.charAt(ix);
		final int index = ALPHABET.indexOf(c);
		if (index == -1) {
			throw new RuntimeException("invalid char:" + c);
		}

		bi = bi.multiply(BIGINT_58);
		bi = bi.add(BigInteger.valueOf(index));
	}
	final byte[] bytes = bi.toByteArray();

	final boolean stripSignByte = (bytes.length > 1) && (bytes[0] == 0) && (bytes[1] >= (byte) 0x80);

	ArrayUtils.reverse(bytes);

	final ByteArrayOutputStream bout = new ByteArrayOutputStream();
	try {
		if (stripSignByte) {
			bout.write(bytes, 0, bytes.length - 1);
		} else {
			bout.write(bytes);
		}
		for (int ix = 0; (ix < input.length()) && (input.charAt(ix) == ALPHABET.charAt(0)); ix++) {
			bout.write(new byte[1]);
		}
	} catch (final IOException e) {
		throw new RuntimeException(e);
	}

	final byte[] ba = bout.toByteArray();
	return ba;
}
 
開發者ID:coranos,項目名稱:neo-java,代碼行數:45,代碼來源:Base58Util.java

示例10: toAddress

import org.apache.commons.lang3.ArrayUtils; //導入方法依賴的package包/類
/**
 * coverts a scriptHash to an address.
 *
 * @param scriptHash
 *            the scriptHash to use.
 * @return the address.
 */
public static String toAddress(final UInt160 scriptHash) {
	final byte[] data = new byte[21];

	if (LOG.isTraceEnabled()) {
		LOG.trace("toAddress ADDRESS_VERSION {}", ModelUtil.toHexString(ADDRESS_VERSION));
	}

	final byte[] scriptHashBa = scriptHash.toByteArray();
	System.arraycopy(scriptHashBa, 0, data, 0, scriptHashBa.length);

	data[data.length - 1] = ADDRESS_VERSION;
	if (LOG.isTraceEnabled()) {
		LOG.info("toAddress data {}", ModelUtil.toHexString(data));
	}

	final byte[] dataAndChecksum = new byte[25];
	System.arraycopy(data, 0, dataAndChecksum, 4, data.length);

	ArrayUtils.reverse(data);
	final byte[] hash = SHA256HashUtil.getDoubleSHA256Hash(data);
	final byte[] hash4 = new byte[4];
	System.arraycopy(hash, 0, hash4, 0, 4);
	ArrayUtils.reverse(hash4);
	System.arraycopy(hash4, 0, dataAndChecksum, 0, 4);
	if (LOG.isTraceEnabled()) {
		LOG.info("toAddress dataAndChecksum {}", ModelUtil.toHexString(dataAndChecksum));
	}

	final String address = toBase58String(dataAndChecksum);
	return address;
}
 
開發者ID:coranos,項目名稱:neo-java,代碼行數:39,代碼來源:ModelUtil.java

示例11: toReverseHexString

import org.apache.commons.lang3.ArrayUtils; //導入方法依賴的package包/類
/**
 * converts a byte array to a hex string in reverse byte order.
 *
 * @param bytes
 *            the array of bytes.
 * @return the string.
 */
public static String toReverseHexString(final byte... bytes) {
	final byte[] ba = new byte[bytes.length];
	System.arraycopy(bytes, 0, ba, 0, bytes.length);
	ArrayUtils.reverse(ba);
	final BigInteger bi = new BigInteger(1, ba);
	return bi.toString(16);
}
 
開發者ID:coranos,項目名稱:neo-java,代碼行數:15,代碼來源:ModelUtil.java

示例12: toByteArray

import org.apache.commons.lang3.ArrayUtils; //導入方法依賴的package包/類
@Override
public byte[] toByteArray() {
	try {
		final ByteArrayOutputStream out = new ByteArrayOutputStream();
		final byte[] versionBa = version.getBytesCopy();
		ArrayUtils.reverse(versionBa);
		if (LOG.isTraceEnabled()) {
			LOG.trace("versionPayload version {}", Hex.encodeHexString(versionBa));
		}
		out.write(versionBa);
		final byte[] servicesBa = services.getBytesCopy();
		if (LOG.isTraceEnabled()) {
			LOG.trace("versionPayload services {}", Hex.encodeHexString(servicesBa));
		}
		ArrayUtils.reverse(servicesBa);
		out.write(servicesBa);
		if (LOG.isTraceEnabled()) {
			LOG.trace("versionPayload version+services {}", Hex.encodeHexString(out.toByteArray()));
		}
		final byte[] timestampBa = timestamp.getBytesCopy();
		ArrayUtils.reverse(timestampBa);
		if (LOG.isTraceEnabled()) {
			LOG.trace("versionPayload timestamp {}", Hex.encodeHexString(timestampBa));
		}
		out.write(timestampBa);
		if (LOG.isTraceEnabled()) {
			LOG.trace("versionPayload version+services+timestamp {}", Hex.encodeHexString(out.toByteArray()));
		}
		final byte[] portBa = port.getBytesCopy();
		ArrayUtils.reverse(portBa);
		if (LOG.isTraceEnabled()) {
			LOG.trace("versionPayload port {}", Hex.encodeHexString(portBa));
		}
		out.write(portBa);
		if (LOG.isTraceEnabled()) {
			LOG.trace("versionPayload version+services+timestamp+port {}", Hex.encodeHexString(out.toByteArray()));
		}
		final byte[] nonceBa = nonce.getBytesCopy();
		ArrayUtils.reverse(nonceBa);
		if (LOG.isTraceEnabled()) {
			LOG.trace("versionPayload nonce {}", Hex.encodeHexString(nonceBa));
		}
		out.write(nonceBa);
		if (LOG.isTraceEnabled()) {
			LOG.trace("versionPayload version+services+timestamp+port+nonce {}",
					Hex.encodeHexString(out.toByteArray()));
		}
		NetworkUtil.writeString(out, userAgent);
		if (LOG.isTraceEnabled()) {
			LOG.trace("versionPayload version+services+timestamp+port+nonce+userAgent {}",
					Hex.encodeHexString(out.toByteArray()));
		}

		final byte[] startHeightBa = startHeight.getBytesCopy();
		ArrayUtils.reverse(startHeightBa);
		if (LOG.isTraceEnabled()) {
			LOG.trace("versionPayload version+services+timestamp+port+nonce+userAgent+startHeight {}",
					Hex.encodeHexString(out.toByteArray()));
		}

		out.write(startHeightBa);

		if (relay) {
			out.write(new byte[] { 1 });
		} else {
			out.write(new byte[] { 0 });
		}

		if (LOG.isTraceEnabled()) {
			LOG.trace("versionPayload version+services+timestamp+port+nonce+userAgent+startHeight+relay {}",
					Hex.encodeHexString(out.toByteArray()));
		}

		return out.toByteArray();
	} catch (final IOException e) {
		throw new RuntimeException(e);
	}
}
 
開發者ID:coranos,項目名稱:neo-java,代碼行數:79,代碼來源:VersionPayload.java

示例13: encode

import org.apache.commons.lang3.ArrayUtils; //導入方法依賴的package包/類
/**
 * encodes a Base58 byte array.
 *
 * @param input
 *            the byte array to use.
 * @return the encoded Base58 string.
 */
public static String encode(final byte[] input) {
	try {
		final byte[] revInput = new byte[input.length];
		System.arraycopy(input, 0, revInput, 0, input.length);
		ArrayUtils.reverse(revInput);

		BigInteger value = new BigInteger(1, revInput);
		final StringBuilder sb = new StringBuilder();
		if (LOG.isDebugEnabled()) {
			LOG.debug("[0]val58: {}", ModelUtil.toHexString(BIGINT_58.toByteArray()));
			LOG.debug("[0]value: {}", ModelUtil.toHexString(value.toByteArray()));
		}

		while (value.compareTo(BigInteger.ZERO) != 0) {
			final BigInteger[] valueDivAndRemainder = value.divideAndRemainder(BIGINT_58);
			final BigInteger valueDiv = valueDivAndRemainder[0];
			final BigInteger valueRemainder = valueDivAndRemainder[1];

			sb.append(ALPHABET.charAt(valueRemainder.intValue()));
			value = valueDiv;
			if (LOG.isDebugEnabled()) {
				LOG.debug("[1]value: {}", ModelUtil.toHexString(value.toByteArray()));
				LOG.debug("[1]value.compareTo(val58): {}", value.compareTo(BIGINT_58));
			}
		}

		if (LOG.isDebugEnabled()) {
			LOG.debug("[2]value: {}", ModelUtil.toHexString(value.toByteArray()));
		}

		for (int ix = 0; (ix < revInput.length) && (revInput[ix] == 0); ix++) {
			sb.append(ALPHABET.charAt(0));
		}

		sb.reverse();

		return sb.toString();
	} catch (final Exception e) {
		throw new RuntimeException("error encoding \"" + ModelUtil.toHexString(input) + "\"", e);
	}
}
 
開發者ID:coranos,項目名稱:neo-java,代碼行數:49,代碼來源:Base58Util.java

示例14: copyAndReverse

import org.apache.commons.lang3.ArrayUtils; //導入方法依賴的package包/類
/**
 * copies and reverses a byte array.
 *
 * @param input
 *            the byte array to copy and reverse.
 * @return a copy of the byte array, in reverse byte order.
 */
public static byte[] copyAndReverse(final byte[] input) {
	final byte[] revInput = new byte[input.length];
	System.arraycopy(input, 0, revInput, 0, input.length);
	ArrayUtils.reverse(revInput);
	return revInput;
}
 
開發者ID:coranos,項目名稱:neo-java,代碼行數:14,代碼來源:ModelUtil.java

示例15: getFixedLengthByteArray

import org.apache.commons.lang3.ArrayUtils; //導入方法依賴的package包/類
/**
 * gets a fixed length byte array from the ByteBuffer.
 *
 * @param bb
 *            the ByteBuffer to read.
 * @param size
 *            the size of the byte array.
 * @param reverse
 *            if true, reverse the byte array.
 * @return the fixed length byte array.
 */
public static byte[] getFixedLengthByteArray(final ByteBuffer bb, final int size, final boolean reverse) {
	final byte[] ba = new byte[size];
	bb.get(ba);
	if (reverse) {
		ArrayUtils.reverse(ba);
	}
	return ba;
}
 
開發者ID:coranos,項目名稱:neo-java,代碼行數:20,代碼來源:ModelUtil.java


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