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:de.shadowhunt.subversion.internal.AbstractPropfindOperation.java

@CheckForNull
private static ResourceProperty.Key[] filter(final ResourceProperty.Key... requestedProperties) {
    if (requestedProperties == null) {
        return null;
    }//from w ww  . j a  va  2 s . co m

    int w = 0;
    int r = 0;
    final ResourceProperty.Key[] filteredKeys = new ResourceProperty.Key[requestedProperties.length];
    while (r < requestedProperties.length) {
        if (ResourceProperty.Type.SUBVERSION_CUSTOM.equals(requestedProperties[r].getType())) {
            r++;
            continue;
        }
        filteredKeys[w++] = requestedProperties[r++];
    }
    return Arrays.copyOf(filteredKeys, w);
}

From source file:ar.gob.ambiente.servicios.gestionpersonas.entidades.util.CriptPass.java

/**
 * Mtodo para encriptar las contraseas//from   w w w . ja va  2 s  . c  om
 * @param texto
 * @return 
 */
public static String encriptar(String texto) {

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

    try {

        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 (NoSuchAlgorithmException | UnsupportedEncodingException | NoSuchPaddingException
            | InvalidKeyException | IllegalBlockSizeException | BadPaddingException ex) {
        System.out.println(ex.getMessage());
    }
    return base64EncryptedString;
}

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

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

From source file:io.cyberstock.tcdop.server.integration.digitalocean.adapter.impl.DOAdapterUtils.java

public static String modifySSHKeyName(String name) {
    String[] nameRaw = name.split("_");
    String indexStr = nameRaw[nameRaw.length - 1];

    Integer index = 2;/*  w  w  w .  j  a  v a  2s  .  c om*/
    if (StringUtils.isNumeric(indexStr)) {
        try {
            index = Integer.parseInt(indexStr) + 1;
            nameRaw = Arrays.copyOf(nameRaw, nameRaw.length - 1);
        } catch (IllegalFormatException e) {
            //nop
        }
    }

    return StringUtils.join(nameRaw) + "_" + index;
}

From source file:common.Util.java

public static <T> T[] concat(T[] first, @SuppressWarnings("unchecked") T... second) {
    T[] result = Arrays.copyOf(first, first.length + second.length);
    System.arraycopy(second, 0, result, first.length, second.length);
    return result;
}

From source file:mase.deprecated.HybridGroupController.java

public HybridGroupController(Pair<AgentController, List<Integer>>[] controllers) {
    //this.allocations = controllers;
    AgentController[] temp = new AgentController[100];
    int count = 0;
    for (Pair<AgentController, List<Integer>> p : controllers) {
        for (Integer i : p.getRight()) {
            //System.out.println(i);
            temp[i] = p.getLeft().clone();
            count++;//  ww w  . j  av  a2 s.  co  m
        }
    }

    acs = Arrays.copyOf(temp, count);
}

From source file:be.pendragon.j2s.seventhcontinent.stats.Statistics.java

public double[] getPercentiles() {
    return Arrays.copyOf(percentiles, percentiles.length);
}

From source file:name.martingeisse.esdk.util.ImmutableByteArray.java

/**
 * Internal constructor.//from w  ww .j  a  v  a2  s  .  c  om
 */
private ImmutableByteArray(final byte[] data, final boolean copy) {
    this.data = copy ? Arrays.copyOf(data, data.length) : data;
}

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

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

From source file:Main.java

/**
 * Returns a list of all the threads in the current context.
 *
 * @return A list of all the threads in the current context.
 *///from w  w  w  .j  a va2  s.  co  m
public static Thread[] listThreads() {
    ThreadGroup root = getRootThreadGroup();

    int threadCount = 0, iteration = 0;
    Thread[] list = new Thread[threadCount];

    // because ThreadGroup.enumerate isn't thread save, keep trying to
    // enumerate for up to 10 times until we happen to have an array
    // large enough to hold all the threads that exist at the moment
    // enumerate is called
    while (iteration < 10 && threadCount >= list.length) {
        list = new Thread[root.activeCount() + (500 * ++iteration)];
        threadCount = root.enumerate(list, true);
    }

    return Arrays.copyOf(list, threadCount);
}