Mentions légales du service

Skip to content
Snippets Groups Projects
Commit 347fa8ab authored by Guillaume Thomazon's avatar Guillaume Thomazon
Browse files

Display dicom file when user click on view inline

git-svn-id: https://scm.gforge.inria.fr/authscm/ycadoret/svn/gazelle/Maven/gazelle-proxy/trunk@35090 356b4b1a-1d2b-0410-8bf1-ffa24008f01e
parent 75869b64
No related branches found
No related tags found
No related merge requests found
package net.ihe.gazelle.proxy.gui;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintStream;
import java.net.URLEncoder;
import java.sql.Timestamp;
import java.util.ArrayList;
......@@ -33,9 +37,14 @@ import org.apache.commons.httpclient.methods.multipart.FilePart;
import org.apache.commons.httpclient.methods.multipart.MultipartRequestEntity;
import org.apache.commons.httpclient.methods.multipart.Part;
import org.apache.commons.httpclient.methods.multipart.PartSource;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringEscapeUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.dcm4che2.tool.dcm2txt.Dcm2Txt;
import org.jboss.resteasy.client.ClientRequest;
import org.jboss.resteasy.client.ClientResponse;
import org.jboss.seam.Component;
import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.In;
......@@ -45,9 +54,6 @@ import org.jboss.seam.faces.FacesMessages;
import org.jboss.seam.faces.Redirect;
import org.jboss.seam.international.StatusMessage;
import org.jboss.resteasy.client.ClientRequest;
import org.jboss.resteasy.client.ClientResponse;
@Name("messageBean")
@Scope(ScopeType.PAGE)
public class MessageBean {
......@@ -122,23 +128,55 @@ public class MessageBean {
}
}
public byte[] dicom2txt(InputStream messageStream) throws IOException {
byte[] fileByte = null;
Dcm2Txt d2t = new Dcm2Txt();
File f = File.createTempFile("tmp", "dcm");
fileByte = IOUtils.toByteArray(messageStream);
FileUtils.writeByteArrayToFile(f, fileByte);
PrintStream ops = System.out;
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
PrintStream nps = new PrintStream(outStream, true);
System.setOut(nps);
d2t.dump(f);
System.setOut(ops);
byte[] maChaine = outStream.toByteArray();
outStream.close();
f.delete();
return maChaine;
}
public void downloadFile(boolean inline) {
try {
HttpServletResponse response = (HttpServletResponse) extCtx.getResponse();
InputStream messageStream = message.getMessageReceivedStream();
ServletOutputStream servletOutputStream = response.getOutputStream();
response.setContentType("text/plain");
response.setContentLength(message.getMessageLength());
if (!inline) {
response.setHeader("Content-Disposition", "attachment;filename=\"" + message.getId() + "\"");
}
byte[] buf = new byte[8192];
while (true) {
int length = messageStream.read(buf);
if (length < 0)
break;
servletOutputStream.write(buf, 0, length);
if (message.getChannelType().getDiscriminator().equals("DicomMessage")) {
byte[] result = dicom2txt(messageStream);
response.setContentLength(result.length);
ByteArrayInputStream input = new ByteArrayInputStream(result);
IOUtils.copyLarge(input, servletOutputStream);
} else {
response.setContentLength(message.getMessageLength());
byte[] buf = new byte[8192];
while (true) {
int length = messageStream.read(buf);
if (length < 0)
break;
servletOutputStream.write(buf, 0, length);
}
}
try {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment