List of usage examples for java.util Arrays copyOf
public static boolean[] copyOf(boolean[] original, int newLength)
From source file:com.adobe.acs.commons.util.visitors.ContentVisitor.java
public ContentVisitor(T runnable, String[] containerTypes, String[] contentTypes) { this.runnable = runnable; this.containerTypes = Arrays.copyOf(containerTypes, containerTypes.length); this.contentTypes = Arrays.copyOf(contentTypes, contentTypes.length); }
From source file:com.linkedin.pinot.common.partition.PartitionAssignmentGeneratorTest.java
private List<String> getConsumingInstanceList(final int nServers) { Assert.assertTrue(nServers <= consumingServerNames.length); String[] instanceArray = Arrays.copyOf(consumingServerNames, nServers); return Lists.newArrayList(instanceArray); }
From source file:de.drop_converter.plugins.binary_convert.Hex2Data.java
@Override public boolean importData(TransferSupport support) throws ConverterException { try {//from www . j av a 2s . com if (support.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) { List<File> files = (List<File>) support.getTransferable() .getTransferData(DataFlavor.javaFileListFlavor); for (File file : files) { FileInputStream fis = null; OutputStream out = null; try { out = getOutputStream(file, ".hex"); fis = new FileInputStream(file); byte[] buffer = new byte[bufferSize]; int count = 0; while (-1 != (count = fis.read(buffer))) { if (count == bufferSize) { out.write(Hex.decodeHex(new String(buffer).toCharArray())); } else { byte[] tmp = Arrays.copyOf(Hex.decodeHex(new String(buffer).toCharArray()), count); out.write(tmp); } } } catch (Exception e) { throw new ConverterException(e); } finally { IOUtils.closeQuietly(out); IOUtils.closeQuietly(fis); } } return true; } else if (support.isDataFlavorSupported(DataFlavor.stringFlavor)) { String data = (String) support.getTransferable().getTransferData(DataFlavor.stringFlavor); OutputStream out = null; try { byte[] encode = Hex.decodeHex(data.toCharArray()); out = getOutputStream(null, ".hex"); out.write(encode); } catch (Exception e) { throw new ConverterException(e); } finally { IOUtils.closeQuietly(out); } } } catch (Exception e) { throw new ConverterException(e); } return false; }
From source file:com.buaa.cfs.security.token.TokenIdentifier.java
/** * Get the bytes for the token identifier * * @return the bytes of the identifier/*from www. jav a2 s . co m*/ */ public byte[] getBytes() { DataOutputBuffer buf = new DataOutputBuffer(4096); try { this.write(buf); } catch (IOException ie) { throw new RuntimeException("i/o error in getBytes", ie); } return Arrays.copyOf(buf.getData(), buf.getLength()); }
From source file:com.opengamma.analytics.math.curve.ArraysDoublesCurve.java
/** * @param xData An array of <i>x</i> data, not null * @param yData An array of <i>y</i> data, not null, contains same number of entries as <i>x</i> * @param isSorted Is the <i>x</i>-data sorted *//*from ww w. j a v a 2 s. c om*/ public ArraysDoublesCurve(final double[] xData, final double[] yData, final boolean isSorted) { super(); ArgumentChecker.notNull(xData, "x data"); ArgumentChecker.notNull(yData, "y data"); ArgumentChecker.isTrue(xData.length == yData.length, "x data size {} must be equal to y data size {}", xData.length, yData.length); _n = xData.length; _xData = Arrays.copyOf(xData, _n); _yData = Arrays.copyOf(yData, _n); if (!isSorted) { ParallelArrayBinarySort.parallelBinarySort(_xData, _yData); } }
From source file:io.github.dsheirer.util.XTEA.java
/** * XTEA block cipher encryption using 128 bit encryption key and 64 bit plain text block size with 32 Feistel rounds. * Shorter keys and/or plaintext values can be zero padded to the specified lengths. * * Algorithm source code adapted from: https://people.rit.edu/rab3106/CryptoReport.pdf (as accessed Sep. 2016) * * The encryption key can be changed at any point by invoking the setKey() method. * * @param key for encryption//from ww w .j ava 2 s . c o m */ public XTEA(String key) { setKey(Arrays.copyOf(key.getBytes(), 16)); }
From source file:it.unibo.alchemist.language.protelis.datatype.ArrayTupleImpl.java
private ArrayTupleImpl(final Object[] base, final boolean copy) { a = copy ? Arrays.copyOf(base, base.length) : base; }
From source file:gdsc.smlm.filters.MedianDataProcessor.java
/** * @param data/* w w w.java 2s . c om*/ * @param width * @param height * @return */ @Override public float[] process(float[] data, int width, int height) { float[] smoothData = data; if (smooth > 0) { // Smoothing destructively modifies the data so create a copy smoothData = Arrays.copyOf(data, width * height); // Check upper limits are safe final int tmpSmooth = FastMath.min((int) smooth, FastMath.min(width, height) / 2); // JUnit speed tests show that the rolling median is faster on windows of n<=3 if (tmpSmooth <= 3) { if (tmpSmooth <= getBorder()) { filter.rollingMedianInternal(smoothData, width, height, tmpSmooth); } else { filter.rollingMedian(smoothData, width, height, tmpSmooth); } } else { if (tmpSmooth <= getBorder()) { filter.blockMedianInternal(smoothData, width, height, tmpSmooth); } else { filter.blockMedian(smoothData, width, height, tmpSmooth); } } } return smoothData; }
From source file:com.opengamma.analytics.math.interpolation.LinearInterpolator.java
@Override public PiecewisePolynomialResult interpolate(final double[] xValues, final double[] yValues) { ArgumentChecker.notNull(xValues, "xValues"); ArgumentChecker.notNull(yValues, "yValues"); ArgumentChecker.isTrue(xValues.length == yValues.length, "xValues length = yValues length"); ArgumentChecker.isTrue(xValues.length > 1, "Data points should be more than 1"); final int nDataPts = xValues.length; for (int i = 0; i < nDataPts; ++i) { ArgumentChecker.isFalse(Double.isNaN(xValues[i]), "xData containing NaN"); ArgumentChecker.isFalse(Double.isInfinite(xValues[i]), "xData containing Infinity"); ArgumentChecker.isFalse(Double.isNaN(yValues[i]), "yData containing NaN"); ArgumentChecker.isFalse(Double.isInfinite(yValues[i]), "yData containing Infinity"); }//from w w w .j a v a 2 s.c om for (int i = 0; i < nDataPts; ++i) { for (int j = i + 1; j < nDataPts; ++j) { ArgumentChecker.isFalse(xValues[i] == xValues[j], "xValues should be distinct"); } } double[] xValuesSrt = Arrays.copyOf(xValues, nDataPts); double[] yValuesSrt = Arrays.copyOf(yValues, nDataPts); ParallelArrayBinarySort.parallelBinarySort(xValuesSrt, yValuesSrt); final DoubleMatrix2D coefMatrix = solve(xValuesSrt, yValuesSrt); for (int i = 0; i < coefMatrix.getNumberOfRows(); ++i) { for (int j = 0; j < coefMatrix.getNumberOfColumns(); ++j) { ArgumentChecker.isFalse(Double.isNaN(coefMatrix.getData()[i][j]), "Too large input"); ArgumentChecker.isFalse(Double.isInfinite(coefMatrix.getData()[i][j]), "Too large input"); } double ref = 0.; final double interval = xValuesSrt[i + 1] - xValuesSrt[i]; for (int j = 0; j < 2; ++j) { ref += coefMatrix.getData()[i][j] * Math.pow(interval, 1 - j); ArgumentChecker.isFalse(Double.isNaN(coefMatrix.getData()[i][j]), "Too large input"); ArgumentChecker.isFalse(Double.isInfinite(coefMatrix.getData()[i][j]), "Too large input"); } final double bound = Math.max(Math.abs(ref) + Math.abs(yValuesSrt[i + 1]), 1.e-1); ArgumentChecker.isTrue(Math.abs(ref - yValuesSrt[i + 1]) < ERROR * bound, "Input is too large/small or data are not distinct enough"); } return new PiecewisePolynomialResult(new DoubleMatrix1D(xValuesSrt), coefMatrix, coefMatrix.getNumberOfColumns(), 1); }
From source file:videoquotes.util.VideoUtil.java
public void insertQuote(Quote quote, String channelId) { int s = new Double(quote.getStart()).intValue(), e = new Double(quote.getEnd()).intValue(); try {//from w w w . j a v a 2 s. co m Video video = Videos.findOne(quote.getVideoId()); int segStart[] = video.getStart(); int segEnd[] = video.getEnd(); Long quoteId[] = video.getQuoteId(); if (segStart == null) { segStart = new int[] { s }; segEnd = new int[] { e }; quoteId = new Long[] { (quote.getKey()) }; } else { for (int i = 0; i < segStart.length; i++) if ((s <= segStart[i] && segStart[i] <= e) || (s <= segEnd[i] && segEnd[i] <= e) || (segStart[i] <= s && s <= segEnd[i]) || (segStart[i] <= e && e <= segEnd[i])) { Quotes.delete(quote); throw new VideoIntervalIntersect(); } segStart = Arrays.copyOf(segStart, segStart.length + 1); segStart[segStart.length - 1] = s; segEnd = Arrays.copyOf(segEnd, segEnd.length + 1); segEnd[segEnd.length - 1] = e; quoteId = Arrays.copyOf(quoteId, quoteId.length + 1); quoteId[quoteId.length - 1] = (quote.getKey()); } video.setStart(segStart); video.setEnd(segEnd); video.setQuoteId(quoteId); video = Videos.update(video); } catch (Exception we) { try { int segStart[] = new int[] { s }; int segEnd[] = new int[] { e }; Long quoteId[] = new Long[] { (quote.getKey()) }; long time = YoutubeUtil.getPublishedTime(quote.getVideoId()); Videos.save(new Video(quote.getVideoId(), time, channelId, quoteId, segStart, segEnd)); } catch (Exception eww) { throw new UpdateVideoFailed(); } } }