Skip to content

Commit

Permalink
A few try/resources
Browse files Browse the repository at this point in the history
  • Loading branch information
rubendel committed Dec 6, 2019
1 parent 0437367 commit 30565df
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 21 deletions.
19 changes: 8 additions & 11 deletions BimServerClientLib/src/org/bimserver/client/BimServerClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -380,12 +380,9 @@ public void download(long roid, long serializerOid, OutputStream outputStream) t
if (progress != null && progress.getState() == SActionState.AS_ERROR) {
throw new BimServerClientException(Joiner.on(", ").join(progress.getErrors()));
} else {
InputStream inputStream = getDownloadData(topicId);
try {
try (InputStream inputStream = getDownloadData(topicId)) {
IOUtils.copy(inputStream, outputStream);
getServiceInterface().cleanupLongAction(topicId);
} finally {
inputStream.close();
}
}
} catch (ServerException e) {
Expand Down Expand Up @@ -419,13 +416,13 @@ public void download(long roid, Query query, long serializerOid, Path file) thro
@Override
public void download(long roid, String query, long serializerOid, Path file) throws ServerException, UserException, PublicInterfaceNotFoundException, IOException {
Long topicId = getServiceInterface().download(Collections.singleton(roid), query, serializerOid, false);
InputStream downloadData = getDownloadData(topicId);
FileOutputStream fos = new FileOutputStream(file.toFile());
try {
IOUtils.copy(downloadData, fos);
} finally {
downloadData.close();
fos.close();
try (InputStream downloadData = getDownloadData(topicId)) {
FileOutputStream fos = new FileOutputStream(file.toFile());
try {
IOUtils.copy(downloadData, fos);
} finally {
fos.close();
}
}
}

Expand Down
17 changes: 9 additions & 8 deletions BimServerClientLib/src/org/bimserver/client/ClientIfcModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -366,14 +366,15 @@ public void loadGeometry() throws QueryException, ServerException, UserException
long topicId = bimServerClient.query(query, roid, serializerOid);
// TODO use websocket notifications
bimServerClient.waitForDonePreparing(topicId);
InputStream inputStream = bimServerClient.getDownloadData(topicId);
clientDebugInfo.incrementGeometryGetDownloadData();
try {
processGeometryInputStream(inputStream);
} catch (Throwable e) {
e.printStackTrace();
} finally {
bimServerClient.getServiceInterface().cleanupLongAction(topicId);
try (InputStream inputStream = bimServerClient.getDownloadData(topicId)) {
clientDebugInfo.incrementGeometryGetDownloadData();
try {
processGeometryInputStream(inputStream);
} catch (Throwable e) {
e.printStackTrace();
} finally {
bimServerClient.getServiceInterface().cleanupLongAction(topicId);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,7 @@ private void fetch(long roid, Query query, long serializerOid) throws ServerExce
long topicId = bimServerClient.query(query, roid, serializerOid);
// TODO use websocket notifications
bimServerClient.waitForDonePreparing(topicId);
InputStream inputStream = bimServerClient.getDownloadData(topicId);
try {
try (InputStream inputStream = bimServerClient.getDownloadData(topicId)) {
load(inputStream);
} catch (Throwable e) {
e.printStackTrace();
Expand Down

0 comments on commit 30565df

Please sign in to comment.