BrightSide Workbench Full Report + Source Code
FileWDUtil.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2011 Lluis TurrĂ³ Cutiller <http://www.turro.org/>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Affero General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Affero General Public License for more details.
14  *
15  * You should have received a copy of the GNU Affero General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 package org.turro.wd.util;
19 
20 //import java.io.File;
21 //import java.io.FileOutputStream;
22 //import java.io.IOException;
23 //import java.io.UnsupportedEncodingException;
24 //import java.nio.channels.Channel;
25 //import java.nio.channels.Channels;
26 //import java.nio.channels.FileChannel;
27 //import java.nio.channels.ReadableByteChannel;
28 //import java.nio.charset.Charset;
29 //import org.apache.http.HttpEntity;
30 //import org.apache.http.HttpResponse;
31 //import org.apache.http.client.ClientProtocolException;
32 //import org.apache.http.client.methods.HttpGet;
33 //import org.apache.http.client.methods.HttpPost;
34 //import org.apache.http.entity.mime.HttpMultipartMode;
35 //import org.apache.http.entity.mime.MultipartEntity;
36 //import org.apache.http.entity.mime.content.ContentBody;
37 //import org.apache.http.entity.mime.content.FileBody;
38 //import org.apache.http.entity.mime.content.StringBody;
39 //import org.apache.http.impl.client.DefaultHttpClient;
40 
45 public class FileWDUtil {
46 
47 // public HttpResponse upload(String uri, String path, String fileName, File file, String comment)
48 // throws UnsupportedEncodingException, ClientProtocolException, IOException {
49 // DefaultHttpClient httpclient = new DefaultHttpClient();
50 //
51 // HttpPost method = new HttpPost(uri);
52 //
53 // MultipartEntity entity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
54 // entity.addPart("fwd_comment", (ContentBody) new StringBody(comment, Charset.forName("UTF-8")));
55 // entity.addPart("fwd_fileName", (ContentBody) new StringBody(fileName, Charset.forName("UTF-8")));
56 // entity.addPart("fwd_path", (ContentBody) new StringBody(path, Charset.forName("UTF-8")));
57 // entity.addPart("fwd_file", (ContentBody) new FileBody(file));
58 // method.setEntity(entity);
59 //
60 // return httpclient.execute(method);
61 // }
62 //
63 // public HttpResponse download(String uri, String path, String fileName, File file) throws IOException {
64 // DefaultHttpClient httpclient = new DefaultHttpClient();
65 //
66 // HttpGet httpget = new HttpGet(uri);
67 // httpget.getParams().setParameter("fwd_path", path);
68 // httpget.getParams().setParameter("fwd_fileName", file);
69 // HttpResponse response = httpclient.execute(httpget);
70 //
71 // HttpEntity entity = response.getEntity();
72 //
73 // if (entity != null) {
74 // Channel inChannel = Channels.newChannel(entity.getContent());
75 // FileChannel outChannel = new FileOutputStream(file).getChannel();
76 // try {
77 // outChannel.transferFrom((ReadableByteChannel) inChannel, 0, entity.getContentLength());
78 // } catch (IOException e) {
79 // throw e;
80 // } catch (RuntimeException ex) {
81 // httpget.abort();
82 // throw ex;
83 // } finally {
84 // if (inChannel != null) {
85 // inChannel.close();
86 // }
87 // if (outChannel != null) {
88 // outChannel.close();
89 // }
90 // }
91 // httpclient.getConnectionManager().shutdown();
92 // }
93 //
94 // return response;
95 // }
96 
97 }