formatting
[jalview.git] / src / jalview / ws / jws1 / Annotate3D.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8)
3  * Copyright (C) 2012 J Procter, AM Waterhouse, LM Lui, J Engelhardt, G Barton, M Clamp, S Searle
4  * 
5  * This file is part of Jalview.
6  * 
7  * Jalview is free software: you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License 
9  * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
10  *  
11  * Jalview is distributed in the hope that it will be useful, but 
12  * WITHOUT ANY WARRANTY; without even the implied warranty 
13  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
14  * PURPOSE.  See the GNU General Public License for more details.
15  * 
16  * You should have received a copy of the GNU General Public License along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
17  */
18 package jalview.ws.jws1;
19
20 import jalview.datamodel.Alignment;
21 import jalview.datamodel.AlignmentI;
22 import jalview.io.FileParse;
23 import jalview.io.FormatAdapter;
24 import jalview.io.InputStreamParser;
25
26 import java.io.BufferedReader;
27 import java.io.FileReader;
28 import java.io.IOException;
29 import java.io.InputStreamReader;
30 import java.io.Reader;
31 import java.net.MalformedURLException;
32 import java.net.URL;
33 import java.net.URLEncoder;
34
35 public class Annotate3D
36 {
37   // protected BufferedReader in;
38   // protected BufferedWriter out;
39
40   public Annotate3D()
41   {
42     System.out.println("Annotate3D");
43     // try {
44     // Create a URL for the desired page
45     // String id = "1HR2";
46     // URL url = new
47     // URL("http://paradise-ibmc.u-strasbg.fr/webservices/annotate3d?pdbid="+id);
48     // in = new BufferedReader(new InputStreamReader(url.openStream()));
49     // String str;
50     // OutputStream out1 = null;
51     // out = new BufferedWriter(new OutputStreamWriter(out1, "temp.rnaml"));
52     // while ((str = in.readLine()) != null) {
53     // System.out.println(str);
54     // out.write(str);
55     // }
56     // in.close();
57     // out.close();
58     // } catch (MalformedURLException e) {
59     // } catch (IOException e) {
60     // }
61   }
62   public Annotate3D(String path) throws InterruptedException
63   {
64     System.out.println("Annotate3D");
65     try
66     {
67       // //URL url = new
68       // URL("http://paradise-ibmc.u-strasbg.fr/webservices/annotate3d?data="+inFile);
69       // System.out.println("Step1");
70       // FileReader r = new FileReader(inFile);
71       // BufferedReader in = new BufferedReader(r);
72       // StringBuffer content = new StringBuffer();
73       // System.out.println("Step2");
74       // while(in.readLine()!=null){
75       // content.append(in.readLine());
76       // //System.out.println("Step3"+in.readLine());
77       // }
78       //
79       // String data = URLEncoder.encode("data", "UTF-8") + "=" +
80       // URLEncoder.encode(content.toString(), "UTF-8");
81       // for (int i=0;i<data.length();i++)
82       // {
83       // System.out.print(data.charAt(i));
84       // }
85
86       // String data = "width=50&height=100";
87
88       // // Send the request
89       // FileReader r = new FileReader(path);
90       // BufferedReader in = new BufferedReader(r);
91       // StringBuffer content = new StringBuffer();
92       // System.out.println("Step1");
93       // while(in.readLine()!=null){
94       // content.append(in.readLine());
95       //
96       // }
97       // System.out.println("Step2");
98       // String data = URLEncoder.encode("data", "UTF-8") + "=" +
99       // URLEncoder.encode(content.toString(), "UTF-8");
100       // System.out.println("Step2");
101       // URL url = new
102       // URL("http://paradise-ibmc.u-strasbg.fr/webservices/annotate3d?data="+data);
103       // DataInputStream is = new DataInputStream(url.openStream());
104       // String str;
105       // while ((str = is.readLine()) != null) {
106       // System.out.println(str);
107       // //out.write(str);
108       // }
109       FileReader r = new FileReader(path);
110       BufferedReader in = new BufferedReader(r);
111       String content = "";
112       String str;
113
114       while ((str = in.readLine()) != null)
115       {
116         // System.out.println(str);
117
118         content = content + str;
119       }
120       System.out.println("pdbfile=" + content.toString());
121       System.out.println("capacité=" + content.length());
122       String paramfile = URLEncoder.encode(content.toString(), "UTF-8");
123       System.out.println("param=" + paramfile);
124       URL url = new URL(
125               "http://paradise-ibmc.u-strasbg.fr/webservices/annotate3d?data="
126                       + content);
127       BufferedReader is = new BufferedReader(new InputStreamReader(
128               url.openStream()));
129       String str4;
130       while ((str4 = is.readLine()) != null)
131       {
132         System.out.println(str4);
133         // out.write(str);
134       }
135       in.close();
136       is.close();
137
138       // HttpURLConnection connection = (HttpURLConnection)url.openConnection();
139       // connection.setRequestMethod("POST" );
140       // connection.setRequestProperty("data", path );
141       // //connection.setRequestProperty("nomDuChamp2", "valeurDuChamp2" );
142       // BufferedReader input = new BufferedReader(new
143       // InputStreamReader(connection.getInputStream()));
144       // //DataInputStream input = new
145       // DataInputStream(connection.getInputStream());
146       // String c;
147       // while((c=input.readLine())!=null){
148       // System.out.print(c);
149       // }
150       // input.close();
151       // BufferedReader in1 = new BufferedReader(is);
152
153       // OutputStream out1 = null;
154       // System.out.println("Step3");
155       // BufferedWriter out = new BufferedWriter(new OutputStreamWriter(out1,
156       // "temp.rnaml"));
157       //
158       // in.close();
159       // out.close();
160
161       // return;
162
163       // System.out.println(data.length());
164       // System.out.println("step2");
165       // URL url = new
166       // URL("http://paradise-ibmc.u-strasbg.fr/webservices/annotate3d?data="+data);
167       // System.out.println("step3");
168       // URLConnection conn = url.openConnection();
169       // conn.setDoOutput(true);
170       // OutputStreamWriter writer = new
171       // OutputStreamWriter(conn.getOutputStream());
172
173       // write parameters
174       // writer.write(data);
175       // writer.flush();
176
177       // Get the response
178       // StringBuffer answer = new StringBuffer();
179       // //BufferedReader reader = new BufferedReader(new
180       // InputStreamReader(conn.getInputStream()));
181       // //String line;
182       // while ((line = reader.readLine()) != null) {
183       // answer.append(line);
184       // System.out.println(line);
185       // }
186       // writer.close();
187       // reader.close();
188
189       // Output the response
190
191     } catch (MalformedURLException ex)
192     {
193       ex.printStackTrace();
194     } catch (IOException ex)
195     {
196       ex.printStackTrace();
197     }
198   }
199
200   // in = new BufferedReader(new InputStreamReader(url.openStream()));
201
202   // String str;
203
204   // out = new FileOutputStream("temp.rnaml");
205   // out = new BufferedWriter(new FileWriter("temp.rnaml"));
206
207   // while ((str = in.readLine()) != null) {
208   // System.out.println(str);
209   // out.write(str);
210   // System.out.println(str);
211   // in.close();
212
213   // out.close();
214   // } catch (MalformedURLException e) {
215   // } catch (IOException e) {
216   // }
217   //
218   // }
219
220   // public BufferedWriter getReader()
221   // {
222   // System.out.println("The buffer");
223
224   // return out;
225
226   // }
227
228 }