Java Code Examples for com.alibaba.fastjson.util.IOUtils#UTF8
The following examples show how to use
com.alibaba.fastjson.util.IOUtils#UTF8 .
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: JSON.java From uavstack with Apache License 2.0 | 6 votes |
/** * @since 1.2.11 */ @SuppressWarnings("unchecked") public static <T> T parseObject(byte[] bytes, int offset, int len, Charset charset, Type clazz, Feature... features) { if (charset == null) { charset = IOUtils.UTF8; } String strVal; if (charset == IOUtils.UTF8) { char[] chars = allocateChars(bytes.length); int chars_len = IOUtils.decodeUTF8(bytes, offset, len, chars); if (chars_len < 0) { return null; } strVal = new String(chars, 0, chars_len); } else { if (len < 0) { return null; } strVal = new String(bytes, offset, len, charset); } return (T) parseObject(strVal, clazz, features); }
Example 2
Source File: SerializeWriter.java From uavstack with Apache License 2.0 | 5 votes |
public int writeToEx(OutputStream out, Charset charset) throws IOException { if (this.writer != null) { throw new UnsupportedOperationException("writer not null"); } if (charset == IOUtils.UTF8) { return encodeToUTF8(out); } else { byte[] bytes = new String(buf, 0, count).getBytes(charset); out.write(bytes); return bytes.length; } }
Example 3
Source File: SerializeWriter.java From uavstack with Apache License 2.0 | 5 votes |
public byte[] toBytes(Charset charset) { if (this.writer != null) { throw new UnsupportedOperationException("writer not null"); } if (charset == IOUtils.UTF8) { return encodeToUTF8Bytes(); } else { return new String(buf, 0, count).getBytes(charset); } }
Example 4
Source File: JSON.java From uavstack with Apache License 2.0 | 5 votes |
/** * @since 1.2.11 */ @SuppressWarnings("unchecked") public static <T> T parseObject(InputStream is, // Charset charset, // Type type, // Feature... features) throws IOException { if (charset == null) { charset = IOUtils.UTF8; } byte[] bytes = allocateBytes(1024 * 64); int offset = 0; for (;;) { int readCount = is.read(bytes, offset, bytes.length - offset); if (readCount == -1) { break; } offset += readCount; if (offset == bytes.length) { byte[] newBytes = new byte[bytes.length * 3 / 2]; System.arraycopy(bytes, 0, newBytes, 0, bytes.length); bytes = newBytes; } } return (T) parseObject(bytes, 0, offset, charset, type, features); }