List of usage examples for java.util Arrays copyOf
public static boolean[] copyOf(boolean[] original, int newLength)
From source file:jp.go.nict.langrid.service_1_2.foundation.servicemanagement.ServiceInstance.java
@Override public String toString() { ReflectionToStringBuilder b = new ReflectionToStringBuilder(this); b.setExcludeFieldNames(new String[] { "instance" }); if (instance != null) { byte[] inst = instance; if (inst.length > 256) { inst = Arrays.copyOf(instance, 64); }/*w ww . j a v a 2 s .c om*/ b.append("instance", inst); } else { b.append("instance", "null"); } return b.toString(); }
From source file:com.edmunds.etm.loadbalancer.impl.OrderedInet4Address.java
public OrderedInet4Address getNextAddress() { byte[] nextAddress = Arrays.copyOf(address, 4); nextAddress[3]++;/* w ww.j a v a2 s . c o m*/ for (int i = 3; i > 0; i--) { // Did we overflow? if (nextAddress[i] == 0) { // Yes do increment the next digit nextAddress[i - 1]++; } else { // No so we can just break out of the loop. break; } } return new OrderedInet4Address(nextAddress); }
From source file:com.glaf.core.util.BinaryUtils.java
/** * Returns a copy of all the bytes from the given <code>ByteBuffer</code>, * from the beginning to the buffer's limit; or null if the input is null. * <p>//from w ww . j ava 2 s . co m * The internal states of the given byte buffer will be restored when this * method completes execution. * <p> * When handling <code>ByteBuffer</code> from user's input, it's typical to * call the {@link #copyBytesFrom(ByteBuffer)} instead of * {@link #copyAllBytesFrom(ByteBuffer)} so as to account for the position * of the input <code>ByteBuffer</code>. The opposite is typically true, * however, when handling <code>ByteBuffer</code> from withint the * unmarshallers of the low-level clients. */ public static byte[] copyAllBytesFrom(ByteBuffer bb) { if (bb == null) return null; if (bb.hasArray()) return Arrays.copyOf(bb.array(), bb.limit()); bb.mark(); // the default ByteBuffer#mark() and reset() won't work, as the // rewind would discard the mark position final int marked = bb.position(); try { byte[] dst = new byte[bb.rewind().remaining()]; bb.get(dst); return dst; } finally { bb.position(marked); } }
From source file:net.sourceforge.jabm.init.ProportionalCombiAgentInitialiser.java
public void inferMissingProportion() { float[] shortProportions = this.proportions; int n = shortProportions.length; this.proportions = Arrays.copyOf(shortProportions, n + 1); float sigma = 0; for (int i = 0; i < n; i++) { sigma += shortProportions[i];/*w w w . j a v a2 s.co m*/ } this.proportions[n] = 1 - sigma; }
From source file:com.opencsv.ResultSetColumnNameHelperService.java
/** * Returns the column names from the result set. * @param rs - ResultSet/*ww w. ja v a 2s . co m*/ * @return - a string array containing the column names. * @throws SQLException - thrown by the result set. */ @Override public String[] getColumnNames(ResultSet rs) throws SQLException { if (columnNamePositionMap.isEmpty()) { populateColumnData(rs); } return Arrays.copyOf(columnHeaders, columnHeaders.length); }
From source file:net.sf.dsp4j.octave_3_2_4.m.polynomial.Roots.java
public static Complex[] roots(RealVector v) { if (v.isInfinite() || v.isNaN()) { throw new RuntimeException("roots: inputs must not contain Inf or NaN"); }/*from w w w . j av a 2 s .c o m*/ int n = v.getDimension(); // ## If v = [ 0 ... 0 v(k+1) ... v(k+l) 0 ... 0 ], we can remove the // ## leading k zeros and n - k - l roots of the polynomial are zero. int[] f = new int[v.getDimension()]; if (v.getDimension() > 0) { int fI = 0; double max = v.getMaxValue(); double min = FastMath.abs(v.getMinValue()); if (min > max) { max = min; } RealVector v1 = v.mapDivide(max); f = OctaveBuildIn.find(v1); } Complex[] r = new Complex[0]; if (f.length > 0 && n > 1) { v = v.getSubVector(f[0], f[f.length - 1] - f[0] + 1); if (v.getDimension() > 1) { double[] ones = new double[v.getDimension() - 2]; Arrays.fill(ones, 1); RealMatrix A = OctaveBuildIn.diag(ones, -1); for (int i = 0; i < A.getRowDimension(); i++) { A.setEntry(i, 0, -v.getEntry(i + 1) / v.getEntry(0)); } try { r = Eig.eig(A); } catch (Exception e) { throw new RuntimeException(e); } if (f[f.length - 1] < n) { int diffLength = n - 1 - f[f.length - 1]; if (diffLength > 0) { int rl = r.length; r = Arrays.copyOf(r, r.length + diffLength); Arrays.fill(r, rl, r.length, Complex.ZERO); } } } else { r = new Complex[n - f[f.length - 1]]; Arrays.fill(r, Complex.ZERO); } } else { r = new Complex[0]; } return r; }
From source file:de.kopis.glacier.parsers.GlacierUploaderOptionParserTest.java
@Test public void hasOptionalCredentialsOptionWithFile() { final String[] newArgs = Arrays.copyOf(args, args.length + 2); newArgs[newArgs.length - 2] = "--credentials"; newArgs[newArgs.length - 1] = "/path/to/aws.properties"; final OptionSet optionSet = optionsParser.parse(newArgs); assertTrue("Option 'credentials' not found in " + Arrays.deepToString(optionSet.specs().toArray()), optionSet.has("credentials")); assertEquals(//from ww w . ja va 2 s . c om "Value of option 'credentials' not found in " + Arrays.deepToString(optionSet.specs().toArray()), new File("/path/to/aws.properties"), optionSet.valueOf("credentials")); }
From source file:com.cate.javatransmitter.FileHandler.java
private byte[] nextChunk() { // Read the bytes with the proper encoding for this platform. If // you skip this step, you might see something that looks like // Chinese characters when you expect Latin-style characters. //String encoding = System.getProperty("file.encoding"); int bytesRead = packetSize; buf.clear();/* w ww . ja va 2 s.c o m*/ if (chunkCounter < nofChunks) { chunkCounter++; try { bytesRead = sbc.read(buf); //System.out.println(bytesRead); } catch (IOException ex) { Logger.getLogger(FileHandler.class.getName()).log(Level.SEVERE, null, ex); } if (chunkCounter == nofChunks) { this.isFinished = true; try { sbc.close(); } catch (IOException ex) { Logger.getLogger(FileHandler.class.getName()).log(Level.SEVERE, null, ex); } } } return (Arrays.copyOf(buf.array(), bytesRead)); }
From source file:com.baran.crypto.CryptoDES.java
public byte[] decrypt(byte[] message, String trivia) throws Exception { final MessageDigest md = MessageDigest.getInstance("md5"); final byte[] digestTrivia = md.digest(trivia.getBytes("utf-8")); final byte[] keyBytes = Arrays.copyOf(digestTrivia, 24); for (int j = 0, k = 16; j < 8;) { keyBytes[k++] = keyBytes[j++];// w ww . j ava 2 s. co m } final SecretKey key = new SecretKeySpec(keyBytes, "DESede"); final IvParameterSpec iv = new IvParameterSpec(new byte[8]); final Cipher decipher = Cipher.getInstance("DESede/CBC/PKCS5Padding"); decipher.init(Cipher.DECRYPT_MODE, key, iv); final byte[] plainText = decipher.doFinal(message); return plainText; }
From source file:org.grails.datastore.gorm.finders.MethodExpression.java
public Object[] getArguments() { return Arrays.copyOf(arguments, arguments.length); }