Example usage for java.util Arrays copyOf

List of usage examples for java.util Arrays copyOf

Introduction

In this page you can find the example usage for java.util Arrays copyOf.

Prototype

public static boolean[] copyOf(boolean[] original, int newLength) 

Source Link

Document

Copies the specified array, truncating or padding with false (if necessary) so the copy has the specified length.

Usage

From source file:com.opengamma.analytics.math.statistics.descriptive.robust.WinsorizedMeanCalculator.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 double[] winsorized = Arrays.copyOf(x, length);
    Arrays.sort(winsorized);//from w w w .  j  ava 2 s  .c om
    final int value = (int) Math.round(length * _gamma);
    final double x1 = winsorized[value];
    final double x2 = winsorized[length - value - 1];
    for (int i = 0; i < value; i++) {
        winsorized[i] = x1;
        winsorized[length - 1 - i] = x2;
    }
    return MEAN_CALCULATOR.evaluate(winsorized);
}

From source file:us.swcraft.springframework.session.messages.SerializedAttribute.java

public SerializedAttribute(String className, byte[] content) {
    Assert.notNull(content, "Serialized content can't be null");
    this.className = className;
    this.content = Arrays.copyOf(content, content.length);
}

From source file:Clases.cCifrado.java

public String Encriptar(String texto) {

    String secretKey = "MARSOFT"; //llave para encriptar datos
    String base64EncryptedString = "";

    try {//from   www .j a  v a2s  . co m

        MessageDigest md = MessageDigest.getInstance("MD5");
        byte[] digestOfPassword = md.digest(secretKey.getBytes("utf-8"));
        byte[] keyBytes = Arrays.copyOf(digestOfPassword, 24);

        SecretKey key = new SecretKeySpec(keyBytes, "DESede");
        Cipher cipher = Cipher.getInstance("DESede");
        cipher.init(Cipher.ENCRYPT_MODE, key);

        byte[] plainTextBytes = texto.getBytes("utf-8");
        byte[] buf = cipher.doFinal(plainTextBytes);
        byte[] base64Bytes = Base64.encodeBase64(buf);
        base64EncryptedString = new String(base64Bytes);

    } catch (Exception ex) {

        return "Ha habido un problema enviando datos";
    }
    return base64EncryptedString;
}

From source file:com.basp.trabajo_al_minuto.model.business.BusinessSecurity.java

/**
 * Se encarga de desencriptar la contrasea ingresada por el usuario *
 *//*from   w w w. j ava 2 s  .c om*/
public static String decrypt(String encryptValue) throws BusinessException {
    String secretKey = "e-business";
    String base64EncryptedString = "";

    try {
        byte[] message = Base64.decodeBase64(encryptValue.getBytes("utf-8"));
        MessageDigest md = MessageDigest.getInstance("MD5");
        byte[] digestOfPassword = md.digest(secretKey.getBytes("utf-8"));
        byte[] keyBytes = Arrays.copyOf(digestOfPassword, 24);
        SecretKey key = new SecretKeySpec(keyBytes, "DESede");
        Cipher decipher = Cipher.getInstance("DESede");
        decipher.init(Cipher.DECRYPT_MODE, key);
        byte[] plainText = decipher.doFinal(message);
        base64EncryptedString = new String(plainText, "UTF-8");
    } catch (Exception ex) {
        throw new BusinessException(ex);
    }
    return base64EncryptedString;
}

From source file:com.offbynull.peernetic.playground.chorddht.messages.external.GetClosestFingerResponse.java

public GetClosestFingerResponse(byte[] id, A address) {
    this.id = Arrays.copyOf(id, id.length);
    this.address = address;
    validate();
}

From source file:com.opengamma.maths.lowlevelapi.functions.utilities.Sort.java

/**
 * Sorts values statelessly in ascending order
 * @param v1 the values to sort (a native backed array)
 * @return tmp the sorted values//from  w ww  .  j  a  v a  2s .  co m
 */
public static float[] stateless(float[] v1) {
    Validate.notNull(v1);
    float[] tmp = Arrays.copyOf(v1, v1.length);
    Arrays.sort(tmp);
    return tmp;
}

From source file:com.offbynull.peernetic.playground.chorddht.messages.external.FindSuccessorResponse.java

public FindSuccessorResponse(byte[] id, A address) {
    this.id = id != null ? Arrays.copyOf(id, id.length) : null;
    this.address = address;
    validate();// w w  w  .  java2  s.  c o  m
}

From source file:com.offbynull.peernetic.playground.chorddht.messages.external.GetPredecessorResponse.java

public GetPredecessorResponse(byte[] id, A address) {
    this.id = id != null ? Arrays.copyOf(id, id.length) : null;
    this.address = address;
    validate();/*from   ww  w .  j a  va  2  s .c  o m*/
}

From source file:com.offbynull.peernetic.playground.chorddht.messages.external.GetClosestPrecedingFingerResponse.java

public GetClosestPrecedingFingerResponse(byte[] id, A address) {
    this.id = Arrays.copyOf(id, id.length);
    this.address = address;
    validate();
}

From source file:com.boulmier.machinelearning.jobexecutor.encrypted.AES.java

private void setKey(String myKey) {

    MessageDigest sha;//from   w w  w .  j ava  2  s .  com
    try {
        key = myKey.getBytes("UTF-8");
        sha = MessageDigest.getInstance("SHA-1");
        key = sha.digest(key);
        key = Arrays.copyOf(key, 16); // use only first 128 bit
        secretKey = new SecretKeySpec(key, "AES");

    } catch (NoSuchAlgorithmException | UnsupportedEncodingException e) {
    }

}