您好,登錄后才能下訂單哦!
com.fasterxml.jackson.databind.ObjectMapper
?在讀取輸入流變量的時(shí)候默認(rèn)的將會(huì)關(guān)閉輸入流。
如果你不希望關(guān)閉輸入流,你可以設(shè)置?JsonParser.Feature.AUTO_CLOSE_SOURCE
?參數(shù)為 false。
本測(cè)試方法,可以在?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
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。