Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -330,8 +330,10 @@ public void close() throws IOException {
flush();
}
finally {
MessagePacker messagePacker = getMessagePacker();
messagePacker.close();
if (isEnabled(Feature.AUTO_CLOSE_TARGET)) {
MessagePacker messagePacker = getMessagePacker();
messagePacker.close();
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.*;
Expand Down Expand Up @@ -263,4 +264,24 @@ public void testBigDecimal() throws IOException {
}
}
}

@Test
public void testDisableFeatureAutoCloseTarget() throws IOException {
File tempFile = File.createTempFile("test", "msgpack");
tempFile.deleteOnExit();
FileOutputStream out = new FileOutputStream(tempFile);
MessagePackFactory messagePackFactory = new MessagePackFactory();
messagePackFactory.disable(JsonGenerator.Feature.AUTO_CLOSE_TARGET);
ObjectMapper objectMapper = new ObjectMapper(messagePackFactory);
List<Integer> integers = Arrays.asList(1);
objectMapper.writeValue(out, integers);
objectMapper.writeValue(out, integers);
out.close();

MessageUnpacker unpacker = MessagePack.newDefaultUnpacker(new FileInputStream(tempFile));
assertEquals(1, unpacker.unpackArrayHeader());
assertEquals(1, unpacker.unpackInt());
assertEquals(1, unpacker.unpackArrayHeader());
assertEquals(1, unpacker.unpackInt());
}
}