File tree Expand file tree Collapse file tree 2 files changed +25
-2
lines changed
main/java/org/msgpack/jackson/dataformat
test/java/org/msgpack/jackson/dataformat Expand file tree Collapse file tree 2 files changed +25
-2
lines changed Original file line number Diff line number Diff line change @@ -330,8 +330,10 @@ public void close() throws IOException {
330330 flush ();
331331 }
332332 finally {
333- MessagePacker messagePacker = getMessagePacker ();
334- messagePacker .close ();
333+ if (isEnabled (Feature .AUTO_CLOSE_TARGET )) {
334+ MessagePacker messagePacker = getMessagePacker ();
335+ messagePacker .close ();
336+ }
335337 }
336338 }
337339
Original file line number Diff line number Diff line change 2525
2626import java .io .File ;
2727import java .io .FileInputStream ;
28+ import java .io .FileOutputStream ;
2829import java .io .IOException ;
2930import java .math .BigDecimal ;
3031import java .util .*;
@@ -263,4 +264,24 @@ public void testBigDecimal() throws IOException {
263264 }
264265 }
265266 }
267+
268+ @ Test
269+ public void testDisableFeatureAutoCloseTarget () throws IOException {
270+ File tempFile = File .createTempFile ("test" , "msgpack" );
271+ tempFile .deleteOnExit ();
272+ FileOutputStream out = new FileOutputStream (tempFile );
273+ MessagePackFactory messagePackFactory = new MessagePackFactory ();
274+ messagePackFactory .disable (JsonGenerator .Feature .AUTO_CLOSE_TARGET );
275+ ObjectMapper objectMapper = new ObjectMapper (messagePackFactory );
276+ List <Integer > integers = Arrays .asList (1 );
277+ objectMapper .writeValue (out , integers );
278+ objectMapper .writeValue (out , integers );
279+ out .close ();
280+
281+ MessageUnpacker unpacker = MessagePack .newDefaultUnpacker (new FileInputStream (tempFile ));
282+ assertEquals (1 , unpacker .unpackArrayHeader ());
283+ assertEquals (1 , unpacker .unpackInt ());
284+ assertEquals (1 , unpacker .unpackArrayHeader ());
285+ assertEquals (1 , unpacker .unpackInt ());
286+ }
266287}
You can’t perform that action at this time.
0 commit comments