List of usage examples for java.util Arrays copyOfRange
public static boolean[] copyOfRange(boolean[] original, int from, int to)
From source file:Main.java
/** * @return Get the array for week days for the current locale *///from ww w .j a v a 2 s . c o m public static String[] getWeekDaysList(Context context) { DateFormatSymbols symbols = new DateFormatSymbols(getLocale(context)); return Arrays.copyOfRange(symbols.getShortWeekdays(), 1, 8); }
From source file:Main.java
public static byte[] aesIGEdecrypt(byte[] tmpAESiv, byte[] tmpAesKey, byte[] data) { try {/* w w w . j a va 2 s. c om*/ ByteBuffer out = ByteBuffer.allocate(data.length); byte[] iv2p = Arrays.copyOfRange(tmpAESiv, 0, tmpAESiv.length / 2); byte[] ivp = Arrays.copyOfRange(tmpAESiv, tmpAESiv.length / 2, tmpAESiv.length); int len = data.length / AES_BLOCK_SIZE; byte[] xorInput = null; byte[] xorOutput = null; SecretKeySpec keySpec = null; keySpec = new SecretKeySpec(tmpAesKey, "AES"); Cipher cipher = null; cipher = Cipher.getInstance("AES/ECB/NoPadding"); cipher.init(Cipher.DECRYPT_MODE, keySpec); byte[] input = null; byte[] output = null; for (int i = 0; i < len; i++) { input = Arrays.copyOfRange(data, i * AES_BLOCK_SIZE, (i + 1) * AES_BLOCK_SIZE); xorInput = xor(input, ivp); output = cipher.doFinal(xorInput); xorOutput = xor(output, iv2p); out.put(xorOutput); ivp = xorOutput; iv2p = input; } return out.array(); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } catch (NoSuchPaddingException e) { e.printStackTrace(); } catch (IllegalBlockSizeException e) { e.printStackTrace(); } catch (BadPaddingException e) { e.printStackTrace(); } catch (InvalidKeyException e) { e.printStackTrace(); } return null; }
From source file:mongodb.MongoUtils.java
public static Object getValue(Document doc, String attribut) { if (!attribut.contains(".")) return doc.get(attribut); else {//from ww w .j ava2 s. c o m //System.out.println("Attribut a splitter : ["+attribut+"]"); String[] parties = attribut.split("\\."); Document nested = (Document) doc.get(parties[0]); return getValue(nested, StringUtils.join(Arrays.copyOfRange(parties, 1, parties.length), ".")); } }
From source file:Main.java
/** * Splits an array of objects into an array of smaller arrays. Useful for multithreaded bots. * CAVEAT: if splits > z.length, splits will be set to z.length. * /*from www . j a v a 2s . c o m*/ * @param z The array we'll be splitting * @param splits The number of sub-arrays you want. * */ public static Object[][] arraySplitter(Object[] z, int splits) { if (splits > z.length) splits = z.length; Object[][] xf; if (splits == 0) { xf = new Object[][] { z }; return xf; } else { xf = new Object[splits][]; for (int i = 0; i < splits; i++) { Object[] temp; if (i == 0) temp = Arrays.copyOfRange(z, 0, z.length / splits); else if (i == splits - 1) temp = Arrays.copyOfRange(z, z.length / splits * (splits - 1), z.length); else temp = Arrays.copyOfRange(z, z.length / splits * (i), z.length / splits * (i + 1)); xf[i] = temp; } return xf; } }
From source file:Main.java
public static byte[] getRSAHackdData(byte[] dataWithHash) { BigInteger modulus = new BigInteger( "C150023E2F70DB7985DED064759CFECF0AF328E69A41DAF4D6F01B538135A6F91F8F8B2A0EC9BA9720CE352EFCF6C5680FFC424BD634864902DE0B4BD6D49F4E580230E3AE97D95C8B19442B3C0A10D8F5633FECEDD6926A7F6DAB0DDB7D457F9EA81B8465FCD6FFFEED114011DF91C059CAEDAF97625F6C96ECC74725556934EF781D866B34F011FCE4D835A090196E9A5F0E4449AF7EB697DDB9076494CA5F81104A305B6DD27665722C46B60E5DF680FB16B210607EF217652E60236C255F6A28315F4083A96791D7214BF64C1DF4FD0DB1944FB26A2A57031B32EEE64AD15A8BA68885CDE74A5BFC920F6ABF59BA5C75506373E7130F9042DA922179251F", 16);//from w ww . j a v a 2 s .c o m BigInteger pubExp = new BigInteger("010001", 16); BigInteger r = new BigInteger(dataWithHash); BigInteger s = r.modPow(pubExp, modulus); byte[] temp = s.toByteArray(); return Arrays.copyOfRange(temp, temp.length - 256, temp.length); }
From source file:Main.java
public static byte[] trimLeadingZeros(byte[] byteArray) { int zeroCounter; for (zeroCounter = 0; zeroCounter < byteArray.length; zeroCounter++) { if (byteArray[zeroCounter] != 0) { break; }// w w w.j a va 2 s . co m } return Arrays.copyOfRange(byteArray, zeroCounter, byteArray.length); }
From source file:Main.java
public static float readFloat32(byte[] value, int start, int end) { byte[] bytes = Arrays.copyOfRange(value, start, end); float result = ByteBuffer.wrap(bytes).order(ByteOrder.LITTLE_ENDIAN).getFloat(); return result; }
From source file:Main.java
public static double readFloat64(byte[] value, int start, int end) { byte[] bytes = Arrays.copyOfRange(value, start, end); double result = ByteBuffer.wrap(bytes).order(ByteOrder.LITTLE_ENDIAN).getDouble(); return result; }
From source file:Main.java
public static CompletionInfo[] removeNulls(final CompletionInfo[] src) { int j = 0;// w ww. ja v a2 s . co m final CompletionInfo[] dst = new CompletionInfo[src.length]; for (int i = 0; i < src.length; ++i) { if (null != src[i] && !TextUtils.isEmpty(src[i].getText())) { dst[j] = src[i]; ++j; } } return Arrays.copyOfRange(dst, 0, j); }
From source file:Main.java
/** * Finds the earliest point in buffer1 at which the first part of buffer2 matches. For example, * overlapPoint("abcd", "cdef") == 2.// www. j a v a 2 s.c o m */ public static int overlapPoint(CharArrayBuffer buffer1, CharArrayBuffer buffer2) { if (buffer1 == null || buffer2 == null) { return -1; } return overlapPoint(Arrays.copyOfRange(buffer1.data, 0, buffer1.sizeCopied), Arrays.copyOfRange(buffer2.data, 0, buffer2.sizeCopied)); }