From 352b780363fe129066fd0fafaa55af0a526c8549 Mon Sep 17 00:00:00 2001 From: "Denny C. Ng" Date: Tue, 14 Apr 2015 11:45:19 +0800 Subject: [PATCH] delete useless code delete useless code --- .../tsinghua/spice/Utilies/SpiceHttpUtil.java | 90 ------------------- 1 file changed, 90 deletions(-) delete mode 100644 twidere/src/main/java/edu/tsinghua/spice/Utilies/SpiceHttpUtil.java diff --git a/twidere/src/main/java/edu/tsinghua/spice/Utilies/SpiceHttpUtil.java b/twidere/src/main/java/edu/tsinghua/spice/Utilies/SpiceHttpUtil.java deleted file mode 100644 index d445f81dd..000000000 --- a/twidere/src/main/java/edu/tsinghua/spice/Utilies/SpiceHttpUtil.java +++ /dev/null @@ -1,90 +0,0 @@ -package edu.tsinghua.spice.Utilies; - -import java.io.InputStream; -import java.io.OutputStream; -import java.net.HttpURLConnection; -import java.net.URL; - -/** - * Created by Denny C. Ng on 2/20/15. - - * Copyright (C) 2013 Surviving with Android (http://www.survivingwithandroid.com) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -public class SpiceHttpUtil { - private String url; - private HttpURLConnection con; - private OutputStream os; - - private String delimiter = "--"; - private String boundary = "SwA"+Long.toString(System.currentTimeMillis())+"SwA"; - - public SpiceHttpUtil(String url) { - this.url = url; - } - - public void connectForMultipart() throws Exception { - con = (HttpURLConnection) ( new URL(url)).openConnection(); - con.setRequestMethod("POST"); - con.setDoInput(true); - con.setDoOutput(true); - con.setRequestProperty("Connection", "Keep-Alive"); - con.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + boundary); - con.connect(); - os = con.getOutputStream(); - } - - public void addFormPart(String paramName, String value) throws Exception { - writeParamData(paramName, value); - } - - public void addFilePart(String paramName, String fileName, byte[] data) throws Exception { - os.write( (delimiter + boundary + "\r\n").getBytes()); - os.write( ("Content-Disposition: form-data; name=\"" + paramName + "\"; filename=\"" + fileName + "\"\r\n" ).getBytes()); - os.write( ("Content-Type: application/octet-stream\r\n" ).getBytes()); - os.write( ("Content-Transfer-Encoding: binary\r\n" ).getBytes()); - os.write("\r\n".getBytes()); - - os.write(data); - - os.write("\r\n".getBytes()); - } - - public void finishMultipart() throws Exception { - os.write( (delimiter + boundary + delimiter + "\r\n").getBytes()); - } - - - public String getResponse() throws Exception { - InputStream is = con.getInputStream(); - byte[] b1 = new byte[1024]; - StringBuffer buffer = new StringBuffer(); - - while ( is.read(b1) != -1) - buffer.append(new String(b1)); - - con.disconnect(); - - return buffer.toString(); - } - - private void writeParamData(String paramName, String value) throws Exception { - - os.write( (delimiter + boundary + "\r\n").getBytes()); - os.write( "Content-Type: text/plain\r\n".getBytes()); - os.write( ("Content-Disposition: form-data; name=\"" + paramName + "\"\r\n").getBytes());; - os.write( ("\r\n" + value + "\r\n").getBytes()); - } -}