您好,登錄后才能下訂單哦!
com.fasterxml.jackson.databind.ObjectMapper
?在讀取輸入流變量的時候默認的將會關閉輸入流。
如果你不希望關閉輸入流,你可以設置?JsonParser.Feature.AUTO_CLOSE_SOURCE
?參數為 false。
本測試方法,可以在?https://github.com/cwiki-us-demo/serialize-deserialize-demo-java/blob/master/src/test/java/com/insight/demo/serialize/MessagePackSerializer.java?中找到。
?
/** ?*?Serialization?Not?Close?input?stream ?*/ @Test public?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
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。