List of usage examples for java.nio ByteBuffer putLong
public abstract ByteBuffer putLong(long value);
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()); idxOut.write(lbb.array());//from w w w.j ava 2 s . c o m ibb.putInt(position); idxOut.write(ibb.array()); idxOut.flush(); }
From source file:org.getspout.spoutapi.packet.PacketEntityInformation.java
public PacketEntityInformation(List<LivingEntity> entities) { ByteBuffer tempbuffer = ByteBuffer.allocate(entities.size() * 20); //4 bytes for entity id, 16 for uuid for (Entity e : entities) { tempbuffer.putLong(e.getUniqueId().getLeastSignificantBits()); tempbuffer.putLong(e.getUniqueId().getMostSignificantBits()); tempbuffer.putInt(e.getEntityId()); }// w w w . j a v a2 s.c o m data = tempbuffer.array(); }
From source file:org.hashtrees.store.HashTreesPersistentStore.java
@Override public void setCompleteRebuiltTimestamp(long treeId, long ts) { byte[] value = new byte[ByteUtils.SIZEOF_LONG]; ByteBuffer bbValue = ByteBuffer.wrap(value); bbValue.putLong(ts); byte[] key = generateMetaDataKey(MetaDataKey.FULL_REBUILT_TS, treeId); dbObj.put(key, value);/*w ww. j a va2 s . co m*/ }
From source file:org.apache.distributedlog.DLSN.java
/** * Serialize the DLSN into bytes with given <code>version</code>. * * @param version//from w ww . jav a 2s. c o m * version to serialize the DLSN * @return the serialized bytes */ public byte[] serializeBytes(byte version) { checkArgument(version <= CUR_VERSION && version >= VERSION0); byte[] data = new byte[CUR_VERSION == version ? VERSION1_LEN : VERSION0_LEN]; ByteBuffer bb = ByteBuffer.wrap(data); bb.put(version); bb.putLong(logSegmentSequenceNo); bb.putLong(entryId); bb.putLong(slotId); return data; }
From source file:com.twitter.distributedlog.DLSN.java
/** * Serialize the DLSN into bytes with given <code>version</code>. * * @param version/* www . j a va 2s.co m*/ * version to serialize the DLSN * @return the serialized bytes */ public byte[] serializeBytes(byte version) { Preconditions.checkArgument(version <= CUR_VERSION && version >= VERSION0); byte[] data = new byte[CUR_VERSION == version ? VERSION1_LEN : VERSION0_LEN]; ByteBuffer bb = ByteBuffer.wrap(data); bb.put(version); bb.putLong(logSegmentSequenceNo); bb.putLong(entryId); bb.putLong(slotId); return data; }
From source file:io.warp10.quasar.encoder.QuasarTokenEncoder.java
public String getTokenIdent(String token, byte[] tokenSipHashkey) { long ident = SipHashInline.hash24_palindromic(tokenSipHashkey, token.getBytes()); ByteBuffer buffer = ByteBuffer.allocate(Long.BYTES); buffer.order(ByteOrder.BIG_ENDIAN); buffer.putLong(ident); return Hex.encodeHexString(buffer.array()); }
From source file:io.warp10.quasar.encoder.QuasarTokenEncoder.java
public String cypherToken(TBase<?, ?> token, KeyStore keyStore) throws TException { byte[] tokenAesKey = keyStore.getKey(KeyStore.AES_TOKEN); byte[] tokenSipHashkey = keyStore.getKey(KeyStore.SIPHASH_TOKEN); // Serialize the thrift token into byte array byte[] serialized = serializer.serialize(token); // Calculate the SIP long sip = SipHashInline.hash24_palindromic(tokenSipHashkey, serialized); //Create the token byte buffer ByteBuffer buffer = ByteBuffer.allocate(8 + serialized.length); // adds the sip buffer.putLong(sip); // adds the thrift token buffer.put(serialized);// w ww. ja v a 2 s . c om // Wrap the TOKEN byte[] wrappedData = CryptoUtils.wrap(tokenAesKey, buffer.array()); String accessToken = new String(OrderPreservingBase64.encode(wrappedData)); return accessToken; }
From source file:org.apache.pulsar.broker.admin.v2.SchemasResource.java
@GET @Path("/{tenant}/{namespace}/{topic}/schema/{version}") @Produces(MediaType.APPLICATION_JSON)//from w w w . j av a 2s . c o m @ApiOperation(value = "Get the schema of a topic at a given version", response = GetSchemaResponse.class) @ApiResponses(value = { @ApiResponse(code = 307, message = "Current broker doesn't serve the namespace of this topic"), @ApiResponse(code = 401, message = "Client is not authorized or Don't have admin permission"), @ApiResponse(code = 403, message = "Client is not authenticated"), @ApiResponse(code = 404, message = "Tenant or Namespace or Topic doesn't exist; or Schema is not found for this topic"), @ApiResponse(code = 412, message = "Failed to find the ownership for the topic"), }) public void getSchema(@PathParam("tenant") String tenant, @PathParam("namespace") String namespace, @PathParam("topic") String topic, @PathParam("version") @Encoded String version, @QueryParam("authoritative") @DefaultValue("false") boolean authoritative, @Suspended final AsyncResponse response) { validateDestinationAndAdminOperation(tenant, namespace, topic, authoritative); String schemaId = buildSchemaId(tenant, namespace, topic); ByteBuffer bbVersion = ByteBuffer.allocate(Long.SIZE); bbVersion.putLong(Long.parseLong(version)); SchemaVersion v = pulsar().getSchemaRegistryService().versionFromBytes(bbVersion.array()); pulsar().getSchemaRegistryService().getSchema(schemaId, v).handle((schema, error) -> { if (isNull(error)) { if (isNull(schema)) { response.resume(Response.status(Response.Status.NOT_FOUND).build()); } else if (schema.schema.isDeleted()) { response.resume(Response.status(Response.Status.NOT_FOUND).build()); } else { response.resume(Response.ok().encoding(MediaType.APPLICATION_JSON) .entity(GetSchemaResponse.builder().version(getLongSchemaVersion(schema.version)) .type(schema.schema.getType()).timestamp(schema.schema.getTimestamp()) .data(new String(schema.schema.getData())).properties(schema.schema.getProps()) .build()) .build()); } } else { response.resume(error); } return null; }); }
From source file:com.codeabovelab.dm.common.security.token.SignedTokenServiceBackend.java
private byte[] contentPack(long creationTime, byte[] random, byte[] serverSecret, byte[] payload) { ByteBuffer buffer = ByteBuffer .allocate(8 + 1 + random.length + 1 + serverSecret.length + 1 + payload.length); buffer.putLong(creationTime); store(buffer, random);/*from www .ja v a2s. c om*/ store(buffer, serverSecret); store(buffer, payload); return buffer.array(); }
From source file:edu.umn.cs.spatialHadoop.core.ZCurvePartitioner.java
@Override public void write(DataOutput out) throws IOException { mbr.write(out);//from www . j a v a 2 s . c om out.writeInt(zSplits.length); ByteBuffer bbuffer = ByteBuffer.allocate(zSplits.length * 8); for (long zSplit : zSplits) bbuffer.putLong(zSplit); if (bbuffer.hasRemaining()) throw new RuntimeException("Did not calculate buffer size correctly"); out.write(bbuffer.array(), bbuffer.arrayOffset(), bbuffer.position()); }