Java Code Examples for io.vertx.core.json.JsonObject#getBinary()
The following examples show how to use
io.vertx.core.json.JsonObject#getBinary() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DigestBlob.java From sfs with Apache License 2.0 | 6 votes |
public DigestBlob(JsonObject jsonObject) { super(jsonObject); digests = new HashMap<>(); JsonArray jsonArray = jsonObject.getJsonArray("X-Computed-Digests"); if (jsonArray != null) { for (Object o : jsonArray) { JsonObject jsonDigest = (JsonObject) o; String digestName = jsonDigest.getString("name"); byte[] value = jsonDigest.getBinary("value"); Optional<MessageDigestFactory> oMessageDigestFactory = fromValueIfExists(digestName); if (oMessageDigestFactory.isPresent()) { MessageDigestFactory messageDigestFactory = oMessageDigestFactory.get(); withDigest(messageDigestFactory, value); } } } }
Example 2
Source File: Segment.java From sfs with Apache License 2.0 | 5 votes |
public T merge(JsonObject document) { Long id = document.getLong("id"); checkNotNull(id, "id cannot be null"); checkState(id == this.id, "id was %s, expected %s", id, this.id); setReadMd5(document.getBinary("read_md5")); setReadSha512(document.getBinary("read_sha512")); setReadLength(document.getLong("read_length")); setWriteSha512(document.getBinary("write_sha512")); setWriteLength(document.getLong("write_length")); isTinyData = document.getBoolean("is_tiny_data"); tinyData = document.getBinary("tiny_data"); isTinyDataDeleted = document.getBoolean("is_tiny_data_deleted"); String cipherKey = document.getString("container_key_id"); byte[] cipherSalt = document.getBinary("cipher_salt"); segmentCipher = new SegmentCipher(cipherKey, cipherSalt); JsonArray blobJsonArray = document.getJsonArray("blobs"); this.blobs.clear(); if (blobJsonArray != null) { for (Object o : blobJsonArray) { JsonObject jsonObject = (JsonObject) o; TransientBlobReference transientBlobReference = new TransientBlobReference(this).merge(jsonObject); this.blobs.add(transientBlobReference); } } return (T) this; }
Example 3
Source File: BlobReference.java From sfs with Apache License 2.0 | 5 votes |
public T merge(JsonObject jsonObject) { volumeId = jsonObject.getString("volume_id"); position = jsonObject.getLong("position"); readSha512 = jsonObject.getBinary("read_sha512"); readLength = jsonObject.getLong("read_length"); acknowledged = jsonObject.getBoolean("acknowledged"); deleted = jsonObject.getBoolean("deleted"); verifyFailCount = jsonObject.getInteger("verify_fail_count", 0); return (T) this; }
Example 4
Source File: DeviceRegistryUtils.java From hono with Eclipse Public License 2.0 | 5 votes |
/** * Gets the certificate of the device to be provisioned from the client context. * * @param tenantId The tenant to which the device belongs. * @param authId The authentication identifier. * @param clientContext The client context that can be used to get the X.509 certificate * of the device to be provisioned. * @param span The active OpenTracing span for this operation. It is not to be closed in this method! An * implementation should log (error) events on this span and it may set tags and use this span * as the parent for any spans created in this method. * @return A future indicating the outcome of the operation. If the operation succeeds, the * retrieved certificate is returned. Else {@link Optional#empty()} is returned. * @throws NullPointerException if any of the parameters except span is {@code null}. */ public static Future<Optional<X509Certificate>> getCertificateFromClientContext( final String tenantId, final String authId, final JsonObject clientContext, final Span span) { Objects.requireNonNull(tenantId); Objects.requireNonNull(authId); Objects.requireNonNull(clientContext); try { final byte[] bytes = clientContext.getBinary(CredentialsConstants.FIELD_CLIENT_CERT); if (bytes == null) { return Future.succeededFuture(Optional.empty()); } final CertificateFactory factory = CertificateFactory.getInstance("X.509"); final X509Certificate cert = (X509Certificate) factory.generateCertificate(new ByteArrayInputStream(bytes)); if (!cert.getSubjectX500Principal().getName(X500Principal.RFC2253).equals(authId)) { throw new IllegalArgumentException( String.format("Subject DN of the client certificate does not match authId [%s] for tenant [%s]", authId, tenantId)); } return Future.succeededFuture(Optional.of(cert)); } catch (final CertificateException | ClassCastException | IllegalArgumentException error) { final String errorMessage = String.format( "Error getting certificate from client context with authId [%s] for tenant [%s]", authId, tenantId); LOG.error(errorMessage, error); TracingHelper.logError(span, errorMessage, error); return Future .failedFuture(new ClientErrorException(HttpURLConnection.HTTP_BAD_REQUEST, errorMessage, error)); } }
Example 5
Source File: DefaultDeviceResolver.java From hono with Eclipse Public License 2.0 | 5 votes |
private static SecretKey getKey(final JsonObject candidateSecret) { try { final byte[] encodedKey = candidateSecret.getBinary(CredentialsConstants.FIELD_SECRETS_KEY); return SecretUtil.create(encodedKey, "PSK"); } catch (IllegalArgumentException | ClassCastException e) { return null; } }
Example 6
Source File: MailAttachmentImpl.java From vertx-mail-client with Apache License 2.0 | 5 votes |
/** * create a MailAttachmentImpl object from a JsonObject representation * * @param json object to be copied */ public MailAttachmentImpl(final JsonObject json) { Objects.requireNonNull(json); this.data = json.getBinary("data") == null ? null : Buffer.buffer(json.getBinary("data")); this.name = json.getString("name"); this.contentType = json.getString("contentType"); this.disposition = json.getString("disposition"); this.description = json.getString("description"); this.contentId = json.getString("contentId"); JsonObject headers = json.getJsonObject("headers"); if (headers != null) { this.headers = Utils.jsonToMultiMap(headers); } this.size = json.getInteger("size", -1); }
Example 7
Source File: FailureImpl.java From vertx-unit with Apache License 2.0 | 5 votes |
public FailureImpl(JsonObject json) { byte[] tmp = json.getBinary("cause"); Throwable t = null; if (tmp != null) { try { ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(tmp)); t = (Throwable) ois.readObject(); } catch (Exception ignore) { } } error = json.getBoolean("error"); message = json.getString("message"); stackTrace = json.getString("stackTrace"); cause = t; }
Example 8
Source File: JsonObjectCodec.java From vertx-mongo-client with Apache License 2.0 | 5 votes |
@Override protected void writeBinary(BsonWriter writer, String name, Object value, EncoderContext ctx) { JsonObject binaryJsonObject = (JsonObject) value; byte type = Optional.ofNullable(binaryJsonObject.getInteger(TYPE_FIELD)) .map(Integer::byteValue) .orElse(BsonBinarySubType.BINARY.getValue()); final BsonBinary bson = new BsonBinary(type, binaryJsonObject.getBinary(BINARY_FIELD)); writer.writeBinaryData(bson); }
Example 9
Source File: JsonObjectCodecTest.java From vertx-mongo-client with Apache License 2.0 | 5 votes |
@Test public void readDocument_supportBsonBinary() { JsonObjectCodec codec = new JsonObjectCodec(options); Instant now = Instant.now(); BsonDocument bson = new BsonDocument(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { ObjectOutputStream oos = new ObjectOutputStream(baos); oos.writeObject(now); oos.close(); bson.append("test", new BsonBinary(baos.toByteArray())); BsonDocumentReader reader = new BsonDocumentReader(bson); JsonObject result = codec.readDocument(reader, DecoderContext.builder().build()); JsonObject resultValue = result.getJsonObject("test"); byte[] bytes = resultValue.getBinary(JsonObjectCodec.BINARY_FIELD); ByteArrayInputStream bais = new ByteArrayInputStream(bytes); ObjectInputStream ois = new ObjectInputStream(bais); Instant reconstitutedNow = (Instant) ois.readObject(); assertEquals(now, reconstitutedNow); } catch (IOException | ClassNotFoundException e) { e.printStackTrace(); assertTrue(false); } }
Example 10
Source File: DataObjectWithNestedBuffer.java From vertx-codegen with Apache License 2.0 | 5 votes |
public DataObjectWithNestedBuffer(JsonObject json) { byte[] buffer = json.getBinary("buffer"); this.buffer = buffer != null ? Buffer.buffer(buffer) : null; JsonObject nested = json.getJsonObject("nested"); this.nested = nested != null ? new DataObjectWithBuffer(nested) : null; JsonArray buffers_ = json.getJsonArray("buffers"); if (buffers_ != null) { this.buffers = new ArrayList<>(); for (int i = 0;i < buffers_.size();i++) { buffers.add(Buffer.buffer(buffers_.getBinary(i))); } } }
Example 11
Source File: StoreVerticle.java From vertx-mqtt-broker with Apache License 2.0 | 5 votes |
private JsonObject saveRetainMessage(JsonObject request) { String topic = request.getString("topic"); String tenant = request.getString("tenant"); byte[] message = request.getBinary("message"); Map<String, byte[]> db = db(tenant); db.put(topic, message); JsonObject response = new JsonObject(); response.put("topic", topic).put("message", message); return response; }
Example 12
Source File: MQTTJson.java From vertx-mqtt-broker with Apache License 2.0 | 5 votes |
public PublishMessage deserializePublishMessage(JsonObject json) { PublishMessage ret = new PublishMessage(); ret.setTopicName(json.getString("topicName")); AbstractMessage.QOSType qos = AbstractMessage.QOSType.valueOf(json.getString("qos")); ret.setQos(qos); byte[] payload = json.getBinary("payload"); ret.setPayload(ByteBuffer.wrap(payload)); if(qos == AbstractMessage.QOSType.LEAST_ONE || qos == AbstractMessage.QOSType.EXACTLY_ONCE) { ret.setMessageID(json.getInteger("messageID")); } return ret; }
Example 13
Source File: ByteKafkaMessage.java From vertx-kafka-service with Apache License 2.0 | 4 votes |
public ByteKafkaMessage(JsonObject jsonObject) { super(jsonObject.getString(PART_KEY)); this.payload = jsonObject.getBinary(PAYLOAD) != null ? Buffer.buffer(jsonObject.getBinary(PAYLOAD)) : null; }
Example 14
Source File: DataObjectWithBuffer.java From vertx-codegen with Apache License 2.0 | 4 votes |
public DataObjectWithBuffer(JsonObject json) { byte[] buffer = json.getBinary("buffer"); this.buffer = buffer != null ? Buffer.buffer(buffer) : null; }