List of usage examples for java.lang Integer BYTES
int BYTES
To view the source code for java.lang Integer BYTES.
Click Source Link
From source file:edu.umass.cs.gigapaxos.paxospackets.RequestPacket.java
static int sizeof(Class<?> clazz) { switch (clazz.getSimpleName()) { case "int": return Integer.BYTES; case "long": return Long.BYTES; case "boolean": return 1; case "short": return Short.BYTES; case "InetSocketAddress": return Integer.BYTES + Short.BYTES; }//from w w w.j a v a2 s. c o m assert (false) : clazz; return -1; }
From source file:de.micromata.genome.logging.spi.ifiles.IndexHeader.java
public void writLogEntryPosition(LogWriteEntry lwe, int position, OutputStream idxOut) throws IOException { ByteBuffer ibb = ByteBuffer.wrap(new byte[Integer.BYTES]); ByteBuffer lbb = ByteBuffer.wrap(new byte[Long.BYTES]); lbb.putLong(lwe.getTimestamp());//ww w . ja va 2 s. c om idxOut.write(lbb.array()); ibb.putInt(position); idxOut.write(ibb.array()); idxOut.flush(); }
From source file:org.cryptomator.crypto.aes256.Aes256CryptorTest.java
License:asdf
@Test public void testPartialDecryption() throws IOException, DecryptFailedException, WrongPasswordException, UnsupportedKeyLengthException { // our test plaintext data: final byte[] plaintextData = new byte[65536 * Integer.BYTES]; final ByteBuffer bbIn = ByteBuffer.wrap(plaintextData); for (int i = 0; i < 65536; i++) { bbIn.putInt(i);//w w w. ja va 2 s. c om } final InputStream plaintextIn = new ByteArrayInputStream(plaintextData); // init cryptor: final Aes256Cryptor cryptor = new Aes256Cryptor(TEST_PRNG); // encrypt: final ByteBuffer encryptedData = ByteBuffer.allocate((int) (64 + plaintextData.length * 1.2)); final SeekableByteChannel encryptedOut = new ByteBufferBackedSeekableChannel(encryptedData); cryptor.encryptFile(plaintextIn, encryptedOut); IOUtils.closeQuietly(plaintextIn); IOUtils.closeQuietly(encryptedOut); encryptedData.position(0); // decrypt: final SeekableByteChannel encryptedIn = new ByteBufferBackedSeekableChannel(encryptedData); final ByteArrayOutputStream plaintextOut = new ByteArrayOutputStream(); final Long numDecryptedBytes = cryptor.decryptRange(encryptedIn, plaintextOut, 25000 * Integer.BYTES, 30000 * Integer.BYTES); IOUtils.closeQuietly(encryptedIn); IOUtils.closeQuietly(plaintextOut); Assert.assertTrue(numDecryptedBytes > 0); // check decrypted data: final byte[] result = plaintextOut.toByteArray(); final byte[] expected = Arrays.copyOfRange(plaintextData, 25000 * Integer.BYTES, 55000 * Integer.BYTES); Assert.assertArrayEquals(expected, result); }
From source file:org.apache.druid.query.aggregation.histogram.ApproximateHistogramAggregatorFactory.java
@Override public byte[] getCacheKey() { byte[] fieldNameBytes = StringUtils.toUtf8(fieldName); return ByteBuffer.allocate(1 + fieldNameBytes.length + Integer.BYTES * 2 + Float.BYTES * 2) .put(AggregatorUtil.APPROX_HIST_CACHE_TYPE_ID).put(fieldNameBytes).putInt(resolution) .putInt(numBuckets).putFloat(lowerLimit).putFloat(upperLimit).array(); }
From source file:org.gradoop.flink.model.impl.operators.matching.single.cypher.pojos.Embedding.java
/** * Adds the list of properties to the embedding * * @param properties new properties//from w w w . jav a 2 s . co m */ public void addPropertyValues(PropertyValue... properties) { int newPropertiesSize = propertyData.length; for (PropertyValue property : properties) { newPropertiesSize += property.getByteSize() + Integer.BYTES; } byte[] newPropertyData = new byte[newPropertiesSize]; System.arraycopy(propertyData, 0, newPropertyData, 0, propertyData.length); int offset = propertyData.length; for (PropertyValue property : properties) { writeProperty(property, newPropertyData, offset); offset += property.getByteSize() + Integer.BYTES; } this.propertyData = newPropertyData; }
From source file:org.gradoop.flink.model.impl.operators.matching.single.cypher.pojos.Embedding.java
/** * Returns the property stored at the specified column * @param column the properties index in the property list * @return the property stored at the specified index *//*from w w w. j a v a 2s . co m*/ public PropertyValue getProperty(int column) { int offset = getPropertyOffset(column); int entryLength = Ints.fromByteArray(ArrayUtils.subarray(propertyData, offset, offset + Integer.BYTES)); offset += Integer.BYTES; return PropertyValue.fromRawBytes(ArrayUtils.subarray(propertyData, offset, offset + entryLength)); }
From source file:com.github.ambry.utils.UtilsTest.java
@Test public void testGetIntStringLength() { for (int i = 0; i < 10; i++) { String value = getRandomString(1000 + TestUtils.RANDOM.nextInt(10000)); assertEquals("Size mismatch ", Integer.BYTES + value.length(), Utils.getIntStringLength(value)); }//from w ww .j a v a2s . c o m assertEquals("Size mismatch for empty string ", Integer.BYTES, Utils.getIntStringLength("")); assertEquals("Size mismatch for null string ", Integer.BYTES, Utils.getIntStringLength(null)); }
From source file:org.gradoop.flink.model.impl.operators.matching.single.cypher.pojos.Embedding.java
/** * Returns the internal representation of the property stored at the specified column * @param column the properties index in the property list * @return Internal representation of the property stored at the specified column *//*from ww w . ja va 2 s . c o m*/ public byte[] getRawProperty(int column) { int offset = getPropertyOffset(column); int entryLength = Ints.fromByteArray(ArrayUtils.subarray(propertyData, offset, offset + Integer.BYTES)); return ArrayUtils.subarray(propertyData, offset, offset + Integer.BYTES + entryLength); }
From source file:org.gradoop.flink.model.impl.operators.matching.single.cypher.pojos.Embedding.java
/** * Returns a list of all property values stored in the embedding * @return List of all property values stored in the embedding *//*from w ww .j a va 2 s .co m*/ public List<PropertyValue> getProperties() { List<PropertyValue> properties = new ArrayList<>(); int offset = 0; int entrySize; while (offset < propertyData.length) { entrySize = Ints.fromByteArray(ArrayUtils.subarray(propertyData, offset, offset + Integer.BYTES)); offset += Integer.BYTES; properties .add(PropertyValue.fromRawBytes(ArrayUtils.subarray(propertyData, offset, offset + entrySize))); offset += entrySize; } return properties; }
From source file:org.gradoop.flink.model.impl.operators.matching.single.cypher.pojos.Embedding.java
/** * Returns the offset of the property in the propertyData array * @param column the index of the property * @return Offset of the property in the propertyData array *//*from ww w . j av a2 s .c o m*/ private int getPropertyOffset(int column) { int i = 0; int offset = 0; int entryLength; while (i < column && offset < propertyData.length) { entryLength = Ints.fromByteArray(ArrayUtils.subarray(propertyData, offset, offset + Integer.BYTES)); offset += entryLength + Integer.BYTES; i++; } if (offset >= propertyData.length) { throw new IndexOutOfBoundsException("Cant find Property. " + (i - 1) + " < " + column); } return offset; }