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:com.frostwire.search.CrawlPagedWebSearchPerformer.java
private static long array2long(byte[] arr) { return Conversion.byteArrayToLong(arr, 0, 0, 0, Long.SIZE / Byte.SIZE); }
From source file:com.delphix.session.impl.frame.SerialNumber.java
@Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { serialBits = in.readByte() & 0xff; // Unsigned byte if (serialBits < Byte.SIZE) { serialNumber = in.readByte();//from ww w . j a va 2 s .c o m } else if (serialBits < Short.SIZE) { serialNumber = in.readShort(); } else if (serialBits < Integer.SIZE) { serialNumber = in.readInt(); } else { serialNumber = in.readLong(); } }
From source file:com.monitor.baseservice.utils.XCodeUtil.java
public static byte[] longToByteArray(long value) { ByteBuffer bb = ByteBuffer.allocate(Long.SIZE / Byte.SIZE); bb.order(ByteOrder.LITTLE_ENDIAN); bb.putLong(value);/*from ww w . j a v a 2 s. c o m*/ return bb.array(); }
From source file:com.facebook.buck.rules.HttpArtifactCache.java
public void storeImpl(RuleKey ruleKey, final File file) throws IOException { Request request = createRequestBuilder(ruleKey.toString()).put(new RequestBody() { @Override/* w w w . j a va 2s .c om*/ public MediaType contentType() { return OCTET_STREAM; } @Override public long contentLength() throws IOException { return Long.SIZE / Byte.SIZE + projectFilesystem.getFileSize(file.toPath()) + hashFunction.bits() / Byte.SIZE; } @Override public void writeTo(BufferedSink sink) throws IOException { try (DataOutputStream output = new DataOutputStream(sink.outputStream()); InputStream input = projectFilesystem.newFileInputStream(file.toPath()); HashingInputStream hasher = new HashingInputStream(hashFunction, input)) { output.writeLong(projectFilesystem.getFileSize(file.toPath())); ByteStreams.copy(hasher, output); output.write(hasher.hash().asBytes()); } } }).build(); Response response = storeCall(request); if (response.code() != HttpURLConnection.HTTP_ACCEPTED) { LOGGER.warn("store(%s): unexpected response: %d", ruleKey, response.code()); } }
From source file:net.sf.xfd.provider.PublicProvider.java
private static @Nullable Key getSalt(Context c) { if (cookieSalt == null) { synchronized (PublicProvider.class) { if (cookieSalt == null) { try { try (ObjectInputStream oos = new ObjectInputStream(c.openFileInput(COOKIE_FILE))) { cookieSalt = (Key) oos.readObject(); } catch (ClassNotFoundException | IOException e) { LogUtil.logCautiously("Unable to read key file, probably corrupted or missing", e); final File corrupted = c.getFileStreamPath(COOKIE_FILE); //noinspection ResultOfMethodCallIgnored corrupted.delete(); }// w w w .j av a 2s. c o m if (cookieSalt != null) { return cookieSalt; } final KeyGenerator keygen = KeyGenerator.getInstance("HmacSHA1"); keygen.init(COOKIE_SIZE * Byte.SIZE); cookieSalt = keygen.generateKey(); try (ObjectOutputStream oos = new ObjectOutputStream( c.openFileOutput(COOKIE_FILE, Context.MODE_PRIVATE))) { oos.writeObject(cookieSalt); } catch (IOException e) { LogUtil.logCautiously("Failed to save key file", e); return null; } } catch (NoSuchAlgorithmException e) { throw new AssertionError("failed to initialize hash functions", e); } } } } return cookieSalt; }
From source file:com.delphix.session.impl.frame.SerialNumber.java
@Override public void writeExternal(ObjectOutput out) throws IOException { out.writeByte(serialBits);//from w w w . j ava 2s . co m if (serialBits < Byte.SIZE) { out.writeByte((int) serialNumber); } else if (serialBits < Short.SIZE) { out.writeShort((int) serialNumber); } else if (serialBits < Integer.SIZE) { out.writeInt((int) serialNumber); } else { out.writeLong(serialNumber); } }
From source file:org.wso2.carbon.analytics.datasource.core.util.GenericUtils.java
private static int calculateBufferSizePerElement(String name, Object value) throws AnalyticsException { int count = 0; /* column name length value + data type (including null) */ count += Integer.SIZE / 8 + 1; /* column name */ count += name.getBytes(StandardCharsets.UTF_8).length; if (value instanceof String) { /* string length + value */ count += Integer.SIZE / 8; count += ((String) value).getBytes(StandardCharsets.UTF_8).length; } else if (value instanceof Long) { count += Long.SIZE / 8;/*from w ww .java2s .c om*/ } else if (value instanceof Double) { count += Double.SIZE / 8; } else if (value instanceof Boolean) { count += Byte.SIZE / 8; } else if (value instanceof Integer) { count += Integer.SIZE / 8; } else if (value instanceof Float) { count += Float.SIZE / 8; } else if (value instanceof byte[]) { count += Integer.SIZE / 8; count += ((byte[]) value).length; } else if (value != null) { count += Integer.SIZE / 8; count += GenericUtils.serializeObject(value).length; } return count; }
From source file:com.linkedin.pinot.core.minion.RawIndexConverter.java
private boolean shouldConvertColumn(FieldSpec fieldSpec) { String columnName = fieldSpec.getName(); FieldSpec.DataType dataType = fieldSpec.getDataType(); int numTotalDocs = _originalSegmentMetadata.getTotalDocs(); ColumnMetadata columnMetadata = _originalSegmentMetadata.getColumnMetadataFor(columnName); int cardinality = columnMetadata.getCardinality(); // In bits// w ww . j a va2 s.co m int lengthOfEachEntry; if (dataType.equals(FieldSpec.DataType.STRING)) { lengthOfEachEntry = columnMetadata.getStringColumnMaxLength() * Byte.SIZE; } else { lengthOfEachEntry = dataType.size() * Byte.SIZE; } long dictionaryBasedIndexSize = (long) numTotalDocs * columnMetadata.getBitsPerElement() + (long) cardinality * lengthOfEachEntry; long rawIndexSize = (long) numTotalDocs * lengthOfEachEntry; LOGGER.info( "For column: {}, size of dictionary based index: {} bits, size of raw index (without compression): {} bits", columnName, dictionaryBasedIndexSize, rawIndexSize); return rawIndexSize <= dictionaryBasedIndexSize * CONVERSION_THRESHOLD; }
From source file:org.springframework.jdbc.repo.impl.jdbc.RawPropertiesRepoImplTest.java
/** * Make sure that repeated calls to {@link RawPropertiesRepo#setProperties(String, Map)} * with same ID and different properties replaces and previous ones *//*ww w .j a v a 2 s . co m*/ @Test public void testSetPropertiesReplacePrevious() { final String ID = getClass().getSimpleName() + "#testSetPropertiesReplacePrevious"; Map<String, Serializable> expected = createEntityProperties(ID); List<Serializable> values = new ArrayList<Serializable>(expected.keySet()); Set<String> names = new TreeSet<String>(expected.keySet()); for (int index = 0; index < Byte.SIZE; index++) { expected.clear(); for (String key : names) { int valPos = RANDOMIZER.nextInt(values.size()); Serializable value = values.get(valPos); expected.put(key, value); } repo.setProperties(ID, expected); } }
From source file:com.github.joulupunikki.math.random.BitsStreamGenerator64.java
/** * Will hash the seed with the SHA-512 digest. Enough bits are generated to * fill all the state bits of the generator. The digests will be chained so * that each new set of 512 bits receives the digest value of the previous * set as initial digest data. This should provide well mixed and * uncorrelated initial states with all seeds. Secure hashing is however * slower than less involved methods of state initialization. * * @param seed_in the seed/*w ww . j a v a 2s .com*/ * @return hashed state array of longs */ public long[] hashSeed(long[] seed_in) { // prepare to hash seed int seed_len = seed_in.length; long[] seed_out = new long[STATE_WORDS]; MessageDigest md = null; try { md = MessageDigest.getInstance("SHA-512"); } catch (Exception e) { //SHA-512 should be available in java 1.5+ throw new RuntimeException(null, e); } int digest_count = (STATE_BITS - 1) / md.getDigestLength() + 1; int digest_bytes = md.getDigestLength() / Byte.SIZE; if (seed_len > digest_count) { seed_len = digest_count; } byte[] hashed_seed = new byte[STATE_WORDS * Long.BYTES]; int s = 0; byte[] r = null; // hash seed for (; s < seed_len; s++) { r = md.digest(PrimitiveConversion.longToByteArray(seed_in[s])); System.arraycopy(r, 0, hashed_seed, s * digest_bytes, digest_bytes); md.update(r); // chain digests } // if out of seed just chain digests for (; s < digest_count; s++) { r = md.digest(); System.arraycopy(r, 0, hashed_seed, s * digest_bytes, digest_bytes); md.update(r); } // convert digest bytes to longs byte[] t = new byte[Long.BYTES]; for (int i = 0; i < STATE_WORDS; i++) { System.arraycopy(hashed_seed, i * Long.BYTES, t, 0, Long.BYTES); seed_out[i] = PrimitiveConversion.byteArrayToLong(t); } return seed_out; }