if (mt != null) {
ctString = JAXRSUtils.mediaTypeToString(mt);
}
}
if (useJwsOutputStream) {
JwtHeaders headers = new JwtHeaders();
JwsSignature jwsSignature = getInitializedSigProvider().createJwsSignature(headers);
if (ctString != null) {
headers.setContentType(ctString);
}
JwsOutputStream jwsStream = new JwsOutputStream(actualOs, jwsSignature);
byte[] headerBytes = writer.headersToJson(headers).getBytes("UTF-8");
Base64UrlUtility.encodeAndStream(headerBytes, 0, headerBytes.length, jwsStream);
jwsStream.write(new byte[]{'.'});
Base64UrlOutputStream base64Stream = new Base64UrlOutputStream(jwsStream);
ctx.setOutputStream(base64Stream);
ctx.proceed();
base64Stream.flush();
jwsStream.flush();
} else {
CachedOutputStream cos = new CachedOutputStream();
ctx.setOutputStream(cos);
ctx.proceed();
JwtHeaders headers = new JwtHeaders();
if (ctString != null) {
headers.setContentType(ctString);
}
JwsCompactProducer p = new JwsCompactProducer(headers, new String(cos.getBytes(), "UTF-8"));
writeJws(p, actualOs);
}
}