Skip to content

Commit

Permalink
Sync with GeneratorBase changes
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Sep 1, 2023
1 parent 7abf5b3 commit 887e18e
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 80 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -316,9 +316,8 @@ public final void flush() {
}

@Override
public void close()
protected void _closeInput() throws IOException
{
super.close();
if (isEnabled(StreamWriteFeature.AUTO_CLOSE_CONTENT)) {
AvroWriteContext ctxt;
while ((ctxt = _streamWriteContext) != null) {
Expand Down Expand Up @@ -348,19 +347,13 @@ public void close()
}
}
if (_output != null) {
try {
if (_ioContext.isResourceManaged() || isEnabled(StreamWriteFeature.AUTO_CLOSE_TARGET)) {
_output.close();
} else if (isEnabled(StreamWriteFeature.FLUSH_PASSED_TO_STREAM)) {
// If we can't close it, we should at least flush
_output.flush();
}
} catch (IOException e) {
throw _wrapIOFailure(e);
if (_ioContext.isResourceManaged() || isEnabled(StreamWriteFeature.AUTO_CLOSE_TARGET)) {
_output.close();
} else if (isEnabled(StreamWriteFeature.FLUSH_PASSED_TO_STREAM)) {
// If we can't close it, we should at least flush
_output.flush();
}
}
// Internal buffer(s) generator has can now be released as well
_releaseBuffers();
}

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1277,7 +1277,8 @@ public final void flush() throws JacksonException {
}

@Override
public void close() throws JacksonException {
protected void _closeInput() throws IOException
{
// First: let's see that we still have buffers...
if ((_outputBuffer != null)
&& isEnabled(StreamWriteFeature.AUTO_CLOSE_CONTENT)) {
Expand All @@ -1292,24 +1293,16 @@ && isEnabled(StreamWriteFeature.AUTO_CLOSE_CONTENT)) {
}
}
}
// boolean wasClosed = _closed;
super.close();
_flushBuffer();

try {
if (_ioContext.isResourceManaged()
|| isEnabled(StreamWriteFeature.AUTO_CLOSE_TARGET)) {
_out.close();
} else if (isEnabled(StreamWriteFeature.FLUSH_PASSED_TO_STREAM)) {
// 14-Jan-2019, tatu: [dataformats-binary#155]: unless prevented via feature
// If we can't close it, we should at least flush
_out.flush();
}
} catch (IOException e) {
throw _wrapIOFailure(e);
if (_ioContext.isResourceManaged()
|| isEnabled(StreamWriteFeature.AUTO_CLOSE_TARGET)) {
_out.close();
} else if (isEnabled(StreamWriteFeature.FLUSH_PASSED_TO_STREAM)) {
// 14-Jan-2019, tatu: [dataformats-binary#155]: unless prevented via feature
// If we can't close it, we should at least flush
_out.flush();
}
// Internal buffer(s) generator has can now be released as well
_releaseBuffers();
}

/*
Expand Down
32 changes: 10 additions & 22 deletions ion/src/main/java/tools/jackson/dataformat/ion/IonGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -198,25 +198,18 @@ public Object streamWriteOutputTarget() {
}

@Override
public void close()
protected void _closeInput() throws IOException
{
if (!_closed) {
_closed = true;
try {
if (_ionWriterIsManaged) {
_writer.close();
}
if (_ioContext.isResourceManaged()) {
_destination.close();
} else {
if (isEnabled(StreamWriteFeature.FLUSH_PASSED_TO_STREAM)) {
if (_destination instanceof Flushable) {
((Flushable) _destination).flush();
}
}
if (_ionWriterIsManaged) {
_writer.close();
}
if (_ioContext.isResourceManaged()) {
_destination.close();
} else {
if (isEnabled(StreamWriteFeature.FLUSH_PASSED_TO_STREAM)) {
if (_destination instanceof Flushable) {
((Flushable) _destination).flush();
}
} catch (IOException e) {
throw _wrapIOFailure(e);
}
}
}
Expand All @@ -236,11 +229,6 @@ public void flush()
}
}

@Override
public boolean isClosed() {
return _closed;
}

/*
/**********************************************************************
/* Capability introspection
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,9 +312,8 @@ public final void flush() throws JacksonException
}

@Override
public void close() throws JacksonException
protected void _closeInput() throws IOException
{
super.close();
if (isEnabled(StreamWriteFeature.AUTO_CLOSE_CONTENT)) {
ProtobufWriteContext ctxt;
while ((ctxt = _streamWriteContext) != null) {
Expand All @@ -332,20 +331,14 @@ public void close() throws JacksonException
_complete();
}
if (_output != null) {
try {
if (_ioContext.isResourceManaged() || isEnabled(StreamWriteFeature.AUTO_CLOSE_TARGET)) {
_output.close();
} else if (isEnabled(StreamWriteFeature.FLUSH_PASSED_TO_STREAM)) {
// 14-Jan-2019, tatu: [dataformats-binary#155]: unless prevented via feature
// If we can't close it, we should at least flush
_output.flush();
}
} catch (IOException e) {
throw _wrapIOFailure(e);
if (_ioContext.isResourceManaged() || isEnabled(StreamWriteFeature.AUTO_CLOSE_TARGET)) {
_output.close();
} else if (isEnabled(StreamWriteFeature.FLUSH_PASSED_TO_STREAM)) {
// 14-Jan-2019, tatu: [dataformats-binary#155]: unless prevented via feature
// If we can't close it, we should at least flush
_output.flush();
}
}
// Internal buffer(s) generator has can now be released as well
_releaseBuffers();
}

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1867,7 +1867,7 @@ public final void flush() throws JacksonException
}

@Override
public void close() throws JacksonException
protected void _closeInput() throws IOException
{
// First: let's see that we still have buffers...
if (_outputBuffer != null
Expand All @@ -1884,26 +1884,18 @@ && isEnabled(StreamWriteFeature.AUTO_CLOSE_CONTENT)) {
}
}
boolean wasClosed = _closed;
super.close();

if (!wasClosed && isEnabled(Feature.WRITE_END_MARKER)) {
_writeByte(BYTE_MARKER_END_OF_CONTENT);
}
_flushBuffer();

try {
if (_ioContext.isResourceManaged() || isEnabled(StreamWriteFeature.AUTO_CLOSE_TARGET)) {
_out.close();
} else if (isEnabled(StreamWriteFeature.FLUSH_PASSED_TO_STREAM)) {
// If we can't close it, we should at least flush
// 14-Jan-2019, tatu: [dataformats-binary#155]: unless prevented via feature
_out.flush();
}
} catch (IOException e) {
throw _wrapIOFailure(e);
if (_ioContext.isResourceManaged() || isEnabled(StreamWriteFeature.AUTO_CLOSE_TARGET)) {
_out.close();
} else if (isEnabled(StreamWriteFeature.FLUSH_PASSED_TO_STREAM)) {
// If we can't close it, we should at least flush
// 14-Jan-2019, tatu: [dataformats-binary#155]: unless prevented via feature
_out.flush();
}
// Internal buffer(s) generator has can now be released as well
_releaseBuffers();
}

/*
Expand Down

0 comments on commit 887e18e

Please sign in to comment.