1 package jalview.ws.rest.params;
3 import jalview.datamodel.AlignmentI;
4 import jalview.ws.rest.InputType;
5 import jalview.ws.rest.NoValidInputDataException;
6 import jalview.ws.rest.RestJob;
7 import jalview.ws.rest.InputType.molType;
9 import java.io.BufferedOutputStream;
10 import java.io.ByteArrayOutputStream;
12 import java.io.FileOutputStream;
13 import java.io.OutputStreamWriter;
14 import java.io.PrintWriter;
15 import java.io.StringWriter;
16 import java.io.UnsupportedEncodingException;
17 import java.net.URLEncoder;
18 import java.nio.charset.Charset;
20 import org.apache.http.entity.mime.content.ContentBody;
21 import org.apache.http.entity.mime.content.FileBody;
22 import org.apache.http.entity.mime.content.StringBody;
25 * format an alignment for input to rest service.
29 public class Alignment extends InputType {
32 super(new Class[] { AlignmentI.class} );
35 String format="FASTA";
37 boolean jvsuffix=false;
39 * input data as a file upload rather than inline content
41 public boolean writeAsFile;
43 public ContentBody formatForInput(RestJob rj) throws UnsupportedEncodingException, NoValidInputDataException
45 AlignmentI alignment = rj.getAlignmentForInput(token,type);
49 File fa = File.createTempFile("jvmime", ".fa");
50 PrintWriter pw = new PrintWriter(new OutputStreamWriter(new BufferedOutputStream(new FileOutputStream(fa)), "UTF-8"));
51 pw.append(new jalview.io.FormatAdapter().formatSequences(format, alignment, jvsuffix));
53 return new FileBody(fa, "text/plain");
54 } catch (Exception ex)
56 throw new NoValidInputDataException("Couldn't write out alignment to file.",ex);
59 jalview.io.FormatAdapter fa = new jalview.io.FormatAdapter();
60 fa.setNewlineString("\r\n");
61 return new StringBody((fa.formatSequences(format, alignment, jvsuffix)));
63 //"text/plain",Charset.forName("UTF-8"));
64 // , "text/plain", Charset.forName("UTF-8"));
65 // sb.getContentTypeParameters().put("filename", "alignment.fa");