|
48 | 48 | import com.amazonaws.AmazonServiceException; |
49 | 49 | import com.amazonaws.services.s3.AmazonS3; |
50 | 50 | import com.amazonaws.services.s3.model.S3Object; |
| 51 | +import com.amazonaws.services.s3.model.S3ObjectInputStream; |
51 | 52 | import com.teragrep.rlo_06.ParseException; |
52 | 53 | import com.teragrep.rlo_06.RFC5424Frame; |
53 | 54 | import com.teragrep.rlo_06.RFC5424Timestamp; |
@@ -78,6 +79,7 @@ public final class EpochMigrationRowConverter implements RowConverter { |
78 | 79 | private final UnsafeRowWriter rowWriter; |
79 | 80 | private final RFC5424Frame rfc5424Frame; |
80 | 81 | private final AmazonS3 s3client; |
| 82 | + private S3ObjectInputStream objectStream = null; |
81 | 83 | private InputStream inputStream = null; |
82 | 84 | private boolean isSyslogFormat; |
83 | 85 |
|
@@ -138,8 +140,9 @@ public void open() throws IOException { |
138 | 140 | s3object.getObjectMetadata().getContentLength() |
139 | 141 | ); |
140 | 142 | } |
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); |
143 | 146 | rfc5424Frame.load(gz); |
144 | 147 | LOGGER.trace("S3FileHandler.open() Initialized result set with element lists"); |
145 | 148 | LOGGER.info("S3FileHandler.open() Initialized parser for <[{}]>", logName); |
@@ -235,6 +238,9 @@ public InternalRow get() { |
235 | 238 | public void close() throws IOException { |
236 | 239 | final String logName = bucket + "/" + path; |
237 | 240 | LOGGER.info("S3FileHandler.close() on log <{}> read attempted <{}>", logName, readAttempted); |
| 241 | + if (objectStream != null) { |
| 242 | + objectStream.abort(); |
| 243 | + } |
238 | 244 | if (inputStream != null) { |
239 | 245 | inputStream.close(); |
240 | 246 | } |
|
0 commit comments