> getAllRequests() {
+ return mRequestQueue;
+ }
+
+ /**
+ * 为每个请求生成一个系列号
+ *
+ * @return 序列号
+ */
+ private int generateSerialNumber() {
+ return mSerialNumGenerator.incrementAndGet();
+ }
+}
diff --git a/network/SimpleNet/src/org/simple/net/core/ResponseDelivery.java b/network/SimpleNet/src/org/simple/net/core/ResponseDelivery.java
new file mode 100644
index 0000000..3528c9c
--- /dev/null
+++ b/network/SimpleNet/src/org/simple/net/core/ResponseDelivery.java
@@ -0,0 +1,70 @@
+/*
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2014-2015 bboyfeiyu@gmail.com, Inc
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+package org.simple.net.core;
+
+import android.os.Handler;
+import android.os.Looper;
+
+import org.simple.net.base.Request;
+import org.simple.net.base.Response;
+
+import java.util.concurrent.Executor;
+
+/**
+ * 请求结果投递类,将请求结果投递给UI线程
+ *
+ * @author mrsimple
+ */
+class ResponseDelivery implements Executor {
+
+ /**
+ * 主线程的hander
+ */
+ Handler mResponseHandler = new Handler(Looper.getMainLooper());
+
+ /**
+ * 处理请求结果,将其执行在UI线程
+ *
+ * @param request
+ * @param response
+ */
+ public void deliveryResponse(final Request> request, final Response response) {
+ Runnable respRunnable = new Runnable() {
+
+ @Override
+ public void run() {
+ request.deliveryResponse(response);
+ }
+ };
+
+ execute(respRunnable);
+ }
+
+ @Override
+ public void execute(Runnable command) {
+ mResponseHandler.post(command);
+ }
+
+}
diff --git a/network/SimpleNet/src/org/simple/net/core/SimpleNet.java b/network/SimpleNet/src/org/simple/net/core/SimpleNet.java
new file mode 100644
index 0000000..5acafa3
--- /dev/null
+++ b/network/SimpleNet/src/org/simple/net/core/SimpleNet.java
@@ -0,0 +1,65 @@
+/*
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2014-2015 bboyfeiyu@gmail.com
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+package org.simple.net.core;
+
+import org.simple.net.httpstacks.HttpStack;
+
+/**
+ * SimpleNet入口
+ * @author mrsimple
+ */
+public final class SimpleNet {
+ /**
+ * 创建一个请求队列,NetworkExecutor数量为默认的数量
+ *
+ * @return
+ */
+ public static RequestQueue newRequestQueue() {
+ return newRequestQueue(RequestQueue.DEFAULT_CORE_NUMS);
+ }
+
+ /**
+ * 创建一个请求队列,NetworkExecutor数量为coreNums
+ *
+ * @param coreNums
+ * @return
+ */
+ public static RequestQueue newRequestQueue(int coreNums) {
+ return newRequestQueue(coreNums, null);
+ }
+
+ /**
+ * 创建一个请求队列,NetworkExecutor数量为coreNums
+ *
+ * @param coreNums 线程数量
+ * @param httpStack 网络执行者
+ * @return
+ */
+ public static RequestQueue newRequestQueue(int coreNums, HttpStack httpStack) {
+ RequestQueue queue = new RequestQueue(Math.max(0, coreNums), httpStack);
+ queue.start();
+ return queue;
+ }
+}
diff --git a/network/SimpleNet/src/org/simple/net/entity/MultipartEntity.java b/network/SimpleNet/src/org/simple/net/entity/MultipartEntity.java
new file mode 100644
index 0000000..56deaeb
--- /dev/null
+++ b/network/SimpleNet/src/org/simple/net/entity/MultipartEntity.java
@@ -0,0 +1,265 @@
+/*
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2014-2015 bboyfeiyu@gmail.com, Inc
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+package org.simple.net.entity;
+
+import android.text.TextUtils;
+
+import org.apache.http.Header;
+import org.apache.http.HttpEntity;
+import org.apache.http.message.BasicHeader;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.Closeable;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.Random;
+
+/**
+ * POST报文格式请参考博客 : http://blog.csdn.net/bboyfeiyu/article/details/41863951.
+ *
+ * Android中的多参数类型的Entity实体类,用户可以使用该类来上传文件、文本参数、二进制参数,
+ * 不需要依赖于httpmime.jar来实现上传文件的功能.
+ *
+ *
+ * @author mrsimple
+ */
+public class MultipartEntity implements HttpEntity {
+
+ private final static char[] MULTIPART_CHARS = "-_1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
+ .toCharArray();
+ /**
+ * 换行符
+ */
+ private final String NEW_LINE_STR = "\r\n";
+ private final String CONTENT_TYPE = "Content-Type: ";
+ private final String CONTENT_DISPOSITION = "Content-Disposition: ";
+ /**
+ * 文本参数和字符集
+ */
+ private final String TYPE_TEXT_CHARSET = "text/plain; charset=UTF-8";
+
+ /**
+ * 字节流参数
+ */
+ private final String TYPE_OCTET_STREAM = "application/octet-stream";
+ /**
+ * 二进制参数
+ */
+ private final byte[] BINARY_ENCODING = "Content-Transfer-Encoding: binary\r\n\r\n".getBytes();
+ /**
+ * 文本参数
+ */
+ private final byte[] BIT_ENCODING = "Content-Transfer-Encoding: 8bit\r\n\r\n".getBytes();
+
+ /**
+ * 分隔符
+ */
+ private String mBoundary = null;
+ /**
+ * 输出流
+ */
+ ByteArrayOutputStream mOutputStream = new ByteArrayOutputStream();
+
+ public MultipartEntity() {
+ this.mBoundary = generateBoundary();
+ }
+
+ /**
+ * 生成分隔符
+ *
+ * @return
+ */
+ private final String generateBoundary() {
+ final StringBuffer buf = new StringBuffer();
+ final Random rand = new Random();
+ for (int i = 0; i < 30; i++) {
+ buf.append(MULTIPART_CHARS[rand.nextInt(MULTIPART_CHARS.length)]);
+ }
+ return buf.toString();
+ }
+
+ /**
+ * 参数开头的分隔符
+ *
+ * @throws IOException
+ */
+ private void writeFirstBoundary() throws IOException {
+ mOutputStream.write(("--" + mBoundary + "\r\n").getBytes());
+ }
+
+ /**
+ * 添加文本参数
+ *
+ * @param key
+ * @param value
+ */
+ public void addStringPart(final String paramName, final String value) {
+ writeToOutputStream(paramName, value.getBytes(), TYPE_TEXT_CHARSET, BIT_ENCODING, "");
+ }
+
+ /**
+ * 将数据写入到输出流中
+ *
+ * @param key
+ * @param rawData
+ * @param type
+ * @param encodingBytes
+ * @param fileName
+ */
+ private void writeToOutputStream(String paramName, byte[] rawData, String type,
+ byte[] encodingBytes,
+ String fileName) {
+ try {
+ writeFirstBoundary();
+ mOutputStream.write((CONTENT_TYPE + type + NEW_LINE_STR).getBytes());
+ mOutputStream
+ .write(getContentDispositionBytes(paramName, fileName));
+ mOutputStream.write(encodingBytes);
+ mOutputStream.write(rawData);
+ mOutputStream.write(NEW_LINE_STR.getBytes());
+ } catch (final IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * 添加二进制参数, 例如Bitmap的字节流参数
+ *
+ * @param key
+ * @param rawData
+ */
+ public void addBinaryPart(String paramName, final byte[] rawData) {
+ writeToOutputStream(paramName, rawData, TYPE_OCTET_STREAM, BINARY_ENCODING, "no-file");
+ }
+
+ /**
+ * 添加文件参数,可以实现文件上传功能
+ *
+ * @param key
+ * @param file
+ */
+ public void addFilePart(final String key, final File file) {
+ InputStream fin = null;
+ try {
+ fin = new FileInputStream(file);
+ writeFirstBoundary();
+ final String type = CONTENT_TYPE + TYPE_OCTET_STREAM + NEW_LINE_STR;
+ mOutputStream.write(getContentDispositionBytes(key, file.getName()));
+ mOutputStream.write(type.getBytes());
+ mOutputStream.write(BINARY_ENCODING);
+
+ final byte[] tmp = new byte[4096];
+ int len = 0;
+ while ((len = fin.read(tmp)) != -1) {
+ mOutputStream.write(tmp, 0, len);
+ }
+ mOutputStream.flush();
+ } catch (final IOException e) {
+ e.printStackTrace();
+ } finally {
+ closeSilently(fin);
+ }
+ }
+
+ private void closeSilently(Closeable closeable) {
+ try {
+ if (closeable != null) {
+ closeable.close();
+ }
+ } catch (final IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ private byte[] getContentDispositionBytes(String paramName, String fileName) {
+ StringBuilder stringBuilder = new StringBuilder();
+ stringBuilder.append(CONTENT_DISPOSITION + "form-data; name=\"" + paramName + "\"");
+ // 文本参数没有filename参数,设置为空即可
+ if (!TextUtils.isEmpty(fileName)) {
+ stringBuilder.append("; filename=\""
+ + fileName + "\"");
+ }
+
+ return stringBuilder.append(NEW_LINE_STR).toString().getBytes();
+ }
+
+ @Override
+ public long getContentLength() {
+ return mOutputStream.toByteArray().length;
+ }
+
+ @Override
+ public Header getContentType() {
+ return new BasicHeader("Content-Type", "multipart/form-data; boundary=" + mBoundary);
+ }
+
+ @Override
+ public boolean isChunked() {
+ return false;
+ }
+
+ @Override
+ public boolean isRepeatable() {
+ return false;
+ }
+
+ @Override
+ public boolean isStreaming() {
+ return false;
+ }
+
+ @Override
+ public void writeTo(final OutputStream outstream) throws IOException {
+ // 参数最末尾的结束符
+ final String endString = "--" + mBoundary + "--\r\n";
+ // 写入结束符
+ mOutputStream.write(endString.getBytes());
+ //
+ outstream.write(mOutputStream.toByteArray());
+ }
+
+ @Override
+ public Header getContentEncoding() {
+ return null;
+ }
+
+ @Override
+ public void consumeContent() throws IOException,
+ UnsupportedOperationException {
+ if (isStreaming()) {
+ throw new UnsupportedOperationException(
+ "Streaming entity does not implement #consumeContent()");
+ }
+ }
+
+ @Override
+ public InputStream getContent() {
+ return new ByteArrayInputStream(mOutputStream.toByteArray());
+ }
+}
diff --git a/network/SimpleNet/src/org/simple/net/httpstacks/HttpClientStack.java b/network/SimpleNet/src/org/simple/net/httpstacks/HttpClientStack.java
new file mode 100644
index 0000000..7073ecb
--- /dev/null
+++ b/network/SimpleNet/src/org/simple/net/httpstacks/HttpClientStack.java
@@ -0,0 +1,166 @@
+/*
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2014-2015 bboyfeiyu@gmail.com, Inc
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+package org.simple.net.httpstacks;
+
+import android.net.http.AndroidHttpClient;
+
+import org.apache.http.HttpEntity;
+import org.apache.http.HttpResponse;
+import org.apache.http.client.HttpClient;
+import org.apache.http.client.methods.HttpDelete;
+import org.apache.http.client.methods.HttpEntityEnclosingRequestBase;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.client.methods.HttpPut;
+import org.apache.http.client.methods.HttpUriRequest;
+import org.apache.http.conn.scheme.Scheme;
+import org.apache.http.conn.ssl.SSLSocketFactory;
+import org.apache.http.entity.ByteArrayEntity;
+import org.apache.http.params.HttpConnectionParams;
+import org.apache.http.params.HttpParams;
+import org.simple.net.base.Request;
+import org.simple.net.base.Response;
+import org.simple.net.config.HttpClientConfig;
+
+import java.util.Map;
+
+/**
+ * api 9以下使用HttpClient执行网络请求, https配置参考http://jackyrong.iteye.com/blog/1606444
+ *
+ * @author mrsimple
+ */
+public class HttpClientStack implements HttpStack {
+
+ /**
+ * 使用HttpClient执行网络请求时的Https配置
+ */
+ HttpClientConfig mConfig = HttpClientConfig.getConfig();
+ /**
+ * HttpClient
+ */
+ HttpClient mHttpClient = AndroidHttpClient.newInstance(mConfig.userAgent);
+
+ @Override
+ public Response performRequest(Request> request) {
+ try {
+ HttpUriRequest httpRequest = createHttpRequest(request);
+ // 添加连接参数
+ setConnectionParams(httpRequest);
+ // 添加header
+ addHeaders(httpRequest, request.getHeaders());
+ // https配置
+ configHttps(request);
+ // 执行请求
+ HttpResponse response = mHttpClient.execute(httpRequest);
+ // 构建Response
+ Response rawResponse = new Response(response.getStatusLine());
+ // 设置Entity
+ rawResponse.setEntity(response.getEntity());
+ return rawResponse;
+ } catch (Exception e) {
+ }
+
+ return null;
+ }
+
+ /**
+ * 如果是https请求,则使用用户配置的SSLSocketFactory进行配置.
+ *
+ * @param request
+ */
+ private void configHttps(Request> request) {
+ SSLSocketFactory sslSocketFactory = mConfig.getSocketFactory();
+ if (request.isHttps() && sslSocketFactory != null) {
+ Scheme sch = new Scheme("https", sslSocketFactory, 443);
+ mHttpClient.getConnectionManager().getSchemeRegistry().register(sch);
+ }
+ }
+
+ /**
+ * 设置连接参数,这里比较简单啊.一些优化设置就没有写了.
+ *
+ * @param httpUriRequest
+ */
+ private void setConnectionParams(HttpUriRequest httpUriRequest) {
+ HttpParams httpParams = httpUriRequest.getParams();
+ HttpConnectionParams.setConnectionTimeout(httpParams, mConfig.connTimeOut);
+ HttpConnectionParams.setSoTimeout(httpParams, mConfig.soTimeOut);
+ }
+
+ /**
+ * 根据请求类型创建不同的Http请求
+ *
+ * @param request
+ * @return
+ */
+ static HttpUriRequest createHttpRequest(Request> request) {
+ HttpUriRequest httpUriRequest = null;
+ switch (request.getHttpMethod()) {
+ case GET:
+ httpUriRequest = new HttpGet(request.getUrl());
+ break;
+ case DELETE:
+ httpUriRequest = new HttpDelete(request.getUrl());
+ break;
+ case POST: {
+ httpUriRequest = new HttpPost(request.getUrl());
+ httpUriRequest.addHeader(Request.HEADER_CONTENT_TYPE, request.getBodyContentType());
+ setEntityIfNonEmptyBody((HttpPost) httpUriRequest, request);
+ }
+ break;
+ case PUT: {
+ httpUriRequest = new HttpPut(request.getUrl());
+ httpUriRequest.addHeader(Request.HEADER_CONTENT_TYPE, request.getBodyContentType());
+ setEntityIfNonEmptyBody((HttpPut) httpUriRequest, request);
+ }
+ break;
+ default:
+ throw new IllegalStateException("Unknown request method.");
+ }
+
+ return httpUriRequest;
+ }
+
+ private static void addHeaders(HttpUriRequest httpRequest, Map headers) {
+ for (String key : headers.keySet()) {
+ httpRequest.setHeader(key, headers.get(key));
+ }
+ }
+
+ /**
+ * 将请求参数设置到HttpEntity中
+ *
+ * @param httpRequest
+ * @param request
+ */
+ private static void setEntityIfNonEmptyBody(HttpEntityEnclosingRequestBase httpRequest,
+ Request> request) {
+ byte[] body = request.getBody();
+ if (body != null) {
+ HttpEntity entity = new ByteArrayEntity(body);
+ httpRequest.setEntity(entity);
+ }
+ }
+}
diff --git a/network/SimpleNet/src/org/simple/net/httpstacks/HttpStack.java b/network/SimpleNet/src/org/simple/net/httpstacks/HttpStack.java
new file mode 100644
index 0000000..b7c3e6a
--- /dev/null
+++ b/network/SimpleNet/src/org/simple/net/httpstacks/HttpStack.java
@@ -0,0 +1,43 @@
+/*
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2014-2015 bboyfeiyu@gmail.com, Inc
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+package org.simple.net.httpstacks;
+
+import org.simple.net.base.Request;
+import org.simple.net.base.Response;
+
+/**
+ * 执行网络请求的接口
+ *
+ * @author mrsimple
+ */
+public interface HttpStack {
+ /**
+ * 执行Http请求
+ *
+ * @param request 待执行的请求
+ * @return
+ */
+ public Response performRequest(Request> request);
+}
diff --git a/network/SimpleNet/src/org/simple/net/httpstacks/HttpStackFactory.java b/network/SimpleNet/src/org/simple/net/httpstacks/HttpStackFactory.java
new file mode 100644
index 0000000..062ecb5
--- /dev/null
+++ b/network/SimpleNet/src/org/simple/net/httpstacks/HttpStackFactory.java
@@ -0,0 +1,53 @@
+/*
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2014-2015 bboyfeiyu@gmail.com, Inc
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+package org.simple.net.httpstacks;
+
+import android.os.Build;
+
+/**
+ * 根据api版本选择HttpClient或者HttpURLConnection
+ *
+ * @author mrsimple
+ */
+public final class HttpStackFactory {
+
+ private static final int GINGERBREAD_SDK_NUM = 9;
+
+ /**
+ * 根据SDK版本号来创建不同的Http执行器,即SDK 9之前使用HttpClient,之后则使用HttlUrlConnection,
+ * 两者之间的差别请参考 :
+ * http://android-developers.blogspot.com/2011/09/androids-http-clients.html
+ *
+ * @return
+ */
+ public static HttpStack createHttpStack() {
+ int runtimeSDKApi = Build.VERSION.SDK_INT;
+ if (runtimeSDKApi >= GINGERBREAD_SDK_NUM) {
+ return new HttpUrlConnStack();
+ }
+
+ return new HttpClientStack();
+ }
+}
diff --git a/network/SimpleNet/src/org/simple/net/httpstacks/HttpUrlConnStack.java b/network/SimpleNet/src/org/simple/net/httpstacks/HttpUrlConnStack.java
new file mode 100644
index 0000000..3386141
--- /dev/null
+++ b/network/SimpleNet/src/org/simple/net/httpstacks/HttpUrlConnStack.java
@@ -0,0 +1,190 @@
+/*
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2014-2015 bboyfeiyu@gmail.com, Inc
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+package org.simple.net.httpstacks;
+
+import org.apache.http.Header;
+import org.apache.http.HttpEntity;
+import org.apache.http.ProtocolVersion;
+import org.apache.http.StatusLine;
+import org.apache.http.entity.BasicHttpEntity;
+import org.apache.http.message.BasicHeader;
+import org.apache.http.message.BasicHttpResponse;
+import org.apache.http.message.BasicStatusLine;
+import org.simple.net.base.Request;
+import org.simple.net.base.Request.HttpMethod;
+import org.simple.net.base.Response;
+import org.simple.net.config.HttpUrlConnConfig;
+
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.HttpURLConnection;
+import java.net.ProtocolException;
+import java.net.URL;
+import java.net.URLConnection;
+import java.util.List;
+import java.util.Map.Entry;
+import java.util.Set;
+
+import javax.net.ssl.HttpsURLConnection;
+import javax.net.ssl.SSLSocketFactory;
+
+/**
+ * 使用HttpURLConnection执行网络请求的HttpStack
+ *
+ * @author mrsimple
+ */
+public class HttpUrlConnStack implements HttpStack {
+
+ /**
+ * 配置Https
+ */
+ HttpUrlConnConfig mConfig = HttpUrlConnConfig.getConfig();
+
+ @Override
+ public Response performRequest(Request> request) {
+ HttpURLConnection urlConnection = null;
+ try {
+ // 构建HttpURLConnection
+ urlConnection = createUrlConnection(request.getUrl());
+ // 设置headers
+ setRequestHeaders(urlConnection, request);
+ // 设置Body参数
+ setRequestParams(urlConnection, request);
+ // https 配置
+ configHttps(request);
+ return fetchResponse(urlConnection);
+ } catch (Exception e) {
+ e.printStackTrace();
+ } finally {
+ if (urlConnection != null) {
+ urlConnection.disconnect();
+ }
+ }
+ return null;
+ }
+
+ private HttpURLConnection createUrlConnection(String url) throws IOException {
+ URL newURL = new URL(url);
+ URLConnection urlConnection = newURL.openConnection();
+ urlConnection.setConnectTimeout(mConfig.connTimeOut);
+ urlConnection.setReadTimeout(mConfig.soTimeOut);
+ urlConnection.setDoInput(true);
+ urlConnection.setUseCaches(false);
+ return (HttpURLConnection) urlConnection;
+ }
+
+ private void configHttps(Request> request) {
+ if (request.isHttps()) {
+ SSLSocketFactory sslFactory = mConfig.getSslSocketFactory();
+ // 配置https
+ if (sslFactory != null) {
+ HttpsURLConnection.setDefaultSSLSocketFactory(sslFactory);
+ HttpsURLConnection.setDefaultHostnameVerifier(mConfig.getHostnameVerifier());
+ }
+
+ }
+ }
+
+ private void setRequestHeaders(HttpURLConnection connection, Request> request) {
+ Set headersKeys = request.getHeaders().keySet();
+ for (String headerName : headersKeys) {
+ connection.addRequestProperty(headerName, request.getHeaders().get(headerName));
+ }
+ }
+
+ protected void setRequestParams(HttpURLConnection connection, Request> request)
+ throws ProtocolException, IOException {
+ HttpMethod method = request.getHttpMethod();
+ connection.setRequestMethod(method.toString());
+ // add params
+ byte[] body = request.getBody();
+ if (body != null) {
+ // enable output
+ connection.setDoOutput(true);
+ // set content type
+ connection
+ .addRequestProperty(Request.HEADER_CONTENT_TYPE, request.getBodyContentType());
+ // write params data to connection
+ DataOutputStream dataOutputStream = new DataOutputStream(connection.getOutputStream());
+ dataOutputStream.write(body);
+ dataOutputStream.close();
+ }
+ }
+
+ private Response fetchResponse(HttpURLConnection connection) throws IOException {
+
+ // Initialize HttpResponse with data from the HttpURLConnection.
+ ProtocolVersion protocolVersion = new ProtocolVersion("HTTP", 1, 1);
+ int responseCode = connection.getResponseCode();
+ if (responseCode == -1) {
+ throw new IOException("Could not retrieve response code from HttpUrlConnection.");
+ }
+ // 状态行数据
+ StatusLine responseStatus = new BasicStatusLine(protocolVersion,
+ connection.getResponseCode(), connection.getResponseMessage());
+ // 构建response
+ Response response = new Response(responseStatus);
+ // 设置response数据
+ response.setEntity(entityFromURLConnwction(connection));
+ addHeadersToResponse(response, connection);
+ return response;
+ }
+
+ /**
+ * 执行HTTP请求之后获取到其数据流,即返回请求结果的流
+ *
+ * @param connection
+ * @return
+ */
+ private HttpEntity entityFromURLConnwction(HttpURLConnection connection) {
+ BasicHttpEntity entity = new BasicHttpEntity();
+ InputStream inputStream = null;
+ try {
+ inputStream = connection.getInputStream();
+ } catch (IOException e) {
+ e.printStackTrace();
+ inputStream = connection.getErrorStream();
+ }
+
+ // TODO : GZIP
+ entity.setContent(inputStream);
+ entity.setContentLength(connection.getContentLength());
+ entity.setContentEncoding(connection.getContentEncoding());
+ entity.setContentType(connection.getContentType());
+
+ return entity;
+ }
+
+ private void addHeadersToResponse(BasicHttpResponse response, HttpURLConnection connection) {
+ for (Entry> header : connection.getHeaderFields().entrySet()) {
+ if (header.getKey() != null) {
+ Header h = new BasicHeader(header.getKey(), header.getValue().get(0));
+ response.addHeader(h);
+ }
+ }
+ }
+
+}
diff --git a/network/SimpleNet/src/org/simple/net/requests/JsonRequest.java b/network/SimpleNet/src/org/simple/net/requests/JsonRequest.java
new file mode 100644
index 0000000..5ef9cad
--- /dev/null
+++ b/network/SimpleNet/src/org/simple/net/requests/JsonRequest.java
@@ -0,0 +1,57 @@
+/*
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2014-2015 bboyfeiyu@gmail.com, Inc
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+package org.simple.net.requests;
+
+import org.json.JSONException;
+import org.json.JSONObject;
+import org.simple.net.base.Request;
+import org.simple.net.base.Response;
+
+/**
+ * 返回的数据类型为Json的请求, Json对应的对象类型为JSONObject
+ *
+ * @author mrsimple
+ */
+public class JsonRequest extends Request {
+
+ public JsonRequest(HttpMethod method, String url, RequestListener listener) {
+ super(method, url, listener);
+ }
+
+
+ /**
+ * 将Response的结果转换为JSONObject
+ */
+ @Override
+ public JSONObject parseResponse(Response response) {
+ String jsonString = new String(response.getRawData());
+ try {
+ return new JSONObject(jsonString);
+ } catch (JSONException e) {
+ e.printStackTrace();
+ }
+ return null;
+ }
+}
diff --git a/network/SimpleNet/src/org/simple/net/requests/MultipartRequest.java b/network/SimpleNet/src/org/simple/net/requests/MultipartRequest.java
new file mode 100644
index 0000000..35edce7
--- /dev/null
+++ b/network/SimpleNet/src/org/simple/net/requests/MultipartRequest.java
@@ -0,0 +1,82 @@
+/*
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2014-2015 bboyfeiyu@gmail.com, Inc
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+package org.simple.net.requests;
+
+import android.util.Log;
+
+import org.simple.net.base.Request;
+import org.simple.net.base.Response;
+import org.simple.net.entity.MultipartEntity;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+
+/**
+ * Multipart请求 ( 只能为POST请求 ),该请求可以搭载多种类型参数,比如文本、文件等,但是文件仅限于小文件,否则会出现OOM异常.
+ *
+ * @author mrsimple
+ */
+public class MultipartRequest extends Request {
+
+ MultipartEntity mMultiPartEntity = new MultipartEntity();
+
+ public MultipartRequest(String url, RequestListener listener) {
+ super(HttpMethod.POST, url, listener);
+ }
+
+ /**
+ * @return
+ */
+ public MultipartEntity getMultiPartEntity() {
+ return mMultiPartEntity;
+ }
+
+ @Override
+ public String getBodyContentType() {
+ return mMultiPartEntity.getContentType().getValue();
+ }
+
+ @Override
+ public byte[] getBody() {
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ try {
+ // 将MultipartEntity中的参数写入到bos中
+ mMultiPartEntity.writeTo(bos);
+ } catch (IOException e) {
+ Log.e("", "IOException writing to ByteArrayOutputStream");
+ }
+ return bos.toByteArray();
+ }
+
+ @Override
+ public String parseResponse(Response response) {
+ if (response != null && response.getRawData() != null) {
+ return new String(response.getRawData());
+ }
+
+ return "";
+ }
+
+}
diff --git a/network/SimpleNet/src/org/simple/net/requests/StringRequest.java b/network/SimpleNet/src/org/simple/net/requests/StringRequest.java
new file mode 100644
index 0000000..28f2765
--- /dev/null
+++ b/network/SimpleNet/src/org/simple/net/requests/StringRequest.java
@@ -0,0 +1,41 @@
+/*
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2014-2015 bboyfeiyu@gmail.com, Inc
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+package org.simple.net.requests;
+
+import org.simple.net.base.Request;
+import org.simple.net.base.Response;
+
+public class StringRequest extends Request {
+
+ public StringRequest(HttpMethod method, String url, RequestListener listener) {
+ super(method, url, listener);
+ }
+
+ @Override
+ public String parseResponse(Response response) {
+ return new String(response.getRawData());
+ }
+
+}
diff --git a/orm/README.md b/orm/README.md
new file mode 100644
index 0000000..648ebb5
--- /dev/null
+++ b/orm/README.md
@@ -0,0 +1,13 @@
+# 任务表
+| 开源框架名称 | 作者 | 预计完成时间 |
+| ------------- |:-------------:| ------------- |
+| | [用户名](git地址) | 完成时间 |
+
+
+
+
+
+
+
+
+
diff --git a/others/README.md b/others/README.md
new file mode 100644
index 0000000..c6eec1a
--- /dev/null
+++ b/others/README.md
@@ -0,0 +1,13 @@
+# 任务表
+| 简版框架名称 | 作者 | 预计完成时间 |
+| ------------- |:-------------:| ------------- |
+| 这里指向你的框架文件夹 | [用户名](git地址) | 完成时间 |
+
+
+
+
+
+
+
+
+
diff --git a/template.md b/template.md
new file mode 100644
index 0000000..ca140d4
--- /dev/null
+++ b/template.md
@@ -0,0 +1,52 @@
+${简版开源库} 的设计与实现
+====================================
+> 本文为 [Android著名开源库的简版实现](https://github.com/simple-android-framework-exchange/simple-android-opensource-framework) 中的 ${简版开源库} 的设计与实现
+> 原始开源库: [${原始开源库名称}](链接)
+> 作者:[作者用户名](作者github链接),开发状态:完成/未完成,校对者:[等待管理员填写](),校对状态:未开始
+
+
+建议大家看下 [SimpleNet](network/SimpleNet/README.md),了解应该写到什么程度,以及类似流程图和总体设计该怎么做。当然,如果你只想写README.md一篇介绍,那么该文档中必须包含详细的设计与源码实现介绍,阐述其核心原理。如果你的README.md只是一篇介绍性文档,那么后续必须增加其他阐述核心原理的其他文档。
+
+`复制一份到自己的项目文件夹下,然后根据自己项目替换掉 ${} 内容,删掉本行及上面两行。`
+
+## 1. 功能介绍
+功能介绍,包括功能或优点等
+
+
+## 2. 总体设计
+整个库分为哪些模块及模块之间的调用关系。
+- 如大多数图片缓存会分为 Loader 和 Processer 等模块。
+- 可使用 [Google Drawing](https://docs.google.com/drawings)、[Visio](http://products.office.com/en-us/visio/flowchart-software)、[StarUML](http://staruml.io/) 等工具完成,其他工具推荐??
+- 非所有项目必须,不需要的请先在群里反馈。
+
+
+## 3. 流程图
+主要功能流程图
+
+- 如 Retrofit、Volley 的请求处理流程,Android-Universal-Image-Loader 的图片处理流程图
+- 可使用 [Google Drawing](https://docs.google.com/drawings)、[Visio](http://products.office.com/en-us/visio/flowchart-software)、[StarUML](http://staruml.io/) 等工具完成,其他工具推荐??
+- 非所有项目必须,不需要的请先在群里反馈
+
+
+
+
+## 4. 详细设计
+### 4.1 核心类详细介绍
+
+类及其主要函数功能介绍、核心功能流程图,流程图可使用 [Google Drawing](https://docs.google.com/drawings)、[Visio](http://products.office.com/en-us/visio/flowchart-software)、[StarUML](http://staruml.io/)。
+
+
+### 4.2 类关系图
+类关系图,类的继承、组合关系图,可是用 [StarUML](http://staruml.io/) 工具。
+
+
+
+
+##5. 杂谈
+该项目存在的问题、可优化点及类似功能项目对比等,非所有项目必须。
+
+
+
+
+`写完相关内容之后到开发群告知管理员,管理员安排相关人员进行审核,审核通过之后即可。`
+
diff --git a/view/README.md b/view/README.md
new file mode 100644
index 0000000..c6eec1a
--- /dev/null
+++ b/view/README.md
@@ -0,0 +1,13 @@
+# 任务表
+| 简版框架名称 | 作者 | 预计完成时间 |
+| ------------- |:-------------:| ------------- |
+| 这里指向你的框架文件夹 | [用户名](git地址) | 完成时间 |
+
+
+
+
+
+
+
+
+