Example usage for java.util Arrays fill

List of usage examples for java.util Arrays fill

Introduction

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

Prototype

public static void fill(Object[] a, Object val) 

Source Link

Document

Assigns the specified Object reference to each element of the specified array of Objects.

Usage

From source file:gnu.trove.map.custom_hash.TObjectCharCustomHashMap.java

/**
 * Creates a new <code>TObjectCharHashMap</code> instance with a prime
 * value at or near the specified capacity and load factor.
 *
 * @param initialCapacity used to find a prime capacity for the table.
 * @param loadFactor used to calculate the threshold over which
 * rehashing takes place.//w  w w  .jav  a2  s  .  c  o m
 * @param noEntryValue the value used to represent null.
 */
public TObjectCharCustomHashMap(HashingStrategy<K> strategy, int initialCapacity, float loadFactor,
        char noEntryValue) {

    super(strategy, initialCapacity, loadFactor);

    no_entry_value = noEntryValue;
    //noinspection RedundantCast
    if (no_entry_value != (char) 0) {
        Arrays.fill(_values, no_entry_value);
    }
}

From source file:com.vake.ArrayUtils.java

/**
 * byte?length,??"0"//from   w w  w .ja  va  2  s  .c  om
 * 
 *
 * @param src
 * @param length
 * @return
 */
public static byte[] fillArray(byte[] src, int length) {
    if (src == null) {
        throw new IllegalArgumentException("needed fill byte array can't be null!");
    }
    final int srcLength = src.length;
    byte[] dest = new byte[length];
    //src????
    if (srcLength < length) {
        Arrays.fill(dest, (byte) 0);
        System.arraycopy(src, 0, dest, 0, srcLength);
        return dest;
    }

    //???src?length
    System.arraycopy(src, 0, dest, 0, length);
    return dest;
}

From source file:bobs.is.compress.sevenzip.SevenZFile.java

/**
 * Closes the archive.//from  w ww  . j  a  va 2 s . c o m
 * @throws IOException if closing the file fails
 */
@Override
public void close() throws IOException {
    if (file != null) {
        try {
            file.close();
        } finally {
            file = null;
            if (password != null) {
                Arrays.fill(password, (byte) 0);
            }
            password = null;
        }
    }
}

From source file:com.google.enterprise.connector.encryptpassword.EncryptPassword.java

/**
 * Encrypts the supplied password.  As a side-effect, it clears the supplied
 * plain-text password after the conversion.
 *
 * @param password plain text password//  w  w w . j  ava 2 s  . c o m
 * @return encrypted password
 */
private String encryptPassword(char[] password) {
    try {
        return EncryptedPropertyPlaceholderConfigurer.encryptChars(password);
    } finally {
        Arrays.fill(password, '\0');
    }
}

From source file:gnu.trove.map.custom_hash.TObjectFloatCustomHashMap.java

/**
 * Creates a new <code>TObjectFloatHashMap</code> instance with a prime
 * value at or near the specified capacity and load factor.
 *
 * @param initialCapacity used to find a prime capacity for the table.
 * @param loadFactor used to calculate the threshold over which
 * rehashing takes place./*from w  w w.j  a  va2s.  c o  m*/
 * @param noEntryValue the value used to represent null.
 */
public TObjectFloatCustomHashMap(HashingStrategy<K> strategy, int initialCapacity, float loadFactor,
        float noEntryValue) {

    super(strategy, initialCapacity, loadFactor);

    no_entry_value = noEntryValue;
    //noinspection RedundantCast
    if (no_entry_value != (float) 0) {
        Arrays.fill(_values, no_entry_value);
    }
}

From source file:gnu.trove.map.custom_hash.TObjectDoubleCustomHashMap.java

/**
 * Creates a new <code>TObjectDoubleHashMap</code> instance with a prime
 * value at or near the specified capacity and load factor.
 *
 * @param initialCapacity used to find a prime capacity for the table.
 * @param loadFactor used to calculate the threshold over which
 * rehashing takes place.//from w  w  w  .  j av  a  2  s  . c  om
 * @param noEntryValue the value used to represent null.
 */
public TObjectDoubleCustomHashMap(HashingStrategy<K> strategy, int initialCapacity, float loadFactor,
        double noEntryValue) {

    super(strategy, initialCapacity, loadFactor);

    no_entry_value = noEntryValue;
    //noinspection RedundantCast
    if (no_entry_value != (double) 0) {
        Arrays.fill(_values, no_entry_value);
    }
}

