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.google.nigori.server.appengine.AEUser.java

@Override
public byte[] getPublicHash() {
    byte[] pkB = publicHash.getBytes();
    return Arrays.copyOf(pkB, pkB.length);
}

From source file:libepg.epg.section.Section.java

/**
 * ??????ID????+3?????????????//from  w ww.  j  ava  2s .c  o m
 *
 * @param data ?
 * @throws IllegalArgumentException
 * 1:???????ID????3???????<br>
 * 2:?2?0?????<br>
 * 3:???????preferedTableID???????????<br>
 */
public Section(byte[] data) throws IllegalArgumentException {
    byte[] temp = Arrays.copyOf(data, data.length);
    final int id = ByteConverter.byteToInt(temp[0]);
    tableId = TABLE_ID.reverseLookUp(id);

    String hexValue = Hex.encodeHexString(data);

    //ID??ID????????????ID?????????????(?????ID???????????)
    if (tableId == null) {
        MessageFormat msg2 = new MessageFormat(
                "????? ???={0}");
        Object[] parameters2 = { hexValue };
        LOG.trace(msg2.format(parameters2));
        throw new IllegalArgumentException(msg2.format(parameters2));
    }

    byte[] t = new byte[2];
    System.arraycopy(temp, 1, t, 0, t.length);
    int sectionLength = ByteConverter.bytesToInt(t);

    if (LOG.isTraceEnabled()) {
        LOG.trace("b1 = " + Integer.toHexString(sectionLength));
    }

    sectionLength = sectionLength & 0x0FFF;

    if (LOG.isTraceEnabled()) {
        LOG.trace("b2 = " + Integer.toHexString(sectionLength));
    }

    //???????
    if (sectionLength > tableId.getMaxSectionLength().getMaxSectionBodyLength()) {
        MessageFormat msg3 = new MessageFormat(
                "?????????={0} ?={1} ???={2}");
        Object[] parameters3 = { tableId.getMaxSectionLength().getMaxSectionBodyLength(), sectionLength,
                hexValue };
        LOG.trace(msg3.format(parameters3));
        throw new IllegalArgumentException(msg3.format(parameters3));
    }

    //???????????
    int targetLength = sectionLength + 3;
    byte[] sectionByteArray = new byte[targetLength];
    System.arraycopy(temp, 0, sectionByteArray, 0, sectionByteArray.length);

    if (LOG.isTraceEnabled()) {
        MessageFormat msg1 = new MessageFormat("\n??={0}\n?={1}");
        Object[] parameters1 = { Hex.encodeHexString(temp), Hex.encodeHexString(sectionByteArray) };
        LOG.trace(msg1.format(parameters1));
    }

    this.data = new ByteDataBlock(sectionByteArray);
}

From source file:com.frame.Conf.Utilidades.java

/**
 * //w  w  w. ja va  2s  .c o m
 * @param keypass Es la llave plublica para desencriptar el texto
 * @param textoEncriptado hash del texto a desencriptar
 * @return retorna el texto desencriptado
 * @throws Exception 
 */
public String Desencriptar(String keypass, String textoEncriptado) throws Exception {

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

    try {
        System.out.println("checkpoint");
        byte[] message = Base64.decodeBase64(textoEncriptado.getBytes("utf-8"));
        MessageDigest md = MessageDigest.getInstance("MD5");
        System.out.println("checkpoint2");
        byte[] digestOfPassword = md.digest(secretKey.getBytes("utf-8"));
        byte[] keyBytes = Arrays.copyOf(digestOfPassword, 24);
        System.out.println("checkpoint3");
        SecretKey key = new SecretKeySpec(keyBytes, "DESede");

        System.out.println("checkpoint4");
        Cipher decipher = Cipher.getInstance("DESede");
        decipher.init(Cipher.DECRYPT_MODE, key);
        System.out.println("checkpoint5");

        byte[] plainText = decipher.doFinal(message);
        System.out.println("checkpoint6");
        base64EncryptedString = new String(plainText, "UTF-8");

    } catch (UnsupportedEncodingException | NoSuchAlgorithmException | NoSuchPaddingException
            | InvalidKeyException | IllegalBlockSizeException | BadPaddingException ex) {
        throw new Exception(ex.getMessage());
    }
    return base64EncryptedString;
}

From source file:com.rockhoppertech.music.scale.Scale.java

public Scale(final String name, final int[] intervals) {
    setName(name);//from   ww w  .ja va 2  s. c  o m
    this.intervals = Arrays.copyOf(intervals, intervals.length);
    degrees = Interval.intervalsToDegrees(this.intervals);
    spelling = Interval.spellScale(degrees);
}

