Skip to content

Commit 05374bb

Browse files
committed
fix FasterXML#155: Only flush outputs when FLUSH_PASSED_TO_STREAM is allowed
Previously most serializers would attempt a flush when AUTO_CLOSE_TARGET was disabled, which is not expected if FLUSH_PASSED_TO_STREAM is also disabled. This change results in binary serializers behaving the same as the json serializer.
1 parent 42acbcd commit 05374bb

File tree

4 files changed

+8
-4
lines changed

4 files changed

+8
-4
lines changed

avro/src/main/java/com/fasterxml/jackson/dataformat/avro/AvroGenerator.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,9 @@ public final void writeStringField(String fieldName, String value)
292292

293293
@Override
294294
public final void flush() throws IOException {
295-
_output.flush();
295+
if (isEnabled(StreamWriteFeature.FLUSH_PASSED_TO_STREAM)) {
296+
_output.flush();
297+
}
296298
}
297299

298300
@Override

cbor/src/main/java/com/fasterxml/jackson/dataformat/cbor/CBORGenerator.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1128,7 +1128,7 @@ && isEnabled(StreamWriteFeature.AUTO_CLOSE_CONTENT)) {
11281128
if (_ioContext.isResourceManaged()
11291129
|| isEnabled(StreamWriteFeature.AUTO_CLOSE_TARGET)) {
11301130
_out.close();
1131-
} else {
1131+
} else if (isEnabled(StreamWriteFeature.FLUSH_PASSED_TO_STREAM)) {
11321132
// If we can't close it, we should at least flush
11331133
_out.flush();
11341134
}

protobuf/src/main/java/com/fasterxml/jackson/dataformat/protobuf/ProtobufGenerator.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,9 @@ public final void flush() throws IOException
326326
_output.write(_currBuffer, start, len);
327327
}
328328
}
329-
_output.flush();
329+
if (isEnabled(StreamWriteFeature.FLUSH_PASSED_TO_STREAM)) {
330+
_output.flush();
331+
}
330332
}
331333

332334
@Override

smile/src/main/java/com/fasterxml/jackson/dataformat/smile/SmileGenerator.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1807,7 +1807,7 @@ && isEnabled(StreamWriteFeature.AUTO_CLOSE_CONTENT)) {
18071807

18081808
if (_ioContext.isResourceManaged() || isEnabled(StreamWriteFeature.AUTO_CLOSE_TARGET)) {
18091809
_out.close();
1810-
} else {
1810+
} else if (isEnabled(StreamWriteFeature.FLUSH_PASSED_TO_STREAM)) {
18111811
// If we can't close it, we should at least flush
18121812
_out.flush();
18131813
}

0 commit comments

Comments
 (0)