Skip to content

Commit 46755a9

Browse files
committed
abort object stream
1 parent 082376e commit 46755a9

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

src/main/java/com/teragrep/pth_06/task/s3/EpochMigrationRowConverter.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
import com.amazonaws.AmazonServiceException;
4949
import com.amazonaws.services.s3.AmazonS3;
5050
import com.amazonaws.services.s3.model.S3Object;
51+
import com.amazonaws.services.s3.model.S3ObjectInputStream;
5152
import com.teragrep.rlo_06.ParseException;
5253
import com.teragrep.rlo_06.RFC5424Frame;
5354
import com.teragrep.rlo_06.RFC5424Timestamp;
@@ -78,6 +79,7 @@ public final class EpochMigrationRowConverter implements RowConverter {
7879
private final UnsafeRowWriter rowWriter;
7980
private final RFC5424Frame rfc5424Frame;
8081
private final AmazonS3 s3client;
82+
private S3ObjectInputStream objectStream = null;
8183
private InputStream inputStream = null;
8284
private boolean isSyslogFormat;
8385

@@ -138,8 +140,9 @@ public void open() throws IOException {
138140
s3object.getObjectMetadata().getContentLength()
139141
);
140142
}
141-
inputStream = new BufferedInputStream(s3object.getObjectContent(), 8 * 1024 * 1024);
142-
final GZIPInputStream gz = new GZIPInputStream(inputStream);
143+
objectStream = s3object.getObjectContent();
144+
inputStream = new BufferedInputStream(objectStream, 8 * 1024 * 1024);
145+
final GZIPInputStream gz = new GZIPInputStream(objectStream);
143146
rfc5424Frame.load(gz);
144147
LOGGER.trace("S3FileHandler.open() Initialized result set with element lists");
145148
LOGGER.info("S3FileHandler.open() Initialized parser for <[{}]>", logName);
@@ -235,6 +238,9 @@ public InternalRow get() {
235238
public void close() throws IOException {
236239
final String logName = bucket + "/" + path;
237240
LOGGER.info("S3FileHandler.close() on log <{}> read attempted <{}>", logName, readAttempted);
241+
if (objectStream != null) {
242+
objectStream.abort();
243+
}
238244
if (inputStream != null) {
239245
inputStream.close();
240246
}

0 commit comments

Comments
 (0)