List of usage examples for java.lang Byte SIZE
int SIZE
To view the source code for java.lang Byte SIZE.
Click Source Link
From source file:Main.java
public static byte[] leIntToByteArray(int i) { final ByteBuffer bb = ByteBuffer.allocate(Integer.SIZE / Byte.SIZE); bb.order(ByteOrder.LITTLE_ENDIAN); bb.putInt(i);//from w w w. ja va 2s . c o m return bb.array(); }
From source file:Main.java
public static byte[] int2bytes(int a) { int arraySize = Integer.SIZE / Byte.SIZE; ByteBuffer buffer = ByteBuffer.allocate(arraySize); buffer.order(ByteOrder.LITTLE_ENDIAN); return buffer.putInt(a).array(); }
From source file:Main.java
/** * 7 => 00000111//from w w w . j av a 2 s. co m * * @param src * @return */ public static String getBinaryString(byte src) { String binaryString = Integer.toBinaryString(src); if (binaryString.length() > Byte.SIZE) { binaryString = binaryString.substring(binaryString.length() - Byte.SIZE); } else { StringBuffer sb = new StringBuffer(); for (int i = 0; i < Byte.SIZE - binaryString.length(); i++) { sb.append("0"); } binaryString = sb.toString() + binaryString; } return binaryString; }
From source file:Main.java
/** * Converting the Byte to binary// w w w . jav a2 s . co m * * @param bytes * @return {@link String} */ public static String BytetoBinary(byte[] bytes) { StringBuilder sb = new StringBuilder(bytes.length * Byte.SIZE); for (int i = 0; i < Byte.SIZE * bytes.length; i++) sb.append((bytes[i / Byte.SIZE] << i % Byte.SIZE & 0x80) == 0 ? '0' : '1'); return sb.toString(); }
From source file:ByteString.java
public int getStoredLength() { return bytes.length + (Short.SIZE / Byte.SIZE); }
From source file:net.ripe.rpki.commons.crypto.util.Asn1Util.java
public static DERBitString resourceToBitString(UniqueIpResource resource, int bitCount) { int resourceTypeByteSize = resource.getType().getBitSize() / Byte.SIZE; byte[] value = resource.getValue().toByteArray(); byte[] padded; if (value.length > resourceTypeByteSize) { // Skip extra sign byte added by BigInteger. padded = Arrays.copyOfRange(value, 1, value.length); } else if (value.length < resourceTypeByteSize) { // Pad with leading zero bytes (e.g. 0.12.0.0) padded = new byte[resourceTypeByteSize]; System.arraycopy(value, 0, padded, resourceTypeByteSize - value.length, value.length); } else {/* www . j ava2s .com*/ padded = value; } assert padded.length == resourceTypeByteSize : "incorrect padded length"; int byteCount = (bitCount + Byte.SIZE - 1) / Byte.SIZE; int unusedBits = Byte.SIZE - 1 - ((bitCount + Byte.SIZE - 1) % Byte.SIZE); return new DERBitString(ArrayUtils.subarray(padded, 0, byteCount), unusedBits); }
From source file:org.apache.accumulo.server.security.SecurityConstants.java
private static AuthenticationToken makeSystemPassword() { int wireVersion = Constants.WIRE_VERSION; byte[] inst = HdfsZooInstance.getInstance().getInstanceID().getBytes(Constants.UTF8); try {/*from w w w .j a v a2 s . c o m*/ confChecksum = getSystemConfigChecksum(); } catch (NoSuchAlgorithmException e) { throw new RuntimeException("Failed to compute configuration checksum", e); } ByteArrayOutputStream bytes = new ByteArrayOutputStream( 3 * (Integer.SIZE / Byte.SIZE) + inst.length + confChecksum.length); DataOutputStream out = new DataOutputStream(bytes); try { out.write(wireVersion * -1); out.write(inst.length); out.write(inst); out.write(confChecksum.length); out.write(confChecksum); } catch (IOException e) { throw new RuntimeException(e); // this is impossible with // ByteArrayOutputStream; crash hard // if this happens } return new PasswordToken(Base64.encodeBase64(bytes.toByteArray())); }
From source file:com.xsdn.main.util.EtherAddress.java
/** * Convert the given byte array that represents an ethernet address into * a long integer number./* ww w . j a v a 2s .c o m*/ * * @param b A byte array. * @return A long integer number. * @throws NullPointerException * {@code b} is {@code null}. * @throws IllegalArgumentException * The length of {@code b} is not 6. */ public static long toLong(byte[] b) { checkAddress(b); long num = 0L; int i = 0; do { num <<= Byte.SIZE; num |= b[i] & NumberUtils.MASK_BYTE; i++; } while (i < SIZE); return num; }
From source file:com.jadarstudios.rankcapes.bukkit.network.packet.S0PacketPlayerCapesUpdate.java
@Override public int getSize() { return Byte.SIZE + JSONValue.toJSONString(this.playersMap).getBytes().length; }
From source file:ninja.utils.CookieEncryption.java
@Inject public CookieEncryption(NinjaProperties properties) { Optional<SecretKeySpec> secretKeySpec = Optional.absent(); if (properties.getBooleanWithDefault(NinjaConstant.applicationCookieEncrypted, false)) { encryptionEnabled = true;/* ww w.j av a2 s. c o m*/ String secret = properties.getOrDie(NinjaConstant.applicationSecret); try { int maxKeyLengthBits = Cipher.getMaxAllowedKeyLength(ALGORITHM); if (maxKeyLengthBits == Integer.MAX_VALUE) { maxKeyLengthBits = 256; } secretKeySpec = Optional .of(new SecretKeySpec(secret.getBytes(), 0, maxKeyLengthBits / Byte.SIZE, ALGORITHM)); logger.info("Ninja session encryption is using {} / {} bit.", secretKeySpec.get().getAlgorithm(), maxKeyLengthBits); } catch (Exception exception) { logger.error("Can not create class to encrypt cookie.", exception); throw new RuntimeException(exception); } } else { encryptionEnabled = false; secretKeySpec = Optional.absent(); } this.secretKeySpec = secretKeySpec; }