Skip to content

Commit 97e0bce

Browse files
committed
Merge pull request msgpack#239 from msgpack/issue_233
Issue 233
2 parents 13e79ed + a785c91 commit 97e0bce

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

msgpack-jackson/src/main/java/org/msgpack/jackson/dataformat/MessagePackGenerator.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff 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

msgpack-jackson/src/test/java/org/msgpack/jackson/dataformat/MessagePackGeneratorTest.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
import java.io.File;
2727
import java.io.FileInputStream;
28+
import java.io.FileOutputStream;
2829
import java.io.IOException;
2930
import java.math.BigDecimal;
3031
import 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
}

0 commit comments

Comments
 (0)