Example usage for java.lang Byte SIZE

List of usage examples for java.lang Byte SIZE

Introduction

In this page you can find the example usage for java.lang Byte SIZE.

Prototype

int SIZE

To view the source code for java.lang Byte SIZE.

Click Source Link

Document

The number of bits used to represent a byte value in two's complement binary form.

Usage

From source file:org.springframework.context.RefreshedContextAttacherTest.java

@Test
public void testSingleOnContextInitializedCall() {
    final AtomicInteger counter = new AtomicInteger(0);
    RefreshedContextAttacher attacher = new RefreshedContextAttacher() {
        @Override/*  w  ww.j a  v  a 2  s  . co  m*/
        protected void onContextInitialized(ApplicationContext context) {
            super.onContextInitialized(context);
            logger.info("onContextInitialized(" + context.getDisplayName() + ") call count: "
                    + counter.incrementAndGet());
        }
    };
    ContextRefreshedEvent event = new ContextRefreshedEvent(applicationContext);
    for (int index = 1; index <= Byte.SIZE; index++) {
        attacher.onApplicationEvent(event);
        Assert.assertEquals("Mismatched number of calls at index=" + index, 1, counter.get());
    }
}

From source file:org.apache.sshd.server.PasswordAuthenticatorUtilsTest.java

@Test
public void testAcceptAllPasswordAuthenticatorOnVariousValues() {
    Collection<String> values = Collections.unmodifiableList(
            Arrays.asList(getClass().getSimpleName(), "testAcceptAllPasswordAuthenticatorOnVariousValues"));
    for (String username : values) {
        for (String password : values) {
            for (int index = 0; index < Byte.SIZE; index++) {
                String u = shuffleCase(username), p = shuffleCase(password);
                assertTrue("user=" + u + "/password=" + p,
                        PasswordAuthenticatorUtils.ACCEPT_ALL_AUTHENTICATOR.authenticate(u, p, MOCK_SESSION));
            }//from  w  w w. j a  v  a 2s .  co  m
        }
    }
}

From source file:com.linkedin.pinot.core.segment.memory.PinotDataBufferTest.java

private static void loadVerifyByte(PinotDataBuffer buffer) {
    final int fieldSize = Byte.SIZE / 8;
    int maxElementCount = (int) (buffer.size() / fieldSize);
    int elemCount = Math.min(100_000, maxElementCount);

    Map<Integer, Byte> positionValues = new HashMap<>();
    byte[] val = new byte[1];
    for (long i = 0; i < elemCount; i++) {
        int pos = random.nextInt(elemCount);
        random.nextBytes(val);
        positionValues.put(pos, val[0]);
        buffer.putByte(pos * fieldSize, val[0]);
    }//from  w w  w.  j a  v  a 2  s . c o m
    for (Map.Entry<Integer, Byte> entry : positionValues.entrySet()) {
        Assert.assertEquals(buffer.getByte(entry.getKey() * fieldSize), (byte) entry.getValue(),
                "Failure at index: " + entry.getKey());
    }
}

From source file:org.apache.zeppelin.python.PythonUtils.java

public static String createSecret(int secretBitLength) {
    SecureRandom rnd = new SecureRandom();
    byte[] secretBytes = new byte[secretBitLength / java.lang.Byte.SIZE];
    rnd.nextBytes(secretBytes);//from   w  ww . jav a2s  .c  om
    return Base64.encodeBase64String(secretBytes);
}

From source file:com.openteach.diamond.network.waverider.command.Command.java

/**
 * /*from  ww  w . j  a  v a  2 s.c  om*/
 * @return
 */
public static int getHeaderSize() {
    int size = 0;
    size += Long.SIZE / Byte.SIZE;
    size += Integer.SIZE / Byte.SIZE;
    return size;
}

From source file:com.asakusafw.directio.hive.parquet.DecimalValueDriver.java

static int getByteLength(int precision) {
    if (precision == 0) {
        return 1;
    }//from  w ww  .j  a  va  2 s.  c  om
    int bits = BigInteger.TEN.pow(precision).bitLength() + 1;
    return (bits + Byte.SIZE - 1) / Byte.SIZE;
}

From source file:com.xsdn.main.util.EtherAddress.java

/**
 * Convert a string representation of an ethernet address into a long
 * integer number.//from   w ww . j  av a 2 s  .c om
 *
 * @param hex  A hex string which represents an ethernet address.
 * @return  A long integer number.
 * @throws NullPointerException
 *    {@code hex} is {@code null}.
 * @throws NumberFormatException
 *    The given string is not a hex string.
 * @throws IllegalArgumentException
 *    The given string is not a string representation of an ethernet
 *    address.
 */
public static long toLong(String hex) {
    long value = 0L;
    int count = 1;
    StringBuilder builder = new StringBuilder();
    for (int i = 0; i < hex.length(); i++) {
        char c = hex.charAt(i);
        if (c == ByteUtils.HEX_SEPARATOR_CHAR) {
            count++;
            int octet = ByteUtils.parseHexOctet(builder.toString());
            value = (value << Byte.SIZE) | (long) octet;
            builder = new StringBuilder();
        } else {
            builder.append(c);
        }
    }

    if (count != SIZE) {
        throw new IllegalArgumentException("Too many octets: " + hex);
    }

    int octet = ByteUtils.parseHexOctet(builder.toString());
    return (value << Byte.SIZE) | (long) octet;
}

From source file:com.openteach.diamond.network.waverider.network.Packet.java

/**
 * //from   w w  w  .  j  av  a  2 s  .c  o  m
 * @return
 */
public static int getHeaderSize() {
    int size = 0;
    size += NetWorkConstants.WAVERIDER_MAGIC.getBytes().length;
    size += Long.SIZE / Byte.SIZE;
    size += Long.SIZE / Byte.SIZE;
    size += Integer.SIZE / Byte.SIZE;

    return size;
}

From source file:org.apache.spark.network.crypto.AuthEngine.java

/**
 * Create the client challenge./*from w ww.  j  av  a  2s  .  c  o  m*/
 *
 * @return A challenge to be sent the remote side.
 */
ClientChallenge challenge() throws GeneralSecurityException, IOException {
    this.authNonce = randomBytes(conf.encryptionKeyLength() / Byte.SIZE);
    SecretKeySpec authKey = generateKey(conf.keyFactoryAlgorithm(), conf.keyFactoryIterations(), authNonce,
            conf.encryptionKeyLength());
    initializeForAuth(conf.cipherTransformation(), authNonce, authKey);

    this.challenge = randomBytes(conf.encryptionKeyLength() / Byte.SIZE);
    return new ClientChallenge(new String(appId, UTF_8), conf.keyFactoryAlgorithm(),
            conf.keyFactoryIterations(), conf.cipherTransformation(), conf.encryptionKeyLength(), authNonce,
            challenge(appId, authNonce, challenge));
}

From source file:org.onosproject.net.pi.impl.AbstractCriterionTranslator.java

/**
 * Computes the prefix padding size (in bits) based on value and bit width.
 *
 * @return prefix padding in bits//from   w  ww  .j  a  v  a 2 s. c  o m
 */
private int prefixPadding() {
    return value.size() * Byte.SIZE - this.bitWidth;
}