Skip to content

Commit 0af917a

Browse files
committed
Merge branch 'dev' into dev-flex
2 parents 38eb9f1 + 80c716e commit 0af917a

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

src/main/java/com/conveyal/datatools/manager/models/FeedSource.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636

3737
import java.io.File;
3838
import java.io.IOException;
39+
import java.io.InputStream;
3940
import java.net.HttpURLConnection;
4041
import java.net.MalformedURLException;
4142
import java.net.URL;
@@ -241,11 +242,12 @@ public FeedVersion fetch (MonitorableJob.Status status, String optionalUrlOverri
241242
conn.connect();
242243
return processFetchResponse(status, optionalUrlOverride, version, latest, new HttpURLConnectionResponse(conn));
243244
} catch (IOException e) {
244-
String message = String.format("Unable to connect to %s; not fetching %s feed", conn.getURL(), this.name); // url, this.name);
245-
LOG.error(message);
245+
String message = String.format("Unable to connect to %s; not fetching %s feed", conn.getURL(), this.name);
246+
LOG.error(message, e);
246247
status.fail(message);
247-
e.printStackTrace();
248248
return null;
249+
} finally {
250+
conn.disconnect();
249251
}
250252
}
251253

@@ -331,7 +333,9 @@ public FeedVersion processFetchResponse(
331333
status.update(message, 75.0);
332334
// Create new file from input stream (this also handles hashing the file and other version fields
333335
// calculated from the GTFS file.
334-
newGtfsFile = version.newGtfsFile(response.getInputStream());
336+
try (InputStream inputStream = response.getInputStream()) {
337+
newGtfsFile = version.newGtfsFile(inputStream);
338+
}
335339
break;
336340
case HttpURLConnection.HTTP_MOVED_TEMP:
337341
case HttpURLConnection.HTTP_MOVED_PERM:

src/main/java/com/conveyal/datatools/manager/persistence/FeedStore.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,9 @@ public File newFeed (String id, InputStream inputStream, FeedSource feedSource)
139139
// NOTE: depending on the feed store, there may not be a feedSource provided (e.g., gtfsplus)
140140
File file = new File(path, id);
141141
LOG.info("Writing file to {}", file.getAbsolutePath());
142-
ByteStreams.copy(inputStream, new FileOutputStream(file));
142+
try (InputStream stream = inputStream; FileOutputStream outputStream = new FileOutputStream(file)) {
143+
ByteStreams.copy(stream, outputStream);
144+
}
143145
if (feedSource != null && !DataManager.useS3) {
144146
// Store latest as feed-source-id.zip if feedSource provided and if not using s3
145147
copyVersionToLatest(file, feedSource);

0 commit comments

Comments
 (0)