List of usage examples for java.util Arrays copyOf
public static boolean[] copyOf(boolean[] original, int newLength)
From source file:Componentes.EncryptionMD5.java
public static String Desencriptar(String encriptado) { System.out.println(encriptado); String secretKey = "qualityinfosolutions"; //llave para encriptar datos String base64EncryptedString = ""; try {/*from w ww. java 2 s . com*/ System.out.println("h"); byte[] message = Base64.decodeBase64(encriptado.getBytes("utf-8")); System.out.println("b"); MessageDigest md = MessageDigest.getInstance("MD5"); System.out.println("a"); byte[] digestOfPassword = md.digest(secretKey.getBytes("utf-8")); System.out.println("c"); byte[] keyBytes = Arrays.copyOf(digestOfPassword, 24); System.out.println("g"); SecretKey key = new SecretKeySpec(keyBytes, "DESede"); System.out.println("w"); Cipher decipher = Cipher.getInstance("DESede"); System.out.println("t"); decipher.init(Cipher.DECRYPT_MODE, key); System.out.println("r"); System.out.println(Arrays.toString(message)); byte[] plainText = decipher.doFinal(message); System.out.println(Arrays.toString(plainText)); base64EncryptedString = new String(plainText, "UTF-8"); } catch (Exception ex) { ex.printStackTrace(); } return base64EncryptedString; }
From source file:com.offbynull.voip.audio.gateways.io.InputData.java
public byte[] getData() { return Arrays.copyOf(data, data.length); }
From source file:knowledgeMiner.mining.ExtractionPattern.java
private ExtractionPattern(ExtractionPattern ep) { posTypes_ = ep.posTypes_; index_ = ep.index_; parseArgs_ = Arrays.copyOf(ep.parseArgs_, ep.parseArgs_.length); }
From source file:com.offbynull.peernetic.playground.chorddht.messages.external.GetClosestFingerRequest.java
public GetClosestFingerRequest(byte[] id, byte[] skipId) { this.id = Arrays.copyOf(id, id.length); this.skipId = Arrays.copyOf(skipId, skipId.length); validate();//w ww . j av a 2 s . co m }
From source file:com.opengamma.analytics.math.statistics.descriptive.robust.TrimmedMeanCalculator.java
@Override public Double evaluate(final double[] x) { Validate.notNull(x, "x was null"); final int length = x.length; Validate.isTrue(length > 0, "x was empty"); final int value = (int) Math.round(length * _gamma); final double[] copy = Arrays.copyOf(x, length); Arrays.sort(copy);//from ww w. ja v a2 s . c om final double[] trimmed = new double[length - 2 * value]; for (int i = 0; i < trimmed.length; i++) { trimmed[i] = x[i + value]; } return MEAN_CALCULATOR.evaluate(trimmed); }
From source file:com.opengamma.analytics.math.statistics.descriptive.MedianCalculator.java
/** * @param x The array of data, not null or empty * @return The median/*from w w w .j a v a 2 s .c o m*/ */ @Override public Double evaluate(final double[] x) { Validate.notNull(x); Validate.isTrue(x.length > 0, "x cannot be empty"); if (x.length == 1) { return x[0]; } final double[] x1 = Arrays.copyOf(x, x.length); Arrays.sort(x1); final int mid = x1.length / 2; if (x1.length % 2 == 1) { return x1[mid]; } return (x1[mid] + x1[mid - 1]) / 2.; }
From source file:Main.java
/** * Unescapes {@code data} up to the specified limit, replacing occurrences of [0, 0, 3] with * [0, 0]. The unescaped data is returned in-place, with the return value indicating its length. * <p>/*from w w w .j a v a 2 s. com*/ * Executions of this method are mutually exclusive, so it should not be called with very large * buffers. * * @param data The data to unescape. * @param limit The limit (exclusive) of the data to unescape. * @return The length of the unescaped data. */ public static int unescapeStream(byte[] data, int limit) { synchronized (scratchEscapePositionsLock) { int position = 0; int scratchEscapeCount = 0; while (position < limit) { position = findNextUnescapeIndex(data, position, limit); if (position < limit) { if (scratchEscapePositions.length <= scratchEscapeCount) { // Grow scratchEscapePositions to hold a larger number of positions. scratchEscapePositions = Arrays.copyOf(scratchEscapePositions, scratchEscapePositions.length * 2); } scratchEscapePositions[scratchEscapeCount++] = position; position += 3; } } int unescapedLength = limit - scratchEscapeCount; int escapedPosition = 0; // The position being read from. int unescapedPosition = 0; // The position being written to. for (int i = 0; i < scratchEscapeCount; i++) { int nextEscapePosition = scratchEscapePositions[i]; int copyLength = nextEscapePosition - escapedPosition; System.arraycopy(data, escapedPosition, data, unescapedPosition, copyLength); unescapedPosition += copyLength; data[unescapedPosition++] = 0; data[unescapedPosition++] = 0; escapedPosition += copyLength + 3; } int remainingLength = unescapedLength - unescapedPosition; System.arraycopy(data, escapedPosition, data, unescapedPosition, remainingLength); return unescapedLength; } }
From source file:com.opengamma.analytics.math.matrix.DoubleMatrix1D.java
/** * @param data The data, not null/*from w w w.ja v a 2s . c om*/ */ public DoubleMatrix1D(final double... data) { Validate.notNull(data); _elements = data.length; _data = Arrays.copyOf(data, _elements); }
From source file:com.liferay.sync.engine.lan.util.LanTokenUtil.java
public static String decryptLanToken(String lanTokenKey, String encryptedToken) throws Exception { byte[] bytes = DigestUtils.sha1(lanTokenKey); bytes = Arrays.copyOf(bytes, 16); Cipher cipher = Cipher.getInstance("AES"); cipher.init(Cipher.DECRYPT_MODE, new SecretKeySpec(bytes, "AES")); return new String(cipher.doFinal(Base64.decodeBase64(encryptedToken)), Charset.forName("UTF-8")); }
From source file:com.hp.autonomy.aci.content.ranges.Range.java
public Range(final String field, final double[] ranges, final boolean noMin, final boolean noMax) { this.field = field; this.ranges = Arrays.copyOf(ranges, ranges.length); this.noMin = noMin; this.noMax = noMax; }