List of usage examples for java.util Arrays copyOf
public static boolean[] copyOf(boolean[] original, int newLength)
From source file:de.drop_converter.plugins.binary_convert.Data2Hex.java
@Override public boolean importData(TransferSupport support) throws ConverterException { try {// ww w .j a v a 2s. co m 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.encodeHexString(buffer).getBytes("UTF-8")); } else { byte[] tmp = Arrays.copyOf(Hex.encodeHexString(buffer).getBytes("UTF-8"), 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.encodeHexString(data.getBytes()).getBytes(); 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:edu.kit.trufflehog.model.network.MacAddress.java
@Override public byte[] toByteArray() { return Arrays.copyOf(bytes, 6); }
From source file:net.shipilev.fjptrace.util.PairedList.java
public long[] getAllX() { return Arrays.copyOf(k1, index); }
From source file:hu.bme.mit.sette.common.tasks.JaCoCoClassLoader.java
public JaCoCoClassLoader(File[] binaryDirectories, Instrumenter instrumenter, ClassLoader parent) { super(parent); Validate.notEmpty(binaryDirectories, "The array of binary directories must not be empty or null"); Validate.noNullElements(binaryDirectories, "The array of binary directories must not contain null elements"); Validate.notNull(instrumenter, "The instrumenter must not be null"); this.binaryDirectories = Arrays.copyOf(binaryDirectories, binaryDirectories.length); this.instrumenter = instrumenter; logger.debug("JaCoCoClassLoader has been created"); }
From source file:com.linkedin.pinot.core.segment.creator.impl.fwd.MultiValueUnsortedForwardIndexCreator.java
@Override public void index(int docId, int[] dictionaryIndices) { final int[] entries = Arrays.copyOf(dictionaryIndices, dictionaryIndices.length); Arrays.sort(entries);//from ww w . j a v a 2s .c om mVWriter.setIntArray(docId, entries); }
From source file:SCTPTest.java
@Test public void testSCTPHeader() throws DecoderException { byte[] hex = Hex.decodeHex(data.toCharArray()); SCTPHeader hrd = SCTPHeader.fromBytes(Arrays.copyOf(hex, 12)); System.out.println("Hrd: " + hrd); }
From source file:model.Encryption.java
public void generateSecretKey() { try {/* www. j a va 2 s. com*/ String specificCryptKey = "zertfghzbenrfzer65z+er56365zr45ze4rz4er534z65rzrz53er4135a456r4az4er34z56er42df13z4er5646z5r4zer4"; MessageDigest shahash = MessageDigest.getInstance("SHA-1"); byte[] key = shahash.digest(specificCryptKey.getBytes("UTF-8")); key = Arrays.copyOf(key, 16); secret = new SecretKeySpec(key, "AES"); } catch (NoSuchAlgorithmException ex) { Logger.getLogger(Encryption.class.getName()).log(Level.SEVERE, null, ex); } catch (UnsupportedEncodingException ex) { Logger.getLogger(Encryption.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.opengamma.analytics.math.FunctionUtils.java
/** * Same behaviour as mathlab unique//from w w w . jav a 2s.c o m * @param in input array * @return a sorted array with no duplicates values */ public static int[] unique(final int[] in) { Arrays.sort(in); final int n = in.length; final int[] temp = new int[n]; temp[0] = in[0]; int count = 1; for (int i = 1; i < n; i++) { if (in[i] != in[i - 1]) { temp[count++] = in[i]; } } if (count == n) { return temp; } return Arrays.copyOf(in, count); }
From source file:com.opengamma.maths.lowlevelapi.functions.utilities.Reverse.java
/** * Reverses a vector in place//from ww w . j a v a 2s .c o m * @param v1 the vector to be reversed * @return r a reversed copy of v1 */ public static double[] stateless(double[] v1) { Validate.notNull(v1); double[] r = Arrays.copyOf(v1, v1.length); inPlace(r); return r; }
From source file:com.opengamma.analytics.math.surface.ObjectsSurface.java
/** * @param xData An array of <i>x</i> data, not null * @param yData An array of <i>y</i> data, not null * @param zData An array of <i>z</i> data, not null * @param name The surface name//from w ww . jav a2 s . c o m */ public ObjectsSurface(final T[] xData, final U[] yData, final V[] zData, final String name) { super(name); Validate.notNull(xData, "x data"); Validate.notNull(yData, "y data"); Validate.notNull(zData, "z data"); Validate.isTrue(xData.length == yData.length); Validate.isTrue(xData.length == zData.length); _n = xData.length; _xData = Arrays.copyOf(xData, _n); _yData = Arrays.copyOf(yData, _n); _zData = Arrays.copyOf(zData, _n); }