Skip to content

Commit

Permalink
Merged in dev (pull request #10)
Browse files Browse the repository at this point in the history
Merge dev to master
  • Loading branch information
pradeeban committed Aug 17, 2017
2 parents 59bc248 + c8cdca4 commit 14f4899
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 32 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ This project depends on the below major projects.
* Apache Velocity
* Apache Log4j2
* Mashape Unirest
* SparkJava



Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package edu.emory.bmi.datarepl.ds_mgmt.tcia;


import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
Expand Down Expand Up @@ -293,6 +294,38 @@ public String getPatient(String collection, OutputFormat format)
}
}

/**
* Downloads the images in a given series
* @param seriesInstanceUID the inst
* @throws TCIAClientException
* @throws IOException
*/
public void downloadImagesOfSeries(String seriesInstanceUID) throws TCIAClientException, IOException {
ITCIAClient.ImageResult imageResult = getImage(seriesInstanceUID);
saveTo(imageResult.getRawData(), seriesInstanceUID + ".zip", ".");
}


private static void saveTo(InputStream in, String name, String directory) throws IOException {
FileOutputStream fos = new FileOutputStream(directory + "/" + name);
byte[] buffer = new byte[4096];
int read = -1;
int sum = 0;
while ((read = in.read(buffer)) > 0) {
fos.write(buffer, 0, read);
long mseconds = System.currentTimeMillis();
sum += read;

if (mseconds % 10 == 0) {
System.out.println(String.format("Bytes Written %s", sum));
}
}

fos.close();
in.close();
}


public ImageResult getImage(String seriesInstanceUID)
throws edu.emory.bmi.datarepl.ds_mgmt.tcia.TCIAClientException {
try {
Expand All @@ -310,8 +343,6 @@ public ImageResult getImage(String seriesInstanceUID)
// create a new HttpGet request
HttpGet request = new HttpGet(uri);

// add api_key to the header
request.setHeader(API_KEY_FIELD, apiKey);
long startTime = System.currentTimeMillis();
HttpResponse response = httpClient.execute(request);
long diff = System.currentTimeMillis() - startTime;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,24 +53,17 @@ public void testGetCollectionValues() {
* Method : GetImage
* Description : Returns images in a zip file
*/

@Test
public void testGetImage() {

// create TCIA Client by passing API-Key and baseUrl in the constructor
ITCIAClient client = TCIAClientImpl.getTCIAClientImpl();
TCIAClientImpl client = TCIAClientImpl.getTCIAClientImpl();
String seriesInstanceUID = "1.3.6.1.4.1.14519.5.2.1.7695.4001.306204232344341694648035234440";
try {
// Make the RESTfull call . Response comes back as InputStream.
ITCIAClient.ImageResult imageResult = client.getImage(seriesInstanceUID);
saveTo(imageResult.getRawData(), seriesInstanceUID + ".zip", ".");

client.downloadImagesOfSeries(seriesInstanceUID);
} catch (TCIAClientException e) {
fail(e.getMessage()); // request failed
} catch (Exception e) {
fail(e.getMessage()); // request failed
fail("TCIA Client Exception in downloading the images. " + e.getMessage());
} catch (IOException e) {
fail("IOException in downloading the images. " + e.getMessage());
}

}


Expand Down Expand Up @@ -238,24 +231,6 @@ public static void saveTo(InputStream in, String name, String directory, int est
in.close();
}

public static void saveTo(InputStream in, String name, String directory) throws IOException {
FileOutputStream fos = new FileOutputStream(directory + "/" + name);
byte[] buffer = new byte[4096];
int read = -1;
int sum = 0;
while ((read = in.read(buffer)) > 0) {
fos.write(buffer, 0, read);
long mseconds = System.currentTimeMillis();
sum += read;

if (mseconds % 10 == 0) {
System.out.println(String.format("Bytes Written %s", sum));
}
}

fos.close();
in.close();
}

public static String toString(InputStream in) throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
Expand Down

0 comments on commit 14f4899

Please sign in to comment.