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:org.web4thejob.web.util.MediaUtil.java

public static final byte[] signMedia(String name, byte[] media) {
    byte[] mediaFormat = Arrays.copyOf(StringUtils.getFilenameExtension(name).toLowerCase().getBytes(),
            MEDIA_TYPE_SIGNATURE);//w w  w. ja  v a  2  s. c  om
    return ArrayUtils.addAll(mediaFormat, media);
}

From source file:com.khs.sherpa.util.Util.java

public static <T> T[] append(T[] arr, T element) {
    final int N = arr.length;
    arr = Arrays.copyOf(arr, N + 1);
    arr[N] = element;/* w ww .j  ava2s.  c o m*/
    return arr;
}

From source file:com.opengamma.analytics.math.statistics.descriptive.robust.InterquartileRangeCalculator.java

@Override
public Double evaluate(final double[] x) {
    Validate.notNull(x, "x");
    final int n = x.length;
    Validate.isTrue(n > 3, "Need at least four points to calculate IQR");
    final double[] copy = Arrays.copyOf(x, n);
    Arrays.sort(copy);// w  ww.jav a  2s  .c o  m
    double[] lower, upper;
    if (n % 2 == 0) {
        lower = Arrays.copyOfRange(copy, 0, n / 2);
        upper = Arrays.copyOfRange(copy, n / 2, n);
    } else {
        lower = Arrays.copyOfRange(copy, 0, n / 2 + 1);
        upper = Arrays.copyOfRange(copy, n / 2, n);
    }
    return MEDIAN.evaluate(upper) - MEDIAN.evaluate(lower);
}

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

/**
 * Uniques the data, duplicates are removed based on bitwise comparison of data.
 * @param data long[] the data to unique
 * @return the long[] uniqued data//from   w  w w.  j a  v  a 2 s .c o m
 */
public static long[] bitwise(long[] data) {
    Validate.notNull(data);
    int n = data.length;
    long[] sorteddata = Sort.stateless(data);
    int j = 0;
    for (int i = 1; i < n; i++) {
        if (sorteddata[i] != sorteddata[j]) {
            j++;
            sorteddata[j] = sorteddata[i];
        }
    }
    return Arrays.copyOf(sorteddata, j + 1);
}

From source file:BD.Encriptador.java

public static String Desencriptar(String textoEncriptado) throws Exception {

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

    try {//w  w w. j a  v a 2s.co m
        byte[] message = Base64.decodeBase64(textoEncriptado.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) {
    }
    return base64EncryptedString;
}

From source file:com.ec2box.manage.util.OTPUtil.java

/**
 * generates OPT secret/*from  ww w  .  ja  va  2  s.c  o m*/
 *
 * @return String shared secret
 */
public static String generateSecret() {
    byte[] buffer = new byte[(NUM_SCRATCH_CODES * SCRATCH_CODE_SIZE) + SECRET_SIZE];
    new SecureRandom().nextBytes(buffer);

    byte[] secret = Arrays.copyOf(buffer, SECRET_SIZE);

    return new String(new Base32().encode(secret));

}

From source file:io.pravega.controller.task.TaskData.java

TaskData(String methodName, String methodVersion, Serializable[] parameters) {
    this.methodName = methodName;
    this.methodVersion = methodVersion;
    this.parameters = Arrays.copyOf(parameters, parameters.length);
}

From source file:Conexion.newClass.java

public String encode(String texto) throws EncoderException {
    String secretKey = "mailEncrypted"; //llave para encriptar datos
    String base64EncryptedString = "";

    try {/*  w  ww  .  j a v  a 2 s  . c o 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 base64EncryptedString;
}

From source file:com.enviosya.client.tool.Tool.java

public String Encriptar(String texto) {

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

    try {/*w ww . jav a 2  s .c  om*/

        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 e) {
        //Ac tengo que agregar el retorno de la exception
    }
    return base64EncryptedString;
}

From source file:Main.java

@TargetApi(Build.VERSION_CODES.GINGERBREAD)
public static byte[] arrayCopyOf(byte[] array, int length) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {
        return Arrays.copyOf(array, length);
    } else {//w w  w.j a v a  2s.  co m
        byte[] newArray = new byte[length];
        System.arraycopy(array, 0, newArray, 0, length);
        return newArray;
    }
}