ByteSourceJsonBootstrapper strapper = new ByteSourceJsonBootstrapper(jacksonIOContext, buff, 0, 4); JsonEncoding jsonEncoding = strapper.detectEncoding(); if (!JsonEncoding.UTF8.equals(jsonEncoding)) { throw new InvalidEncodingException(jsonEncoding.getJavaName(), "currently only UTF-8 is supported");
/** * Check whether the encoding is valid. * @param in input of bytes * @throws IOException this is an IO exception * @throws UnsupportedException this is an unsupported exception */ private static void checkEncoding(ByteBuf in) throws IOException { int inputStart = 0; int inputLength = 4; fliterCharaters(in); byte[] buff = new byte[4]; in.getBytes(in.readerIndex(), buff); ByteSourceJsonBootstrapper strapper = new ByteSourceJsonBootstrapper(new IOContext(new BufferRecycler(), null, false), buff, inputStart, inputLength); JsonEncoding jsonEncoding = strapper.detectEncoding(); if (!JsonEncoding.UTF8.equals(jsonEncoding)) { throw new UnsupportedException("Only UTF-8 encoding is supported."); } }