Skip to content

Commit

Permalink
Merge pull request #119 from NASA-PDS/issue_118
Browse files Browse the repository at this point in the history
Fix resource leaks
  • Loading branch information
jordanpadams authored Jan 6, 2025
2 parents b5550b0 + f26c07b commit bedc001
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package gov.nasa.pds.registry.common.connection.es;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -96,8 +95,7 @@ public long took() {
@Override
public void logErrors() {
BulkResponseParser parser = new BulkResponseParser();
try (InputStream is = this.response.getEntity().getContent()) {
InputStreamReader reader = new InputStreamReader(is);
try (InputStreamReader reader = new InputStreamReader(this.response.getEntity().getContent())) {
parser.parse(reader);
} catch (UnsupportedOperationException | IOException e) {
throw new RuntimeException("Some weird JSON parsing exception and should never get here.");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package gov.nasa.pds.registry.common.connection.es;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -68,8 +67,7 @@ private List<String> parseRefs(JsonReader rd) throws IOException {
}
@Override
public String productClass() {
try (InputStream is = this.response.getEntity().getContent()) {
JsonReader rd = new JsonReader(new InputStreamReader(is));
try (JsonReader rd = new JsonReader(new InputStreamReader(this.response.getEntity().getContent()))) {
rd.beginObject();
while(rd.hasNext() && rd.peek() != JsonToken.END_OBJECT) {
String name = rd.nextName();
Expand All @@ -87,8 +85,7 @@ public String productClass() {
}
@Override
public List<String> refs() {
try (InputStream is = this.response.getEntity().getContent()) {
JsonReader rd = new JsonReader(new InputStreamReader(is));
try (JsonReader rd = new JsonReader(new InputStreamReader(this.response.getEntity().getContent()))) {
rd.beginObject();
while(rd.hasNext() && rd.peek() != JsonToken.END_OBJECT) {
String name = rd.nextName();
Expand All @@ -107,8 +104,7 @@ public List<String> refs() {
@Override
public IdSets ids() {
LidvidSet collectionIds = null;
try (InputStream is = this.response.getEntity().getContent()) {
JsonReader rd = new JsonReader(new InputStreamReader(is));
try (JsonReader rd = new JsonReader(new InputStreamReader(this.response.getEntity().getContent()))) {
rd.beginObject();
while (rd.hasNext() && rd.peek() != JsonToken.END_OBJECT) {
String name = rd.nextName();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package gov.nasa.pds.registry.common.connection.es;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.StringWriter;
import java.util.Collection;
Expand Down Expand Up @@ -367,8 +366,7 @@ static String buildUpdateSchemaRequest(Collection<Tuple> fields) {

static long findCount (HttpEntity entity) {
long count = 0;
try (InputStream is = entity.getContent()) {
JsonReader rd = new JsonReader(new InputStreamReader(is));
try (JsonReader rd = new JsonReader(new InputStreamReader (entity.getContent()))) {
rd.beginObject();
while(rd.hasNext() && rd.peek() != JsonToken.END_OBJECT) {
String name = rd.nextName();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package gov.nasa.pds.registry.common.connection.es;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.time.Instant;
import java.util.ArrayList;
Expand Down Expand Up @@ -122,9 +121,9 @@ public void onRecord(String id, Object rec) {
}
@Override
public List<String> latestLidvids() {
try (InputStream is = this.response.getEntity().getContent()) {
try (InputStreamReader isr = new InputStreamReader (this.response.getEntity().getContent())) {
LatestLidsResponseParser parser = new LatestLidsResponseParser();
parser.parse(new InputStreamReader(is));
parser.parse(isr);
return parser.getLidvids();
} catch (UnsupportedOperationException | IOException e) {
throw new RuntimeException("Weird JSON parsing error and should never get here");
Expand Down

0 comments on commit bedc001

Please sign in to comment.