Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix resource leaks #119

Merged
merged 1 commit into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading