List of usage examples for java.util Arrays fill
public static void fill(Object[] a, Object val)
From source file:Main.java
private static PKCS8EncodedKeySpec decryptPrivateKey(byte[] encryptedPrivateKey) throws GeneralSecurityException { EncryptedPrivateKeyInfo epkInfo; try {// ww w. ja va2 s. c o m epkInfo = new EncryptedPrivateKeyInfo(encryptedPrivateKey); } catch (IOException ex) { // Probably not an encrypted key. return null; } char[] password = System.console().readPassword("Password for the private key file: "); SecretKeyFactory skFactory = SecretKeyFactory.getInstance(epkInfo.getAlgName()); Key key = skFactory.generateSecret(new PBEKeySpec(password)); Arrays.fill(password, '\0'); Cipher cipher = Cipher.getInstance(epkInfo.getAlgName()); cipher.init(Cipher.DECRYPT_MODE, key, epkInfo.getAlgParameters()); try { return epkInfo.getKeySpec(cipher); } catch (InvalidKeySpecException ex) { System.err.println("Password may be bad."); throw ex; } }
From source file:Main.java
public static void writeCString(OutputStream out, String s, String characterSet, int fixedLen) throws IOException { byte[] bytes = s.getBytes(characterSet); out.write(bytes.length);//from w ww . j av a 2 s. co m fixedLen -= 1; if (fixedLen <= 0) return; if (fixedLen <= bytes.length) { out.write(bytes, 0, fixedLen); } else { out.write(bytes); byte[] fillBytes = new byte[fixedLen - bytes.length]; Arrays.fill(fillBytes, (byte) 0); out.write(fillBytes); } out.flush(); }
From source file:dualcontrol.DualControlDigest.java
public static byte[] digest(char[] chars) throws Exception { byte[] bytes = getBytes(chars); byte[] digestBytes = MessageDigest.getInstance(DIGEST_ALG).digest(bytes); Arrays.fill(bytes, (byte) 0); return digestBytes; }
From source file:com.bigml.histogram.ArrayCategoricalTarget.java
public ArrayCategoricalTarget(Map<Object, Integer> indexMap, double missingCount) { _indexMap = indexMap;/* w w w. j a v a2 s. com*/ _target = new double[indexMap.size()]; Arrays.fill(_target, 0); _missingCount = missingCount; }
From source file:Main.java
public static void writeWString(OutputStream out, String s, String characterSet, int fixedLen) throws IOException { byte[] bytes = s.getBytes(characterSet); writeShort(out, bytes.length);//from w w w .j a v a 2s .com fixedLen -= 2; if (fixedLen <= 0) return; if (fixedLen <= bytes.length) { out.write(bytes, 0, fixedLen); } else { out.write(bytes); byte[] fillBytes = new byte[fixedLen - bytes.length]; Arrays.fill(fillBytes, (byte) 0); out.write(fillBytes); } out.flush(); }
From source file:edu.oregonstate.eecs.mcplan.domains.sailing.SailingWorlds.java
public static SailingState emptyRectangle(final int V, final int T, final int width, final int height) { final String[] spec = new String[height]; final char[] water = new char[width]; Arrays.fill(water, 'w'); for (int y = 0; y < height; ++y) { spec[y] = new String(water); }// w w w . j a v a 2 s . c om final SailingTerrain[][] terrain = parse(spec, 1); return new SailingState(terrain, V, T); }
From source file:com.thoughtworks.xstream.benchmark.reflection.targets.AbstractReflectionTarget.java
protected void fill(final Object o) { final char[] zero = new char[8]; Arrays.fill(zero, '0'); for (Class cls = o.getClass(); cls != Object.class; cls = cls.getSuperclass()) { final Field[] fields = cls.getDeclaredFields(); for (int i = 0; i < fields.length; i++) { final Field field = fields[i]; field.setAccessible(true);/* w w w .j a v a 2s . c om*/ if (field.getType() == String.class) { final String hex = Integer.toHexString(i); try { field.set(o, new String(zero, 0, zero.length - hex.length()) + hex); } catch (final IllegalAccessException e) { throw new RuntimeException(e); } } } } }
From source file:edu.washington.gs.skyline.model.quantification.DesignMatrix.java
public static DesignMatrix getDesignMatrix(FoldChangeDataSet dataSet, boolean includeFeatureInteraction) { List<String> columnNames = new ArrayList<>(); List<double[]> matrixColumns = new ArrayList<>(); List<Double> contrastValues = new ArrayList<>(); double[] interceptColumn = new double[dataSet.getRowCount()]; Arrays.fill(interceptColumn, 1); columnNames.add("Intercept"); matrixColumns.add(interceptColumn);// w ww. jav a 2 s .c o m contrastValues.add(0.0); for (int iFeature = 1; iFeature < dataSet.getFeatureCount(); iFeature++) { columnNames.add("Feature" + iFeature); double[] featureColumn = new double[dataSet.getRowCount()]; for (int iRow = 0; iRow < featureColumn.length; iRow++) { featureColumn[iRow] = iFeature == dataSet.getFeature(iRow) ? 1 : 0; } matrixColumns.add(featureColumn); contrastValues.add(0.0); } if (dataSet.getRowCount() != dataSet.getSubjectCount()) { int controlGroupCount = dataSet.getControlGroupCount(); for (int iSubject = 1; iSubject < dataSet.getSubjectCount(); iSubject++) { columnNames.add("Subject" + iSubject); double[] subjectColumn = new double[dataSet.getRowCount()]; for (int iRow = 0; iRow < subjectColumn.length; iRow++) { subjectColumn[iRow] = iSubject == dataSet.getSubject(iRow) ? 1 : 0; } matrixColumns.add(subjectColumn); if (dataSet.isSubjectInControlGroup(iSubject)) { contrastValues.add(-1.0 / controlGroupCount); } else { contrastValues.add(1.0 / (dataSet.getSubjectCount() - controlGroupCount)); } } } columnNames.add("Control"); double[] controlColumn = new double[dataSet.getRowCount()]; for (int iRow = 0; iRow < controlColumn.length; iRow++) { controlColumn[iRow] = dataSet.isSubjectInControlGroup(iRow) ? 1.0 : 0.0; } matrixColumns.add(controlColumn); contrastValues.add(-1.0); if (includeFeatureInteraction) { for (int iFeature = 1; iFeature < dataSet.getFeatureCount(); iFeature++) { columnNames.add("Feature" + iFeature + "Interaction"); double[] featureInteractionColumn = new double[dataSet.getRowCount()]; for (int iRow = 0; iRow < featureInteractionColumn.length; iRow++) { if (iFeature == dataSet.getFeature(iRow) && dataSet.isRowInControlGroup(iRow)) { featureInteractionColumn[iRow] = 1.0; } else { featureInteractionColumn[iRow] = 0; } } matrixColumns.add(featureInteractionColumn); contrastValues.add(-1.0 / dataSet.getFeatureCount()); } } double[][] contrastValueMatrix = new double[contrastValues.size()][]; for (int i = 0; i < contrastValueMatrix.length; i++) { contrastValueMatrix[i] = new double[] { contrastValues.get(i) }; } return new DesignMatrix(dataSet, matrixColumns.toArray(new double[matrixColumns.size()][]), contrastValueMatrix, columnNames.toArray(new String[columnNames.size()])); }
From source file:ArrayHelper.java
public static String[] fillArray(String value, int length) { String[] result = new String[length]; Arrays.fill(result, value); return result; }
From source file:DoubleList.java
public DoubleList(int size, double fillValue) { int capacity = size; if (capacity < 2) capacity = 2;//from ww w . ja va 2s. c om this.data = new double[capacity]; Arrays.fill(this.data, fillValue); this.size = size; }