io.jsonwebtoken.lang.Objects Java Examples
The following examples show how to use
io.jsonwebtoken.lang.Objects.
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: GzipCompressionCodec.java From lams with GNU General Public License v2.0 | 5 votes |
protected byte[] doCompress(byte[] payload) throws IOException { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); GZIPOutputStream compressorOutputStream = new GZIPOutputStream(outputStream, true); try { compressorOutputStream.write(payload, 0, payload.length); compressorOutputStream.finish(); return outputStream.toByteArray(); } finally { Objects.nullSafeClose(compressorOutputStream, outputStream); } }
Example #2
Source File: JjwtSerializer.java From ditto with Eclipse Public License 2.0 | 5 votes |
private static JsonValue toJson(final Object input) { if (input == null) { return JsonFactory.nullLiteral(); } else if (input instanceof Boolean) { return JsonFactory.newValue((boolean) input); } else if (input instanceof Byte || input instanceof Short || input instanceof Integer) { return JsonFactory.newValue((int) input); } else if (input instanceof Long) { return JsonFactory.newValue((long) input); } else if (input instanceof Float) { return JsonFactory.newValue((float) input); } else if (input instanceof Double) { return JsonFactory.newValue((double) input); } else if (input instanceof Character || input instanceof String || input instanceof Enum) { return JsonFactory.newValue(input.toString()); } else if (input instanceof Calendar) { return JsonFactory.newValue(DateFormats.formatIso8601(((Calendar) input).getTime())); } else if (input instanceof Date) { return JsonFactory.newValue(DateFormats.formatIso8601((Date) input)); } else if (input instanceof byte[]) { return JsonFactory.newValue(Encoders.BASE64.encode((byte[]) input)); } else if (input instanceof char[]) { return JsonFactory.newValue(new String((char[]) input)); } else if (input instanceof Map) { return toJsonObject((Map<?, ?>) input); } else if (input instanceof Collection) { return toJsonArray((Collection<?>) input); } else if (Objects.isArray(input)) { return toJsonArray(Collections.arrayToList(input)); } throw new SerializationException("Unable to serialize object of type " + input.getClass().getName() + " to JSON using known heuristics."); }
Example #3
Source File: JWTPolicy.java From apiman-plugins with Apache License 2.0 | 5 votes |
private void forwardHeaders(ApiRequest request, JWTPolicyBean config, String rawToken, Map<String, Object> claims) { for (ForwardAuthInfo entry : config.getForwardAuthInfo()) { // Add the header if we've been able to look it up, else it'll just be empty. Object claimValue = ACCESS_TOKEN_QUERY_KEY.equals(entry.getField()) ? rawToken : claims.get(entry.getField()); if (claimValue != null) { request.getHeaders().put(entry.getHeader(), Objects.nullSafeToString(claimValue)); } } }
Example #4
Source File: AbstractCompressionCodec.java From jjwt with Apache License 2.0 | 5 votes |
byte[] readAndClose(InputStream input) throws IOException { byte[] buffer = new byte[512]; ByteArrayOutputStream out = new ByteArrayOutputStream(buffer.length); int read; try { read = input.read(buffer); //assignment separate from loop invariant check for code coverage checks while (read != -1) { out.write(buffer, 0, read); read = input.read(buffer); } } finally { Objects.nullSafeClose(input); } return out.toByteArray(); }
Example #5
Source File: AbstractCompressionCodec.java From jjwt with Apache License 2.0 | 5 votes |
byte[] writeAndClose(byte[] payload, StreamWrapper wrapper) throws IOException { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(512); OutputStream compressionStream = wrapper.wrap(outputStream); try { compressionStream.write(payload); compressionStream.flush(); } finally { Objects.nullSafeClose(compressionStream); } return outputStream.toByteArray(); }
Example #6
Source File: OrgJsonSerializer.java From jjwt with Apache License 2.0 | 4 votes |
private Object toJSONInstance(Object object) { if (object == null) { return JSONObject.NULL; } if (object instanceof JSONObject || object instanceof JSONArray || JSONObject.NULL.equals(object) || isJSONString(object) || object instanceof Byte || object instanceof Character || object instanceof Short || object instanceof Integer || object instanceof Long || object instanceof Boolean || object instanceof Float || object instanceof Double || object instanceof String || object instanceof BigInteger || object instanceof BigDecimal || object instanceof Enum) { return object; } if (object instanceof Calendar) { object = ((Calendar) object).getTime(); //sets object to date, will be converted in next if-statement: } if (object instanceof Date) { Date date = (Date) object; return DateFormats.formatIso8601(date); } if (object instanceof byte[]) { return Encoders.BASE64.encode((byte[]) object); } if (object instanceof char[]) { return new String((char[]) object); } if (object instanceof Map) { Map<?, ?> map = (Map<?, ?>) object; return toJSONObject(map); } if (object instanceof Collection) { Collection<?> coll = (Collection<?>) object; return toJSONArray(coll); } if (Objects.isArray(object)) { Collection c = Collections.arrayToList(object); return toJSONArray(c); } //not an immediately JSON-compatible object and probably a JavaBean (or similar). We can't convert that //directly without using a marshaller of some sort: String msg = "Unable to serialize object of type " + object.getClass().getName() + " to JSON using known heuristics."; throw new SerializationException(msg); }