source 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 java.io.BufferedInputStream;
21 import java.io.BufferedReader;
22 import java.io.BufferedWriter;
23 import java.io.DataInputStream;
24 import java.io.File;
25 import java.io.FileOutputStream;
26 import java.io.FileReader;
27 import java.io.FileWriter;
28 import java.io.IOException;
29 import java.io.InputStream;
30 import java.io.InputStreamReader;
31 import java.io.OutputStream;
32 import java.io.OutputStreamWriter;
33 import java.io.Reader;
34 import java.io.StringWriter;
35 import java.net.HttpURLConnection;
36 import java.net.MalformedURLException;
37 import java.net.URL;
38 import java.net.URLConnection;
39
40 import java.net.URLEncoder;
41
42
43
44 public class Annotate3D {
45         //protected BufferedReader in;
46         //protected BufferedWriter out;
47         
48         public Annotate3D()
49         {
50                 System.out.println("Annotate3D");
51                 //try {
52                      // Create a URL for the desired page
53                      //String id = "1HR2";
54                      //URL url = new URL("http://paradise-ibmc.u-strasbg.fr/webservices/annotate3d?pdbid="+id);
55                      //in = new BufferedReader(new InputStreamReader(url.openStream()));
56                      //String str;
57                      //OutputStream out1 = null;
58                      //out = new BufferedWriter(new OutputStreamWriter(out1, "temp.rnaml"));
59                      //while ((str = in.readLine()) != null) {
60                      //System.out.println(str);
61                      //out.write(str);
62                      //}
63                      //in.close();
64                      //out.close();
65                      //} catch (MalformedURLException e) {
66                      //} catch (IOException e) {
67                      //}
68         }
69         
70         public Annotate3D(String path) throws InterruptedException{
71                 System.out.println("Annotate3D");
72                 try {
73 //                  //URL url = new URL("http://paradise-ibmc.u-strasbg.fr/webservices/annotate3d?data="+inFile);
74 //                      System.out.println("Step1");
75 //                  FileReader r = new FileReader(inFile);
76 //                  BufferedReader in = new BufferedReader(r);
77 //                  StringBuffer content = new StringBuffer();
78 //                  System.out.println("Step2");
79 //                      while(in.readLine()!=null){
80 //                              content.append(in.readLine());
81 //                              //System.out.println("Step3"+in.readLine());
82 //                      }
83 //                      
84 //                      String data = URLEncoder.encode("data", "UTF-8") + "=" + URLEncoder.encode(content.toString(), "UTF-8");
85 //                      for (int i=0;i<data.length();i++)
86 //                      {
87 //                              System.out.print(data.charAt(i));
88 //                      }
89                         
90                         //String data = "width=50&height=100";
91                
92                     
93 //                  // Send the request
94 //                              FileReader r = new FileReader(path);
95 //                              BufferedReader in = new BufferedReader(r);
96 //                              StringBuffer content = new StringBuffer();
97 //                              System.out.println("Step1");
98 //                              while(in.readLine()!=null){
99 //                                      content.append(in.readLine());
100 //                                      
101 //                              }
102 //                              System.out.println("Step2");
103 //                              String data = URLEncoder.encode("data", "UTF-8") + "=" + URLEncoder.encode(content.toString(), "UTF-8");
104 //                              System.out.println("Step2");
105 //                              URL url = new URL("http://paradise-ibmc.u-strasbg.fr/webservices/annotate3d?data="+data);
106 //                              DataInputStream is = new DataInputStream(url.openStream());
107 //                              String str;
108 //                              while ((str = is.readLine()) != null) {
109 //                                   System.out.println(str);
110 //                                   //out.write(str);
111 //                                   }
112                         FileReader r = new FileReader(path);
113                         BufferedReader in = new BufferedReader(r);
114                         String content ="";
115                         String str;
116                         
117                         while((str=in.readLine())!=null){
118                                 //System.out.println(str);
119                                 
120                                 content=content+str;
121                         }
122                         System.out.println("pdbfile="+content.toString());
123                         System.out.println("capacité="+content.length());
124                         String paramfile = URLEncoder.encode(content.toString(), "UTF-8");
125                         System.out.println("param="+paramfile);
126                             URL url = new URL("http://paradise-ibmc.u-strasbg.fr/webservices/annotate3d?data="+content);
127                             BufferedReader is = new BufferedReader(new InputStreamReader(url.openStream()));
128                                 String str4;
129                                 while ((str4 = is.readLine()) != null) {
130                                      System.out.println(str4);
131                                      //out.write(str);
132                                      }
133                             in.close();
134                             is.close();
135                             
136 //                          HttpURLConnection connection = (HttpURLConnection)url.openConnection();
137 //                          connection.setRequestMethod("POST" );
138 //                          connection.setRequestProperty("data", path );
139 //                          //connection.setRequestProperty("nomDuChamp2", "valeurDuChamp2" );
140 //                          BufferedReader input = new BufferedReader(new InputStreamReader(connection.getInputStream()));
141 //                          //DataInputStream input = new DataInputStream(connection.getInputStream());
142 //                          String c;
143 //                          while((c=input.readLine())!=null){
144 //                           System.out.print(c);
145 //                          }
146 //                          input.close();
147                                 //BufferedReader in1 = new BufferedReader(is);
148                                 
149 //                           OutputStream out1 = null;
150 //                           System.out.println("Step3");
151 //                           BufferedWriter out = new BufferedWriter(new OutputStreamWriter(out1, "temp.rnaml"));
152 //                           
153 //                           in.close();
154 //                           out.close();
155                                 
156                                 
157                                 //return;
158                                 
159                                 //System.out.println(data.length());
160                                 //System.out.println("step2");
161                     //URL url = new URL("http://paradise-ibmc.u-strasbg.fr/webservices/annotate3d?data="+data);
162                     //System.out.println("step3");
163                     //URLConnection conn = url.openConnection();
164                     //conn.setDoOutput(true);
165                     //OutputStreamWriter writer = new OutputStreamWriter(conn.getOutputStream());
166                     
167                     //write parameters
168                     //writer.write(data);
169                    // writer.flush();
170                     
171                     // Get the response
172 //                  StringBuffer answer = new StringBuffer();
173 //                  //BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
174 //                  //String line;
175 //                  while ((line = reader.readLine()) != null) {
176 //                      answer.append(line);
177 //                      System.out.println(line);
178 //                  }
179 //                  writer.close();
180 //                  reader.close();
181                     
182                     //Output the response
183                     
184                     
185                 } catch (MalformedURLException ex) {
186                     ex.printStackTrace();
187                 } catch (IOException ex) {
188                     ex.printStackTrace();
189                 }
190         }
191                         
192                         //in = new BufferedReader(new InputStreamReader(url.openStream()));
193                         
194                      //String str;
195                      
196                      
197                      //out = new FileOutputStream("temp.rnaml");
198                      //out = new BufferedWriter(new FileWriter("temp.rnaml"));
199                      
200                      //while ((str = in.readLine()) != null) {
201                      //System.out.println(str);
202                      //out.write(str);
203                      //System.out.println(str);
204 //                      in.close();
205                      
206                      
207                      //out.close();
208 //                   } catch (MalformedURLException e) {
209 //                   } catch (IOException e) {
210 //                   }
211 //              
212 //      }
213         
214         //public BufferedWriter getReader()
215         //{
216                         //System.out.println("The buffer");
217                         
218                         //return out;
219                         
220                 
221         //}
222
223 }