From source file:com.adobe.acs.commons.exporters.impl.users.Parameters.java

public String[] getGroups() {
    return Arrays.copyOf(groups, groups.length);
}

From source file:com.google.identitytoolkit.GitkitUser.java

public GitkitUser setSalt(byte[] salt) {
    this.salt = Arrays.copyOf(salt, salt.length);
    return this;
}

From source file:com.opencsv.ResultSetColumnNameHelperService.java

private void populateColumnData(ResultSet rs) throws SQLException {
    String[] realColumnNames = super.getColumnNames(rs);

    if (columnNames == null) {
        columnNames = Arrays.copyOf(realColumnNames, realColumnNames.length);
        columnHeaders = Arrays.copyOf(realColumnNames, realColumnNames.length);
    }//from  ww w .  j a  v a 2s. com

    for (String name : columnNames) {
        int position = ArrayUtils.indexOf(realColumnNames, name);
        if (position == ArrayUtils.INDEX_NOT_FOUND) {
            throw new UnsupportedOperationException(
                    "The column named " + name + " does not exist in the result set!");
        }
        columnNamePositionMap.put(name, position);
    }
}

From source file:hivemall.model.NewDenseModel.java

private void ensureCapacity(final int index) {
    if (index >= size) {
        int bits = MathUtils.bitsRequired(index);
        int newSize = (1 << bits) + 1;
        int oldSize = size;
        if (logger.isInfoEnabled()) {
            logger.info(//w  w  w.  j  a v  a 2s .  c om
                    "Expands internal array size from " + oldSize + " to " + newSize + " (" + bits + " bits)");
        }
        this.size = newSize;
        this.weights = Arrays.copyOf(weights, newSize);
        if (covars != null) {
            this.covars = Arrays.copyOf(covars, newSize);
            Arrays.fill(covars, oldSize, newSize, 1.f);
        }
        if (clocks != null) {
            this.clocks = Arrays.copyOf(clocks, newSize);
            this.deltaUpdates = Arrays.copyOf(deltaUpdates, newSize);
        }
    }
}

From source file:gedi.util.math.function.KnotFunction.java

/**
 * Builds a knot function from a list of arguments and the corresponding
 * values. Specifically, returns the function h(x) defined by <pre><code>
 * h(x) = y[0] for all x < x[1]/*from  w ww  .  j  a  v a2  s  .  c o m*/
 *        y[1] for x[1] <= x < x[2]
 *        ...
 *        y[y.length - 1] for x >= x[x.length - 1]
 * </code></pre>
 * The value of {@code x[0]} is ignored, but it must be strictly less than
 * {@code x[1]}.
 * 
 * x and y are not copied!
 * if x and y are not strictly monotonically increasing, the mean of the y values is computed for equal x values
 * It has to be increasing! 
 *
 * @param x Domain values where the function changes value.
 * @param y Values of the function.
 * @throws NullArgumentException if {@code x} or {@code y} are {@code null}.
 * @throws NoDataException if {@code x} or {@code y} are zero-length.
 * @throws DimensionMismatchException if {@code x} and {@code y} do not
 * have the same length.
 */
public KnotFunction(double[] x, double[] y)
        throws NullArgumentException, NoDataException, DimensionMismatchException {
    if (x == null || y == null) {
        throw new NullArgumentException();
    }
    if (x.length == 0 || y.length == 0) {
        throw new NoDataException();
    }
    if (y.length != x.length) {
        throw new DimensionMismatchException(y.length, x.length);
    }
    MathArrays.checkOrder(x, OrderDirection.INCREASING, false);

    int index = 0;
    double sumy = 0;
    int ny = 0;
    for (int i = 0; i < x.length; i++) {
        if (x[i] != x[index]) {
            index++;
            ny = 1;
            sumy = y[i];
        } else {
            ny++;
            sumy += y[i];
        }
        x[index] = x[i];
        y[index] = sumy / ny;
    }
    if (index + 1 != x.length) {
        x = Arrays.copyOf(x, index + 1);
        y = Arrays.copyOf(y, index + 1);
    }

    this.x = x;
    this.y = y;
}

From source file:com.consol.citrus.admin.web.ProjectSetupInterceptor.java

/**
 * Gets the excludes.
 * @return the excludes the excludes to get.
 */
public String[] getExcludes() {
    return Arrays.copyOf(excludes, excludes.length);
}