Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

MessagePack Java Jackson without closing the input stream (input stream)

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/03 Report--

Com.fasterxml.jackson.databind.ObjectMapper will close the input stream by default when reading input stream variables.

If you do not want to close the input stream, you can set the JsonParser.Feature.AUTO_CLOSE_SOURCE parameter to false.

This test method can be found in https://github.com/cwiki-us-demo/serialize-deserialize-demo-java/blob/master/src/test/java/com/insight/demo/serialize/MessagePackSerializer.java.

/ * SerializationNotClose 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) ObjectMapper objectMapper = new ObjectMapper (new MessagePackFactory ()); objectMapper.configure (JsonParser.Feature.AUTO_CLOSE_SOURCE, false); System.out.println (objectMapper.readValue (in, Integer.class)); System.out.println (objectMapper.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

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report