From source file:edu.snu.leader.discrete.simulator.Group.java

/**
 * This is for Group.NONE so it can reset itself after every simulation run
 *///from   w  w w.  java  2  s  . co m
public void reset() {
    // reset all of the colors in use to false
    Arrays.fill(_simState.colorsInUse, false);
    // set unique group id count equal to 0
    _simState.uniqueGroupIdCount = 0;
    _simState.noneGroup = new Group(_simState);

    _simState.totalNumGroups = 0;
}

From source file:com.lightboxtechnologies.io.IOUtilsTest.java

@Test
public void testReadShort() throws IOException {
    final byte[] expected = new byte[50];
    Arrays.fill(expected, (byte) 1);

    final InputStream in = new ByteArrayInputStream(expected);
    final byte[] actual = new byte[100];
    final int count = IOUtils.read(in, actual);

    assertEquals(50, count);/*  ww w.  j ava  2  s.  c  o  m*/
    assertArrayEquals(expected, Arrays.copyOfRange(actual, 0, count));
    assertArrayEquals(new byte[50], Arrays.copyOfRange(actual, count, 100));
}

From source file:org.cryptomator.crypto.engine.impl.CryptorImpl.java

@Override
public void readKeysFromMasterkeyFile(byte[] masterkeyFileContents, CharSequence passphrase) {
    final KeyFile keyFile;
    try {//w w  w  .  j  av a2 s  .  c o m
        final ObjectMapper om = new ObjectMapper();
        keyFile = om.readValue(masterkeyFileContents, KeyFile.class);
        if (keyFile == null) {
            throw new InvalidFormatException("Could not read masterkey file", null, KeyFile.class);
        }
    } catch (IOException e) {
        throw new IllegalArgumentException("Unable to parse masterkeyFileContents", e);
    }
    assert keyFile != null;

    // check version
    if (!CURRENT_VAULT_VERSION.equals(keyFile.getVersion())) {
        throw new UnsupportedVaultFormatException(keyFile.getVersion(), CURRENT_VAULT_VERSION);
    }

    final byte[] kekBytes = Scrypt.scrypt(passphrase, keyFile.getScryptSalt(), keyFile.getScryptCostParam(),
            keyFile.getScryptBlockSize(), KEYLENGTH_IN_BYTES);
    try {
        final SecretKey kek = new SecretKeySpec(kekBytes, ENCRYPTION_ALG);
        this.macKey = AesKeyWrap.unwrap(kek, keyFile.getMacMasterKey(), MAC_ALG);
        // future use (as soon as we need to prevent downgrade attacks):
        //         final Mac mac = new ThreadLocalMac(macKey, MAC_ALG).get();
        //         final byte[] versionMac = mac.doFinal(ByteBuffer.allocate(Integer.BYTES).putInt(CURRENT_VAULT_VERSION).array());
        //         if (!MessageDigest.isEqual(versionMac, keyFile.getVersionMac())) {
        //            destroyQuietly(macKey);
        //            throw new UnsupportedVaultFormatException(Integer.MAX_VALUE, CURRENT_VAULT_VERSION);
        //         }
        this.encryptionKey = AesKeyWrap.unwrap(kek, keyFile.getEncryptionMasterKey(), ENCRYPTION_ALG);
    } catch (InvalidKeyException e) {
        throw new InvalidPassphraseException();
    } catch (NoSuchAlgorithmException e) {
        throw new IllegalStateException("Hard-coded algorithm doesn't exist.", e);
    } finally {
        Arrays.fill(kekBytes, (byte) 0x00);
    }
}

From source file:bide.simulation.Simulation.java

private static Hashtable<String, double[]> simFalsePositive() {

    double[] setupMean = new double[totalSpot];
    double[] setupDelta = new double[totalSpot];
    double[] setupPi = new double[totalSpot];
    double[] setupRho = new double[totalSpot];

    for (int i = 0; i < totalSpot; i++) {
        setupMean[i] = rd.nextGaussian(simMean, globalSd);
        setupPi[i] = rd.nextGaussian(1, 1);
    }//w w w  .j ava  2 s .  c om
    Arrays.fill(setupDelta, 0);
    Arrays.fill(setupRho, 0);

    Hashtable<String, double[]> table = new Hashtable<String, double[]>();
    table.put("setupMean", setupMean);
    table.put("setupDelta", setupDelta);
    table.put("setupPi", setupPi);
    table.put("setupRho", setupRho);

    return table;
}