@Override public int getDisplaySize() { return MathUtils.convertLongToInt(value.length * 2L); }
@Override protected int compareSecure(Value o, CompareMode mode) { ValueShort v = (ValueShort) o; return MathUtils.compareInt(value, v.value); }
@Override protected int compareSecure(Value o, CompareMode mode) { ValueTimestamp t = (ValueTimestamp) o; int c = MathUtils.compareLong(dateValue, t.dateValue); if (c != 0) { return c; } return MathUtils.compareLong(timeNanos, t.timeNanos); }
private static int getBufferSize( long remaining) { if (remaining < 0 || remaining > Integer.MAX_VALUE) { remaining = Integer.MAX_VALUE; } int inplace = /*handler.*/getMaxLengthInplaceLob(); long m = Constants.IO_BUFFER_SIZE; if (m < remaining && m <= inplace) { // using "1L" to force long arithmetic because // inplace could be Integer.MAX_VALUE m = Math.min(remaining, inplace + 1L); // the buffer size must be bigger than the inplace lob, otherwise we // can't know if it must be stored in-place or not m = MathUtils.roundUpLong(m, Constants.IO_BUFFER_SIZE); } m = Math.min(remaining, m); m = MathUtils.convertLongToInt(m); if (m < 0) { m = Integer.MAX_VALUE; } return (int) m; }
warn("InterruptedException", e); byte[] seed = generateAlternativeSeed(); generateAlternativeSeed(); warn("SecureRandom", e); cachedSecureRandom = new SecureRandom();
/** * Get the next temporary file name part (the part in the middle). * * @param newRandom if the random part of the filename should change * @return the file name part */ protected static synchronized String getNextTempFileNamePart(boolean newRandom) { if (newRandom || tempRandom == null) { tempRandom = MathUtils.randomInt(Integer.MAX_VALUE) + "."; } return tempRandom + tempSequence++; }
/** * Get a cryptographically secure pseudo random long value. * * @return the random long value */ public static long secureRandomLong() { SecureRandom sr = getSecureRandom(); synchronized (sr) { return sr.nextLong(); } }
@Override public void run() { try { SecureRandom sr = SecureRandom.getInstance("SHA1PRNG"); byte[] seed = sr.generateSeed(20); synchronized (cachedSecureRandom) { cachedSecureRandom.setSeed(seed); seeded = true; } } catch (Exception e) { // NoSuchAlgorithmException warn("SecureRandom", e); } } };
/** * Create a new UUID using the pseudo random number generator. * * @return the new UUID */ public static ValueUuid getNewRandom() { long high = MathUtils.secureRandomLong(); long low = MathUtils.secureRandomLong(); // version 4 (random) high = (high & (~0xf000L)) | 0x4000L; // variant (Leach-Salz) low = (low & 0x3fffffffffffffffL) | 0x8000000000000000L; return new ValueUuid(high, low); }
case SECURE_RAND: result = ValueBytes.getNoCopy( MathUtils.secureRandomBytes(v0.getInt())); break; case ZERO:
private static int getBufferSize( long remaining) { if (remaining < 0 || remaining > Integer.MAX_VALUE) { remaining = Integer.MAX_VALUE; } int inplace = getMaxLengthInplaceLob(); long m = Constants.IO_BUFFER_SIZE; if (m < remaining && m <= inplace) { // using "1L" to force long arithmetic m = Math.min(remaining, inplace + 1L); // the buffer size must be bigger than the inplace lob, otherwise we // can't know if it must be stored in-place or not m = MathUtils.roundUpLong(m, Constants.IO_BUFFER_SIZE); } m = Math.min(remaining, m); m = MathUtils.convertLongToInt(m); if (m < 0) { m = Integer.MAX_VALUE; } return (int) m; }
int p = low + MathUtils.randomInt(high - low); X pivot = array[p]; int m = (low + high) >>> 1;
/** * Get a cryptographically secure pseudo random int value between 0 * (including and the given value (excluding). * * @param lowerThan the value returned will be lower than this value * @return the random long value */ public static int secureRandomInt(int lowerThan) { SecureRandom sr = getSecureRandom(); synchronized (sr) { return sr.nextInt(lowerThan); } }
int getPrecisionAsInt() { return MathUtils.convertLongToInt(precision); }
@Override protected int compareSecure(Value o, CompareMode mode) { if (o == this) { return 0; } ValueUuid v = (ValueUuid) o; if (high == v.high) { return MathUtils.compareLong(low, v.low); } return high > v.high ? 1 : -1; }
@Override protected int compareSecure(Value o, CompareMode mode) { ValueByte v = (ValueByte) o; return MathUtils.compareInt(value, v.value); }
dirCounter = MathUtils.randomInt(lobsPerDir - 1) * lobsPerDir; } else {
/** * Get a number of cryptographically secure pseudo random bytes. * * @param len the number of bytes * @return the random bytes */ public static byte[] secureRandomBytes(int len) { if (len <= 0) { len = 1; } byte[] buff = new byte[len]; SecureRandom sr = getSecureRandom(); synchronized (sr) { sr.nextBytes(buff); } return buff; }
@Override public int getDisplaySize() { long size = 0; for (Value v : values) { size += v.getDisplaySize(); } return MathUtils.convertLongToInt(size); }