com.faster .jackson.databind. Mapper 在默认的情况下在写出输入后将会关闭输出流(output stream)。
如果你希望序列化多值变量在同一个输出流的情况下,你不希望在输出完一个就关闭输出流,你可以设置 JsonGenerator.Feature.AUTO_CLOSE_TARGET 参数为 False。
/** * Serialization Not Close output stream */@Testpublic void testMessagePackSerializationNotCloseOutputStream() { logger.debug("testMessagePackSerializationNotCloseOutputStream"); try { File tempFile = File.createTempFile("messagepack-", "-cwiki.us"); OutputStream out = new FileOutputStream(tempFile); Mapper Mapper = new Mapper(new MessagePackFactory()); Mapper.configure(JsonGenerator.Feature.AUTO_CLOSE_TARGET, false); Mapper.writeValue(out, 1); Mapper.writeValue(out, "two"); Mapper.writeValue(out, 3.14); out.close(); MessageUnpacker unpacker = MessagePack.newDefaultUnpacker(new FileInputStream(tempFile)); System.out.println(unpacker.unpackInt()); // => 1 System.out.println(unpacker.unpackString()); // => two System.out.println(unpacker.unpackFloat()); // => 3.14 tempFile.deleteOnExit(); } catch (IOException ex) { logger.error("Serialize Error", ex); }}https://www.cwiki.us/display/Serialization/MessagePack+Jackson+Dataformat
继续阅读与本文标签相同的文章
-
服务挂了,怎么自动恢复?
2026-05-21栏目: 教程
-
【从入门到放弃-Java】并发编程-JUC-LinkedBlockingQueue
2026-05-21栏目: 教程
-
明明打印到文件了,为啥tail -f看不到
2026-05-21栏目: 教程
-
3分钟了解“关联规则”推荐
2026-05-21栏目: 教程
-
1分钟了解比特币,PM都懂了
2026-05-21栏目: 教程
