public static byte[] randomBytes(final int length) { byte[] bytes = new byte[length]; for (int i = 0; i < bytes.length; i++) { bytes[i] = RandomUtil.randomByte(); } return bytes; }
/** * Replaces the currently configured whiteList with a comma separated * string containing the new whiteList. Null or empty string denotes * no whiteList entries, {@value #CATCH_ALL_WILDCARD} indicates that * all classes are whiteListed. * * @param whiteList the whiteList that this policy is configured to recognize. */ public void setWhiteList(String whiteList) { this.whiteList = StringUtil.splitStringList(whiteList, ","); }
/** * Creates a TransportConfiguration providing the class name of the {@link org.apache.activemq.artemis.spi.core.remoting.ConnectorFactory} * and any parameters needed. * * @param className The class name of the ConnectorFactory * @param params The parameters needed by the ConnectorFactory */ public TransportConfiguration(final String className, final Map<String, Object> params) { this(className, params, UUIDGenerator.getInstance().generateStringUUID()); }
public UUID generateTimeBasedUUID(final byte[] byteAddr) { byte[] contents = new byte[16]; int pos = 10; System.arraycopy(byteAddr, 0, contents, pos, 6); synchronized (mTimerLock) { if (mTimer == null) { mTimer = new UUIDTimer(getRandomNumberGenerator()); } mTimer.getTimestamp(contents); } return new UUID(UUID.TYPE_TIME_BASED, contents); }
@Override public ConnectorFactory run() { return (ConnectorFactory) ClassloadingUtil.newInstanceFromClassLoader(connectorFactoryClassName); } });
/** * Returns an {@link Inet4Address}, given a byte array representation of the IPv4 address. * * @param bytes byte array representing an IPv4 address (should be of length 4) * @return {@link Inet4Address} corresponding to the supplied byte array * @throws IllegalArgumentException if a valid {@link Inet4Address} can not be created */ private static Inet4Address getInet4Address(byte[] bytes) { Preconditions.checkArgument(bytes.length == 4, "Byte array has invalid length for an IPv4 address: %s != 4.", bytes.length); // Given a 4-byte array, this cast should always succeed. return (Inet4Address) bytesToInetAddress(bytes); }
/** * Encodes a byte array into Base64 notation. * Does not GZip-compress data. * * @param source The data to convert * @return Base64 String * @since 1.4 */ public static String encodeBytes(final byte[] source) { return Base64.encodeBytes(source, 0, source.length, Base64.NO_OPTIONS); } // end encodeBytes
public void add() { for (;;) { int actualState = getState(); int newState = actualState + 1; if (compareAndSetState(actualState, newState)) { return; } } }
/** * Decodes data from Base64 notation, automatically * detecting gzip-compressed data and decompressing it. * * @param s the string to decode * @return the decoded data * @since 1.4 */ public static byte[] decode(final String s) { return Base64.decode(s, Base64.NO_OPTIONS); }
public static int randomMax(final int max) { int value = randomPositiveInt() % max; if (value == 0) { value = max; } return value; }
@Override public synchronized void syncIDGeneratorSequence(final long id) { if (!idGeneratorSynced) { idGenerator = new SimpleIDGenerator(id); idGeneratorSynced = true; } }
/** * from {@link java.io.DataInput} interface */ @Override public String readLine() throws IOException { return ByteUtil.readLine(this); }
/** * Size of a String as if it was a Nullable Simple String */ public static int sizeOfNullableSimpleString(String str) { if (str == null) { return DataConstants.SIZE_BOOLEAN; } else { return DataConstants.SIZE_BOOLEAN + sizeOfSimpleString(str); } }
/** * Returns {@code true} if the {@link SimpleString} encoded content into {@code bytes} is equals to {@code s}, * {@code false} otherwise. * <p> * It assumes that the {@code bytes} content is read using {@link SimpleString#readSimpleString(ByteBuf, int)} ie starting right after the * length field. */ public boolean equals(final ByteBuf byteBuf, final int offset, final int length) { return ByteUtil.equals(data, byteBuf, offset, length); }
UUIDTimer(final Random rnd) { mRnd = rnd; initCounters(rnd); mLastSystemTimestamp = 0L; // This may get overwritten by the synchronizer mLastUsedTimestamp = 0L; }
@Override public void run() { future.run(); } });
/** * Suspends encoding of the stream. * May be helpful if you need to embed a piece of * base640-encoded data in a stream. * * @throws java.io.IOException On IO Exception * @since 1.5.1 */ public void suspendEncoding() throws java.io.IOException { flushBase64(); suspendEncoding = true; } // end suspendEncoding
/** * Replaces the currently configured blackList with a comma separated * string containing the new blackList. Null or empty string denotes * no blacklist entries, {@value #CATCH_ALL_WILDCARD} indicates that * all classes are blacklisted. * * @param blackList the blackList that this policy is configured to recognize. */ public void setBlackList(String blackList) { this.blackList = StringUtil.splitStringList(blackList, ","); }