use of jakarta.json.JsonWriter in project resteasy by resteasy.
the class JsonObjectProvider method writeTo.
@Override
public void writeTo(JsonObject jsonObject, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException, WebApplicationException {
LogMessages.LOGGER.debugf("Provider : %s, Method : writeTo", getClass().getName());
JsonWriter writer = findWriter(mediaType, entityStream);
try {
writer.writeObject(jsonObject);
} finally {
writer.close();
}
}
use of jakarta.json.JsonWriter in project resteasy by resteasy.
the class JsonStructureProvider method writeTo.
@Override
public void writeTo(JsonStructure jsonStructure, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException, WebApplicationException {
LogMessages.LOGGER.debugf("Provider : %s, Method : writeTo", getClass().getName());
JsonWriter writer = findWriter(mediaType, entityStream);
try {
writer.write(jsonStructure);
} finally {
writer.close();
}
}
use of jakarta.json.JsonWriter in project zilla by aklivity.
the class KafkaCachePartition method writeEntryFinish.
public void writeEntryFinish(ArrayFW<KafkaHeaderFW> headers, KafkaDeltaType deltaType) {
final Node head = sentinel.previous;
assert head != sentinel;
final KafkaCacheSegment headSegment = head.segment;
assert headSegment != null;
final KafkaCacheFile logFile = headSegment.logFile();
final KafkaCacheFile deltaFile = headSegment.deltaFile();
final KafkaCacheFile hashFile = headSegment.hashFile();
final KafkaCacheFile indexFile = headSegment.indexFile();
final int logAvailable = logFile.available();
final int logRequired = headers.sizeof();
assert logAvailable >= logRequired : String.format("%s %d >= %d", headSegment, logAvailable, logRequired);
logFile.appendBytes(headers);
final long offsetDelta = (int) (progress - headSegment.baseOffset());
final long indexEntry = (offsetDelta << 32) | logFile.markValue();
if (!headers.isEmpty()) {
final DirectBuffer buffer = headers.buffer();
final ByteBuffer byteBuffer = buffer.byteBuffer();
assert byteBuffer != null;
byteBuffer.clear();
headers.forEach(h -> {
final long hash = computeHash(h);
final long hashEntry = (hash << 32) | logFile.markValue();
hashFile.appendLong(hashEntry);
});
}
assert indexFile.available() >= Long.BYTES;
indexFile.appendLong(indexEntry);
final KafkaCacheEntryFW headEntry = logFile.readBytes(logFile.markValue(), headEntryRO::wrap);
if (deltaType == JSON_PATCH && ancestorEntry != null && ancestorEntry.valueLen() != -1 && headEntry.valueLen() != -1) {
final OctetsFW ancestorValue = ancestorEntry.value();
final OctetsFW headValue = headEntry.value();
assert headEntry.offset$() == progress;
final JsonProvider json = JsonProvider.provider();
ancestorIn.wrap(ancestorValue.buffer(), ancestorValue.offset(), ancestorValue.sizeof());
final JsonReader ancestorReader = json.createReader(ancestorIn);
final JsonStructure ancestorJson = ancestorReader.read();
ancestorReader.close();
headIn.wrap(headValue.buffer(), headValue.offset(), headValue.sizeof());
final JsonReader headReader = json.createReader(headIn);
final JsonStructure headJson = headReader.read();
headReader.close();
final JsonPatch diff = json.createDiff(ancestorJson, headJson);
final JsonArray diffJson = diff.toJsonArray();
diffOut.wrap(diffBuffer, Integer.BYTES);
final JsonWriter writer = json.createWriter(diffOut);
writer.write(diffJson);
writer.close();
// TODO: signal delta.sizeof > head.sizeof via null delta, otherwise delta file can exceed log file
final int deltaLength = diffOut.position();
diffBuffer.putInt(0, deltaLength);
deltaFile.appendBytes(diffBuffer, 0, Integer.BYTES + deltaLength);
}
headSegment.lastOffset(progress);
}
use of jakarta.json.JsonWriter in project glassfish-hk2 by eclipse-ee4j.
the class JsonParser method marshal.
/* (non-Javadoc)
* @see org.glassfish.hk2.xml.spi.XmlServiceParser#marshall(java.io.OutputStream, org.glassfish.hk2.xml.api.XmlRootHandle)
*/
@Override
public <T> void marshal(OutputStream outputStream, XmlRootHandle<T> rootHandle, Map<String, Object> options) throws IOException {
JsonObjectBuilder objectBuilder = Json.createObjectBuilder();
T root = rootHandle.getRoot();
JsonObject rootObject = createJsonObject((BaseHK2JAXBBean) root, objectBuilder);
Map<String, Object> config = new HashMap<String, Object>();
config.put(JsonGenerator.PRETTY_PRINTING, Boolean.TRUE);
JsonWriterFactory writerFactory = Json.createWriterFactory(config);
JsonWriter writer = writerFactory.createWriter(outputStream);
try {
writer.writeObject(rootObject);
} finally {
writer.close();
}
}
use of jakarta.json.JsonWriter in project avro-util by linkedin.
the class JsonPropertiesContainerImpl method toString.
@Override
public String toString() {
if (props.isEmpty()) {
return "{}";
}
JsonObjectBuilder ob = Json.createObjectBuilder();
props.forEach(ob::add);
JsonObject object = ob.build();
StringWriter sw = new StringWriter();
try (JsonWriter writer = JSON_FACTORY.createWriter(sw)) {
writer.write(object);
}
return sw.toString();
}
Aggregations