com.faster .jackson.databind. Mapper 在读取输入流变量的时候默认的将会关闭输入流。
如果你不希望关闭输入流,你可以设置 JsonParser.Feature.AUTO_CLOSE_SOURCE 参数为 false。
/** * Serialization Not Close input stream */@Testpublic void testMessagePackSerializationNotCloseInputStream() { logger.debug("testMessagePackSerializationNotCloseInputStream"); try { File tempFile = File.createTempFile("messagepack-", "-cwiki.us"); MessagePacker packer = MessagePack.newDefaultPacker(new FileOutputStream(tempFile)); packer.packInt(42); packer.packString("Hello"); packer.close(); FileInputStream in = new FileInputStream(tempFile); Mapper Mapper = new Mapper(new MessagePackFactory()); Mapper.configure(JsonParser.Feature.AUTO_CLOSE_SOURCE, false); System.out.println( Mapper.readValue(in, Integer.class)); System.out.println( Mapper.readValue(in, String.class)); in.close(); tempFile.deleteOnExit(); } catch (IOException ex) { logger.error("Serialize Error", ex); }}https://www.cwiki.us/display/Serialization/MessagePack+Jackson+Dataformat
继续阅读与本文标签相同的文章
-
1分钟了解比特币,PM都懂了
2026-05-21栏目: 教程
-
MessagePack Java Jackson Dataformat - Map 的序列化和反序列化
2026-05-21栏目: 教程
-
MessagePack Java Jackson 序列化和反序列化 POJO 为 MessagePack 的数组类型用来与 msgpack-java:0.6 保持兼容性
2026-05-21栏目: 教程
-
MessagePack Java Jackson 在不关闭输出流(output stream)的情况下序列化多变量
2026-05-21栏目: 教程
-
MessagePack Java Jackson 在不关闭输入流(input stream)的情况下反序列化多变量
2026-05-21栏目: 教程
