[
https://issues.apache.org/jira/browse/THRIFT-3392?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14962371#comment-14962371
]
ASF GitHub Bot commented on THRIFT-3392:
----------------------------------------
GitHub user bluezio opened a pull request:
https://github.com/apache/thrift/pull/655
[THRIFT-3392] Java TZlibTransport: ensure inflater/deflater are closed upon
close()
More information available on the JIRA issue:
https://issues.apache.org/jira/browse/THRIFT-3392
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/bluezio/thrift THRIFT-3392
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/thrift/pull/655.patch
To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:
This closes #655
----
commit e413701b53a4aa0069b5e5d873847c147308581e
Author: Antonio García-Domínguez <[email protected]>
Date: 2015-10-18T13:16:02Z
[THRIFT-3392] Java TZlibTransport: ensure inflater/deflater are closed upon
close()
----
> Java TZlibTransport does not close its wrapper streams upon close()
> -------------------------------------------------------------------
>
> Key: THRIFT-3392
> URL: https://issues.apache.org/jira/browse/THRIFT-3392
> Project: Thrift
> Issue Type: Bug
> Components: Java - Library
> Affects Versions: 0.9.3
> Reporter: Antonio García
>
> While setting up a short demo project using the new Java TZlibTransport in
> 0.9.3, I wrote code like this:
> try (TProtocol proto = new TJSONProtocol(new TZlibTransport(...))) {
> Blog blog = new Blog();
> // set up fields in blog
> proto.write(blog);
> }
> However, when I went to look at the file, I found it mostly empty (with only
> the header bytes). I had a look at the TZlibTransport code, which seems to be
> a subclass of TIOStreamTransport that wraps its underlying transport using
> Java inflater/deflater streams:
> public TZlibTransport(TTransport transport, int compressionLevel) {
> transport_ = transport;
> inputStream_ = new InflaterInputStream(new
> TTransportInputStream(transport_), new Inflater());
> outputStream_ = new DeflaterOutputStream(new
> TTransportOutputStream(transport_), new Deflater(compressionLevel, false),
> true);
> }
> However, on its close method it only closes the transport and not the
> underlying streams, forcing users to flush the transport before closing if
> they really want to write everything:
> public void close() {
> if (transport_.isOpen()) {
> transport_.close();
> }
> I think it would be better if we simply relied on the close() method of the
> TIOStreamTransport, which closes the input and output streams if they have
> been created. Additionally, it would be better to create the input stream on
> the first read and the output stream on the first write: otherwise, we will
> get an error during closing if we're only reading (as TIOStreamTransport will
> still try to close the output side, resulting in writes from the deflater).
> I have a first version of a fix for these issues: I'll turn it into a pull
> request on Github.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)