Skip to content

Commit

Permalink
[DM-41951] BufferedOutputStreams for everything
Browse files Browse the repository at this point in the history
This mimics a change I'm working on in lsst-tap-service where we
stop using outputstream to try to avoid out of memory errors.
  • Loading branch information
cbanek committed Dec 5, 2023
1 parent 733299e commit dcf0f4b
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions tap/src/main/java/ca/nrc/cadc/sample/ResultStoreImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
import com.google.cloud.storage.StorageOptions;

import java.io.File;
import java.io.OutputStream;
import java.io.BufferedOutputStream;
import java.io.IOException;
import java.nio.channels.Channels;
import java.net.MalformedURLException;
Expand All @@ -100,7 +100,7 @@ public class ResultStoreImpl implements ResultStore {
public URL put(final ResultSet resultSet,
final TableWriter<ResultSet> resultSetTableWriter)
throws IOException {
OutputStream os = getOutputStream();
BufferedOutputStream os = getOutputStream();
resultSetTableWriter.write(resultSet, os);
os.close();
return getURL();
Expand All @@ -109,7 +109,7 @@ public URL put(final ResultSet resultSet,
@Override
public URL put(Throwable throwable, TableWriter tableWriter)
throws IOException {
OutputStream os = getOutputStream();
BufferedOutputStream os = getOutputStream();
tableWriter.write(throwable, os);
os.close();
return getURL();
Expand All @@ -119,7 +119,7 @@ public URL put(Throwable throwable, TableWriter tableWriter)
public URL put(final ResultSet resultSet,
final TableWriter<ResultSet> resultSetTableWriter,
final Integer integer) throws IOException {
OutputStream os = getOutputStream();
BufferedOutputStream os = getOutputStream();

if (integer == null) {
resultSetTableWriter.write(resultSet, os);
Expand All @@ -132,12 +132,15 @@ public URL put(final ResultSet resultSet,
return getURL();
}

private OutputStream getOutputStream() {
private BufferedOutputStream getOutputStream() {
Storage storage = StorageOptions.getDefaultInstance().getService();
BlobId blobId = BlobId.of(bucket, filename);
BlobInfo blobInfo = BlobInfo.newBuilder(blobId).setContentType("application/x-votable+xml").build();
Blob blob = storage.create(blobInfo);
return Channels.newOutputStream(blob.writer());
return new BufferedOutputStream(
Channels.newOutputStream(blob.writer()),
32768
);
}

private URL getURL() throws MalformedURLException {
Expand Down

0 comments on commit dcf0f4b

Please sign in to comment.