├── deploy.sh
├── src
├── test
│ ├── resources
│ │ └── org.robolectric.Config.properties
│ └── java
│ │ └── com
│ │ └── android
│ │ └── volley
│ │ ├── mock
│ │ ├── ShadowSystemClock.java
│ │ ├── MockCache.java
│ │ ├── MockResponseDelivery.java
│ │ ├── MockNetwork.java
│ │ ├── MockHttpURLConnection.java
│ │ ├── MockHttpStack.java
│ │ ├── WaitableQueue.java
│ │ ├── MockRequest.java
│ │ ├── MockHttpClient.java
│ │ └── TestRequest.java
│ │ ├── utils
│ │ ├── ImmediateResponseDelivery.java
│ │ └── CacheTestUtils.java
│ │ ├── toolbox
│ │ ├── RequestFutureTest.java
│ │ ├── StringRequestTest.java
│ │ ├── CacheTest.java
│ │ ├── RequestQueueTest.java
│ │ ├── ResponseTest.java
│ │ ├── JsonRequestTest.java
│ │ ├── ByteArrayPoolTest.java
│ │ ├── NetworkImageViewTest.java
│ │ ├── PoolingByteArrayOutputStreamTest.java
│ │ ├── BasicNetworkTest.java
│ │ ├── RequestTest.java
│ │ ├── ImageLoaderTest.java
│ │ ├── AndroidAuthenticatorTest.java
│ │ ├── JsonRequestCharsetTest.java
│ │ ├── HttpClientStackTest.java
│ │ └── DiskBasedCacheTest.java
│ │ ├── ResponseDeliveryTest.java
│ │ ├── RequestQueueTest.java
│ │ ├── RequestTest.java
│ │ ├── NetworkDispatcherTest.java
│ │ └── CacheDispatcherTest.java
└── main
│ ├── AndroidManifest.xml
│ └── java
│ └── com
│ └── android
│ └── volley
│ ├── RedirectError.java
│ ├── TimeoutError.java
│ ├── ServerError.java
│ ├── NoConnectionError.java
│ ├── ParseError.java
│ ├── Network.java
│ ├── NetworkError.java
│ ├── toolbox
│ ├── Authenticator.java
│ ├── NoCache.java
│ ├── HttpStack.java
│ ├── ClearCacheRequest.java
│ ├── StringRequest.java
│ ├── PoolingByteArrayOutputStream.java
│ ├── JsonRequest.java
│ ├── AndroidAuthenticator.java
│ ├── RequestFuture.java
│ ├── Volley.java
│ ├── JsonObjectRequest.java
│ ├── ByteArrayPool.java
│ ├── JsonArrayRequest.java
│ └── HttpHeaderParser.java
│ ├── ResponseDelivery.java
│ ├── InternalUtils.java
│ ├── RetryPolicy.java
│ ├── VolleyError.java
│ ├── AuthFailureError.java
│ ├── NetworkResponse.java
│ ├── Response.java
│ ├── Cache.java
│ ├── DefaultRetryPolicy.java
│ ├── ExecutorDelivery.java
│ └── NetworkDispatcher.java
├── rules.gradle
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .gitignore
├── custom_rules.xml
├── proguard-project.txt
├── gradle.properties
├── Android.mk
├── proguard.cfg
├── README.md
├── gradlew.bat
├── gradlew
└── pom.xml
/deploy.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 | ./gradlew -x test clean assembleRelease uploadArchives
3 |
--------------------------------------------------------------------------------
/src/test/resources/org.robolectric.Config.properties:
--------------------------------------------------------------------------------
1 | manifest=src/main/AndroidManifest.xml
2 |
--------------------------------------------------------------------------------
/rules.gradle:
--------------------------------------------------------------------------------
1 | // See build.gradle for an explanation of what this file is.
2 |
3 | apply plugin: 'com.android.library'
4 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mcxiaoke/android-volley/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Thu Feb 13 14:10:23 CST 2014
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=http\://services.gradle.org/distributions/gradle-2.6-bin.zip
7 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *~
2 | .gradle
3 | gen
4 | bin
5 | local.properties
6 | *.apk
7 | .*.swp
8 | .idea
9 | gen-external-apklibs
10 | target
11 | classes
12 | project.properties
13 | *.iml
14 | .DS_Store
15 | out
16 | .gradle
17 | build
18 | .settings
19 | target
20 | *.iml
21 | .idea
22 | local.properties
23 |
--------------------------------------------------------------------------------
/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/src/test/java/com/android/volley/mock/ShadowSystemClock.java:
--------------------------------------------------------------------------------
1 | package com.android.volley.mock;
2 |
3 | import android.os.SystemClock;
4 | import org.robolectric.annotation.Implements;
5 |
6 | @Implements(value = SystemClock.class, callThroughByDefault = true)
7 | public class ShadowSystemClock {
8 | public static long elapsedRealtime() {
9 | return 0;
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/custom_rules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
6 |
7 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/src/main/java/com/android/volley/RedirectError.java:
--------------------------------------------------------------------------------
1 | package com.android.volley;
2 |
3 | /**
4 | * Indicates that there was a redirection.
5 | */
6 | public class RedirectError extends VolleyError {
7 |
8 | public RedirectError() {
9 | }
10 |
11 | public RedirectError(final Throwable cause) {
12 | super(cause);
13 | }
14 |
15 | public RedirectError(final NetworkResponse response) {
16 | super(response);
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/src/test/java/com/android/volley/utils/ImmediateResponseDelivery.java:
--------------------------------------------------------------------------------
1 | // Copyright 2011 Google Inc. All rights reserved.
2 |
3 | package com.android.volley.utils;
4 |
5 | import com.android.volley.ExecutorDelivery;
6 |
7 | import java.util.concurrent.Executor;
8 |
9 | /**
10 | * A ResponseDelivery for testing that immediately delivers responses
11 | * instead of posting back to the main thread.
12 | */
13 | public class ImmediateResponseDelivery extends ExecutorDelivery {
14 |
15 | public ImmediateResponseDelivery() {
16 | super(new Executor() {
17 | @Override
18 | public void execute(Runnable command) {
19 | command.run();
20 | }
21 | });
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/proguard-project.txt:
--------------------------------------------------------------------------------
1 | # To enable ProGuard in your project, edit project.properties
2 | # to define the proguard.config property as described in that file.
3 | #
4 | # Add project specific ProGuard rules here.
5 | # By default, the flags in this file are appended to flags specified
6 | # in ${sdk.dir}/tools/proguard/proguard-android.txt
7 | # You can edit the include path and order by changing the ProGuard
8 | # include property in project.properties.
9 | #
10 | # For more details, see
11 | # http://developer.android.com/guide/developing/tools/proguard.html
12 |
13 | # Add any project specific keep options here:
14 |
15 | # If your project uses WebView with JS, uncomment the following
16 | # and specify the fully qualified class name to the JavaScript interface
17 | # class:
18 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
19 | # public *;
20 | #}
21 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | VERSION_NAME=1.0.19
2 | VERSION_CODE=20
3 | GROUP=com.mcxiaoke.volley
4 |
5 | POM_DESCRIPTION=Volley is a network library from Android source code.
6 | POM_URL=https://github.com/mcxiaoke/android-volley
7 | POM_SCM_URL=https://github.com/mcxiaoke/android-volley
8 | POM_SCM_CONNECTION=scm:git:git@github.com:mcxiaoke/android-volley.git
9 | POM_SCM_DEV_CONNECTION=scm:git:git@github.com:mcxiaoke/android-volley.git
10 | POM_LICENCE_NAME=The Apache Software License, Version 2.0
11 | POM_LICENCE_URL=http://www.apache.org/licenses/LICENSE-2.0.txt
12 | POM_LICENCE_DIST=repo
13 | POM_DEVELOPER_ID=mcxiaoke
14 | POM_DEVELOPER_NAME=Xiaoke Zhang
15 | POM_DEVELOPER_EMAIL=support@mcxiaoke.com
16 |
17 | ANDROID_BUILD_TARGET_SDK_VERSION=22
18 | ANDROID_BUILD_TOOLS_VERSION=22.0.1
19 | ANDROID_BUILD_SDK_VERSION=22
20 |
21 | POM_NAME=Android-Volley Library
22 | POM_ARTIFACT_ID=library
23 | POM_PACKAGING=aar
24 |
--------------------------------------------------------------------------------
/src/main/java/com/android/volley/TimeoutError.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.volley;
18 |
19 | /**
20 | * Indicates that the connection or the socket timed out.
21 | */
22 | @SuppressWarnings("serial")
23 | public class TimeoutError extends VolleyError { }
24 |
--------------------------------------------------------------------------------
/src/main/java/com/android/volley/ServerError.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.volley;
18 |
19 | /**
20 | * Indicates that the server responded with an error response.
21 | */
22 | @SuppressWarnings("serial")
23 | public class ServerError extends VolleyError {
24 | public ServerError(NetworkResponse networkResponse) {
25 | super(networkResponse);
26 | }
27 |
28 | public ServerError() {
29 | super();
30 | }
31 | }
32 |
33 |
--------------------------------------------------------------------------------
/src/main/java/com/android/volley/NoConnectionError.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.volley;
18 |
19 | /**
20 | * Error indicating that no connection could be established when performing a Volley request.
21 | */
22 | @SuppressWarnings("serial")
23 | public class NoConnectionError extends NetworkError {
24 | public NoConnectionError() {
25 | super();
26 | }
27 |
28 | public NoConnectionError(Throwable reason) {
29 | super(reason);
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/src/main/java/com/android/volley/ParseError.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.volley;
18 |
19 | /**
20 | * Indicates that the server's response could not be parsed.
21 | */
22 | @SuppressWarnings("serial")
23 | public class ParseError extends VolleyError {
24 | public ParseError() { }
25 |
26 | public ParseError(NetworkResponse networkResponse) {
27 | super(networkResponse);
28 | }
29 |
30 | public ParseError(Throwable cause) {
31 | super(cause);
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/Android.mk:
--------------------------------------------------------------------------------
1 | #
2 | # Copyright (C) 2011 The Android Open Source Project
3 | #
4 | # Licensed under the Apache License, Version 2.0 (the "License");
5 | # you may not use this file except in compliance with the License.
6 | # You may obtain a copy of the License at
7 | #
8 | # http://www.apache.org/licenses/LICENSE-2.0
9 | #
10 | # Unless required by applicable law or agreed to in writing, software
11 | # distributed under the License is distributed on an "AS IS" BASIS,
12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | # See the License for the specific language governing permissions and
14 | # limitations under the License.
15 | #
16 |
17 | LOCAL_PATH := $(call my-dir)
18 |
19 | include $(CLEAR_VARS)
20 |
21 | LOCAL_MODULE := volley
22 | LOCAL_SDK_VERSION := 17
23 | LOCAL_SRC_FILES := $(call all-java-files-under, src/main/java)
24 |
25 | include $(BUILD_STATIC_JAVA_LIBRARY)
26 |
27 | # Include this library in the build server's output directory
28 | # TODO: Not yet.
29 | #$(call dist-for-goals, dist_files, $(LOCAL_BUILT_MODULE):volley.jar)
30 |
31 | # Include build files in subdirectories
32 | include $(call all-makefiles-under,$(LOCAL_PATH))
33 |
34 |
--------------------------------------------------------------------------------
/src/main/java/com/android/volley/Network.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.volley;
18 |
19 | /**
20 | * An interface for performing requests.
21 | */
22 | public interface Network {
23 | /**
24 | * Performs the specified request.
25 | * @param request Request to process
26 | * @return A {@link NetworkResponse} with data and caching metadata; will never be null
27 | * @throws VolleyError on errors
28 | */
29 | public NetworkResponse performRequest(Request> request) throws VolleyError;
30 | }
31 |
--------------------------------------------------------------------------------
/src/main/java/com/android/volley/NetworkError.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.volley;
18 |
19 | /**
20 | * Indicates that there was a network error when performing a Volley request.
21 | */
22 | @SuppressWarnings("serial")
23 | public class NetworkError extends VolleyError {
24 | public NetworkError() {
25 | super();
26 | }
27 |
28 | public NetworkError(Throwable cause) {
29 | super(cause);
30 | }
31 |
32 | public NetworkError(NetworkResponse networkResponse) {
33 | super(networkResponse);
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/src/main/java/com/android/volley/toolbox/Authenticator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.volley.toolbox;
18 |
19 | import com.android.volley.AuthFailureError;
20 |
21 | /**
22 | * An interface for interacting with auth tokens.
23 | */
24 | public interface Authenticator {
25 | /**
26 | * Synchronously retrieves an auth token.
27 | *
28 | * @throws AuthFailureError If authentication did not succeed
29 | */
30 | public String getAuthToken() throws AuthFailureError;
31 |
32 | /**
33 | * Invalidates the provided auth token.
34 | */
35 | public void invalidateAuthToken(String authToken);
36 | }
37 |
--------------------------------------------------------------------------------
/src/test/java/com/android/volley/toolbox/RequestFutureTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.volley.toolbox;
18 |
19 | import com.android.volley.Request;
20 | import org.junit.Test;
21 | import org.junit.runner.RunWith;
22 | import org.robolectric.RobolectricTestRunner;
23 |
24 | import static org.junit.Assert.assertNotNull;
25 |
26 | @RunWith(RobolectricTestRunner.class)
27 | public class RequestFutureTest {
28 |
29 | @Test
30 | public void publicMethods() throws Exception {
31 | // Catch-all test to find API-breaking changes.
32 | assertNotNull(RequestFuture.class.getMethod("newFuture"));
33 | assertNotNull(RequestFuture.class.getMethod("setRequest", Request.class));
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/src/main/java/com/android/volley/ResponseDelivery.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.volley;
18 |
19 | public interface ResponseDelivery {
20 | /**
21 | * Parses a response from the network or cache and delivers it.
22 | */
23 | public void postResponse(Request> request, Response> response);
24 |
25 | /**
26 | * Parses a response from the network or cache and delivers it. The provided
27 | * Runnable will be executed after delivery.
28 | */
29 | public void postResponse(Request> request, Response> response, Runnable runnable);
30 |
31 | /**
32 | * Posts an error for the given request.
33 | */
34 | public void postError(Request> request, VolleyError error);
35 | }
36 |
--------------------------------------------------------------------------------
/src/main/java/com/android/volley/toolbox/NoCache.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.volley.toolbox;
18 |
19 | import com.android.volley.Cache;
20 |
21 | /**
22 | * A cache that doesn't.
23 | */
24 | public class NoCache implements Cache {
25 | @Override
26 | public void clear() {
27 | }
28 |
29 | @Override
30 | public Entry get(String key) {
31 | return null;
32 | }
33 |
34 | @Override
35 | public void put(String key, Entry entry) {
36 | }
37 |
38 | @Override
39 | public void invalidate(String key, boolean fullExpire) {
40 | }
41 |
42 | @Override
43 | public void remove(String key) {
44 | }
45 |
46 | @Override
47 | public void initialize() {
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/proguard.cfg:
--------------------------------------------------------------------------------
1 | -optimizationpasses 5
2 | -dontusemixedcaseclassnames
3 | -dontskipnonpubliclibraryclasses
4 | -dontpreverify
5 | -verbose
6 | -optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
7 |
8 | -keep public class * extends android.app.Activity
9 | -keep public class * extends android.app.Application
10 | -keep public class * extends android.app.Service
11 | -keep public class * extends android.content.BroadcastReceiver
12 | -keep public class * extends android.content.ContentProvider
13 | -keep public class * extends android.app.backup.BackupAgentHelper
14 | -keep public class * extends android.preference.Preference
15 | -keep public class com.android.vending.licensing.ILicensingService
16 |
17 | -keepclasseswithmembernames class * {
18 | native ;
19 | }
20 |
21 | -keepclasseswithmembers class * {
22 | public (android.content.Context, android.util.AttributeSet);
23 | }
24 |
25 | -keepclasseswithmembers class * {
26 | public (android.content.Context, android.util.AttributeSet, int);
27 | }
28 |
29 | -keepclassmembers class * extends android.app.Activity {
30 | public void *(android.view.View);
31 | }
32 |
33 | -keepclassmembers enum * {
34 | public static **[] values();
35 | public static ** valueOf(java.lang.String);
36 | }
37 |
38 | -keep class * implements android.os.Parcelable {
39 | public static final android.os.Parcelable$Creator *;
40 | }
41 |
--------------------------------------------------------------------------------
/src/main/java/com/android/volley/InternalUtils.java:
--------------------------------------------------------------------------------
1 | package com.android.volley;
2 |
3 | import java.io.UnsupportedEncodingException;
4 | import java.security.MessageDigest;
5 | import java.security.NoSuchAlgorithmException;
6 |
7 | /**
8 | * User: mcxiaoke
9 | * Date: 15/3/17
10 | * Time: 14:47
11 | */
12 | class InternalUtils {
13 |
14 | // http://stackoverflow.com/questions/9655181/convert-from-byte-array-to-hex-string-in-java
15 | private final static char[] HEX_CHARS = "0123456789ABCDEF".toCharArray();
16 |
17 | private static String convertToHex(byte[] bytes) {
18 | char[] hexChars = new char[bytes.length * 2];
19 | for (int j = 0; j < bytes.length; j++) {
20 | int v = bytes[j] & 0xFF;
21 | hexChars[j * 2] = HEX_CHARS[v >>> 4];
22 | hexChars[j * 2 + 1] = HEX_CHARS[v & 0x0F];
23 | }
24 | return new String(hexChars);
25 | }
26 |
27 | public static String sha1Hash(String text) {
28 | String hash = null;
29 | try {
30 | final MessageDigest digest = MessageDigest.getInstance("SHA-1");
31 | final byte[] bytes = text.getBytes("UTF-8");
32 | digest.update(bytes, 0, bytes.length);
33 | hash = convertToHex(digest.digest());
34 | } catch (NoSuchAlgorithmException e) {
35 | e.printStackTrace();
36 | } catch (UnsupportedEncodingException e) {
37 | e.printStackTrace();
38 | }
39 | return hash;
40 | }
41 |
42 |
43 | }
44 |
--------------------------------------------------------------------------------
/src/main/java/com/android/volley/RetryPolicy.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.volley;
18 |
19 | /**
20 | * Retry policy for a request.
21 | */
22 | public interface RetryPolicy {
23 |
24 | /**
25 | * Returns the current timeout (used for logging).
26 | */
27 | public int getCurrentTimeout();
28 |
29 | /**
30 | * Returns the current retry count (used for logging).
31 | */
32 | public int getCurrentRetryCount();
33 |
34 | /**
35 | * Prepares for the next retry by applying a backoff to the timeout.
36 | * @param error The error code of the last attempt.
37 | * @throws VolleyError In the event that the retry could not be performed (for example if we
38 | * ran out of attempts), the passed in error is thrown.
39 | */
40 | public void retry(VolleyError error) throws VolleyError;
41 | }
42 |
--------------------------------------------------------------------------------
/src/test/java/com/android/volley/utils/CacheTestUtils.java:
--------------------------------------------------------------------------------
1 | // Copyright 2011 Google Inc. All Rights Reserved.
2 |
3 | package com.android.volley.utils;
4 |
5 | import com.android.volley.Cache;
6 |
7 | import java.util.Random;
8 |
9 | public class CacheTestUtils {
10 |
11 | /**
12 | * Makes a random cache entry.
13 | * @param data Data to use, or null to use random data
14 | * @param isExpired Whether the TTLs should be set such that this entry is expired
15 | * @param needsRefresh Whether the TTLs should be set such that this entry needs refresh
16 | */
17 | public static Cache.Entry makeRandomCacheEntry(
18 | byte[] data, boolean isExpired, boolean needsRefresh) {
19 | Random random = new Random();
20 | Cache.Entry entry = new Cache.Entry();
21 | if (data != null) {
22 | entry.data = data;
23 | } else {
24 | entry.data = new byte[random.nextInt(1024)];
25 | }
26 | entry.etag = String.valueOf(random.nextLong());
27 | entry.lastModified = random.nextLong();
28 | entry.ttl = isExpired ? 0 : Long.MAX_VALUE;
29 | entry.softTtl = needsRefresh ? 0 : Long.MAX_VALUE;
30 | return entry;
31 | }
32 |
33 | /**
34 | * Like {@link #makeRandomCacheEntry(byte[], boolean, boolean)} but
35 | * defaults to an unexpired entry.
36 | */
37 | public static Cache.Entry makeRandomCacheEntry(byte[] data) {
38 | return makeRandomCacheEntry(data, false, false);
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/src/test/java/com/android/volley/toolbox/StringRequestTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.volley.toolbox;
18 |
19 | import com.android.volley.Response;
20 | import org.junit.Test;
21 | import org.junit.runner.RunWith;
22 | import org.robolectric.RobolectricTestRunner;
23 |
24 | import static org.junit.Assert.assertNotNull;
25 |
26 | @RunWith(RobolectricTestRunner.class)
27 | public class StringRequestTest {
28 |
29 | @Test
30 | public void publicMethods() throws Exception {
31 | // Catch-all test to find API-breaking changes.
32 | assertNotNull(StringRequest.class.getConstructor(String.class, Response.Listener.class,
33 | Response.ErrorListener.class));
34 | assertNotNull(StringRequest.class.getConstructor(int.class, String.class,
35 | Response.Listener.class, Response.ErrorListener.class));
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/test/java/com/android/volley/toolbox/CacheTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.volley.toolbox;
18 |
19 | import com.android.volley.Cache;
20 | import org.junit.Test;
21 | import org.junit.runner.RunWith;
22 | import org.robolectric.RobolectricTestRunner;
23 |
24 | import static org.junit.Assert.assertNotNull;
25 |
26 | @RunWith(RobolectricTestRunner.class)
27 | public class CacheTest {
28 |
29 | @Test
30 | public void publicMethods() throws Exception {
31 | // Catch-all test to find API-breaking changes.
32 | assertNotNull(Cache.class.getMethod("get", String.class));
33 | assertNotNull(Cache.class.getMethod("put", String.class, Cache.Entry.class));
34 | assertNotNull(Cache.class.getMethod("initialize"));
35 | assertNotNull(Cache.class.getMethod("invalidate", String.class, boolean.class));
36 | assertNotNull(Cache.class.getMethod("remove", String.class));
37 | assertNotNull(Cache.class.getMethod("clear"));
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/src/main/java/com/android/volley/toolbox/HttpStack.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.volley.toolbox;
18 |
19 | import com.android.volley.AuthFailureError;
20 | import com.android.volley.Request;
21 |
22 | import org.apache.http.HttpResponse;
23 |
24 | import java.io.IOException;
25 | import java.util.Map;
26 |
27 | /**
28 | * An HTTP stack abstraction.
29 | */
30 | public interface HttpStack {
31 | /**
32 | * Performs an HTTP request with the given parameters.
33 | *
34 | *
A GET request is sent if request.getPostBody() == null. A POST request is sent otherwise,
35 | * and the Content-Type header is set to request.getPostBodyContentType().
36 | *
37 | * @param request the request to perform
38 | * @param additionalHeaders additional headers to be sent together with
39 | * {@link Request#getHeaders()}
40 | * @return the HTTP response
41 | */
42 | public HttpResponse performRequest(Request> request, Map additionalHeaders)
43 | throws IOException, AuthFailureError;
44 |
45 | }
46 |
--------------------------------------------------------------------------------
/src/main/java/com/android/volley/VolleyError.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.volley;
18 |
19 | /**
20 | * Exception style class encapsulating Volley errors
21 | */
22 | @SuppressWarnings("serial")
23 | public class VolleyError extends Exception {
24 | public final NetworkResponse networkResponse;
25 | private long networkTimeMs;
26 |
27 | public VolleyError() {
28 | networkResponse = null;
29 | }
30 |
31 | public VolleyError(NetworkResponse response) {
32 | networkResponse = response;
33 | }
34 |
35 | public VolleyError(String exceptionMessage) {
36 | super(exceptionMessage);
37 | networkResponse = null;
38 | }
39 |
40 | public VolleyError(String exceptionMessage, Throwable reason) {
41 | super(exceptionMessage, reason);
42 | networkResponse = null;
43 | }
44 |
45 | public VolleyError(Throwable cause) {
46 | super(cause);
47 | networkResponse = null;
48 | }
49 |
50 | /* package */ void setNetworkTimeMs(long networkTimeMs) {
51 | this.networkTimeMs = networkTimeMs;
52 | }
53 |
54 | public long getNetworkTimeMs() {
55 | return networkTimeMs;
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/src/test/java/com/android/volley/mock/MockCache.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.volley.mock;
18 |
19 | import com.android.volley.Cache;
20 |
21 | public class MockCache implements Cache {
22 |
23 | public boolean clearCalled = false;
24 | @Override
25 | public void clear() {
26 | clearCalled = true;
27 | }
28 |
29 | public boolean getCalled = false;
30 | private Entry mFakeEntry = null;
31 |
32 | public void setEntryToReturn(Entry entry) {
33 | mFakeEntry = entry;
34 | }
35 |
36 | @Override
37 | public Entry get(String key) {
38 | getCalled = true;
39 | return mFakeEntry;
40 | }
41 |
42 | public boolean putCalled = false;
43 | public String keyPut = null;
44 | public Entry entryPut = null;
45 |
46 | @Override
47 | public void put(String key, Entry entry) {
48 | putCalled = true;
49 | keyPut = key;
50 | entryPut = entry;
51 | }
52 |
53 | @Override
54 | public void invalidate(String key, boolean fullExpire) {
55 | }
56 |
57 | @Override
58 | public void remove(String key) {
59 | }
60 |
61 | @Override
62 | public void initialize() {
63 | }
64 |
65 | }
66 |
--------------------------------------------------------------------------------
/src/test/java/com/android/volley/mock/MockResponseDelivery.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.volley.mock;
18 |
19 | import com.android.volley.Request;
20 | import com.android.volley.Response;
21 | import com.android.volley.ResponseDelivery;
22 | import com.android.volley.VolleyError;
23 |
24 | public class MockResponseDelivery implements ResponseDelivery {
25 |
26 | public boolean postResponse_called = false;
27 | public boolean postError_called = false;
28 |
29 | public boolean wasEitherResponseCalled() {
30 | return postResponse_called || postError_called;
31 | }
32 |
33 | public Response> responsePosted = null;
34 | @Override
35 | public void postResponse(Request> request, Response> response) {
36 | postResponse_called = true;
37 | responsePosted = response;
38 | }
39 |
40 | @Override
41 | public void postResponse(Request> request, Response> response, Runnable runnable) {
42 | postResponse_called = true;
43 | responsePosted = response;
44 | runnable.run();
45 | }
46 |
47 | @Override
48 | public void postError(Request> request, VolleyError error) {
49 | postError_called = true;
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/src/main/java/com/android/volley/AuthFailureError.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.volley;
18 |
19 | import android.content.Intent;
20 |
21 | /**
22 | * Error indicating that there was an authentication failure when performing a Request.
23 | */
24 | @SuppressWarnings("serial")
25 | public class AuthFailureError extends VolleyError {
26 | /** An intent that can be used to resolve this exception. (Brings up the password dialog.) */
27 | private Intent mResolutionIntent;
28 |
29 | public AuthFailureError() { }
30 |
31 | public AuthFailureError(Intent intent) {
32 | mResolutionIntent = intent;
33 | }
34 |
35 | public AuthFailureError(NetworkResponse response) {
36 | super(response);
37 | }
38 |
39 | public AuthFailureError(String message) {
40 | super(message);
41 | }
42 |
43 | public AuthFailureError(String message, Exception reason) {
44 | super(message, reason);
45 | }
46 |
47 | public Intent getResolutionIntent() {
48 | return mResolutionIntent;
49 | }
50 |
51 | @Override
52 | public String getMessage() {
53 | if (mResolutionIntent != null) {
54 | return "User needs to (re)enter credentials.";
55 | }
56 | return super.getMessage();
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/src/test/java/com/android/volley/mock/MockNetwork.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.volley.mock;
18 |
19 | import com.android.volley.Network;
20 | import com.android.volley.NetworkResponse;
21 | import com.android.volley.Request;
22 | import com.android.volley.ServerError;
23 | import com.android.volley.VolleyError;
24 |
25 | public class MockNetwork implements Network {
26 | public final static int ALWAYS_THROW_EXCEPTIONS = -1;
27 |
28 | private int mNumExceptionsToThrow = 0;
29 | private byte[] mDataToReturn = null;
30 |
31 | /**
32 | * @param numExceptionsToThrow number of times to throw an exception or
33 | * {@link #ALWAYS_THROW_EXCEPTIONS}
34 | */
35 | public void setNumExceptionsToThrow(int numExceptionsToThrow) {
36 | mNumExceptionsToThrow = numExceptionsToThrow;
37 | }
38 |
39 | public void setDataToReturn(byte[] data) {
40 | mDataToReturn = data;
41 | }
42 |
43 | public Request> requestHandled = null;
44 |
45 | @Override
46 | public NetworkResponse performRequest(Request> request) throws VolleyError {
47 | if (mNumExceptionsToThrow > 0 || mNumExceptionsToThrow == ALWAYS_THROW_EXCEPTIONS) {
48 | if (mNumExceptionsToThrow != ALWAYS_THROW_EXCEPTIONS) {
49 | mNumExceptionsToThrow--;
50 | }
51 | throw new ServerError();
52 | }
53 |
54 | requestHandled = request;
55 | return new NetworkResponse(mDataToReturn);
56 | }
57 |
58 | }
59 |
--------------------------------------------------------------------------------
/src/test/java/com/android/volley/toolbox/RequestQueueTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.volley.toolbox;
18 |
19 | import com.android.volley.*;
20 | import org.junit.Test;
21 | import org.junit.runner.RunWith;
22 | import org.robolectric.RobolectricTestRunner;
23 |
24 | import static org.junit.Assert.assertNotNull;
25 |
26 | @RunWith(RobolectricTestRunner.class)
27 | public class RequestQueueTest {
28 |
29 | @Test
30 | public void publicMethods() throws Exception {
31 | // Catch-all test to find API-breaking changes.
32 | assertNotNull(RequestQueue.class.getConstructor(Cache.class, Network.class, int.class,
33 | ResponseDelivery.class));
34 | assertNotNull(RequestQueue.class.getConstructor(Cache.class, Network.class, int.class));
35 | assertNotNull(RequestQueue.class.getConstructor(Cache.class, Network.class));
36 |
37 | assertNotNull(RequestQueue.class.getMethod("start"));
38 | assertNotNull(RequestQueue.class.getMethod("stop"));
39 | assertNotNull(RequestQueue.class.getMethod("getSequenceNumber"));
40 | assertNotNull(RequestQueue.class.getMethod("getCache"));
41 | assertNotNull(RequestQueue.class.getMethod("cancelAll", RequestQueue.RequestFilter.class));
42 | assertNotNull(RequestQueue.class.getMethod("cancelAll", Object.class));
43 | assertNotNull(RequestQueue.class.getMethod("add", Request.class));
44 | assertNotNull(RequestQueue.class.getDeclaredMethod("finish", Request.class));
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ## DEPRECATED
2 |
3 | ### Please note, this project is deprecated and no longer being maintained, please use official version [volley](https://github.com/google/volley).
4 |
5 | ----------
6 |
7 | # Intro
8 |
9 | This is an unofficial mirror (with some minor bugfix) for [volley](https://android.googlesource.com/platform/frameworks/volley).
10 |
11 | * [](http://search.maven.org/#artifactdetails%7Ccom.mcxiaoke.volley%7Clibrary%7C1.0.19%7Cjar)
12 |
13 | ## Gradle
14 |
15 | ``` groovy
16 | compile 'com.mcxiaoke.volley:library:1.0.19'
17 | ```
18 |
19 | ## Contacts
20 |
21 | * Blog:
22 | * Github:
23 | * Email: [github@mcxiaoke.com](mailto:github@mcxiaoke.com)
24 |
25 | ## Projects
26 |
27 | * Awesome-Kotlin:
28 | * Kotlin-Koi:
29 | * Android-Next:
30 | * Packer-Ng:
31 | * Gradle-Packer:
32 | * xBus:
33 | * RxJava Docs:
34 | * MQTT-CN:
35 | * Minicat App:
36 | * Fanfou App:
37 |
38 | ## License
39 |
40 |
41 | Copyright (C) 2014,2015,2016 Xiaoke Zhang
42 | Copyright (C) 2011 The Android Open Source Project
43 |
44 | Licensed under the Apache License, Version 2.0 (the "License");
45 | you may not use this file except in compliance with the License.
46 | You may obtain a copy of the License at
47 |
48 | http://www.apache.org/licenses/LICENSE-2.0
49 |
50 | Unless required by applicable law or agreed to in writing, software
51 | distributed under the License is distributed on an "AS IS" BASIS,
52 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
53 | See the License for the specific language governing permissions and
54 | limitations under the License.
55 |
56 |
--------------------------------------------------------------------------------
/src/test/java/com/android/volley/mock/MockHttpURLConnection.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.volley.mock;
18 |
19 | import java.io.ByteArrayOutputStream;
20 | import java.io.IOException;
21 | import java.io.OutputStream;
22 | import java.net.HttpURLConnection;
23 | import java.net.MalformedURLException;
24 | import java.net.URL;
25 |
26 | public class MockHttpURLConnection extends HttpURLConnection {
27 |
28 | private boolean mDoOutput;
29 | private String mRequestMethod;
30 | private OutputStream mOutputStream;
31 |
32 | public MockHttpURLConnection() throws MalformedURLException {
33 | super(new URL("http://foo.com"));
34 | mDoOutput = false;
35 | mRequestMethod = "GET";
36 | mOutputStream = new ByteArrayOutputStream();
37 | }
38 |
39 | @Override
40 | public void setDoOutput(boolean flag) {
41 | mDoOutput = flag;
42 | }
43 |
44 | @Override
45 | public boolean getDoOutput() {
46 | return mDoOutput;
47 | }
48 |
49 | @Override
50 | public void setRequestMethod(String method) {
51 | mRequestMethod = method;
52 | }
53 |
54 | @Override
55 | public String getRequestMethod() {
56 | return mRequestMethod;
57 | }
58 |
59 | @Override
60 | public OutputStream getOutputStream() {
61 | return mOutputStream;
62 | }
63 |
64 | @Override
65 | public void disconnect() {
66 | }
67 |
68 | @Override
69 | public boolean usingProxy() {
70 | return false;
71 | }
72 |
73 | @Override
74 | public void connect() throws IOException {
75 | }
76 |
77 | }
78 |
--------------------------------------------------------------------------------
/src/test/java/com/android/volley/toolbox/ResponseTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.volley.toolbox;
18 |
19 | import com.android.volley.Cache;
20 | import com.android.volley.NetworkResponse;
21 | import com.android.volley.Response;
22 | import com.android.volley.VolleyError;
23 | import org.junit.Test;
24 | import org.junit.runner.RunWith;
25 | import org.robolectric.RobolectricTestRunner;
26 |
27 | import java.util.Map;
28 |
29 | import static org.junit.Assert.assertNotNull;
30 |
31 | @RunWith(RobolectricTestRunner.class)
32 | public class ResponseTest {
33 |
34 | @Test
35 | public void publicMethods() throws Exception {
36 | // Catch-all test to find API-breaking changes.
37 | assertNotNull(Response.class.getMethod("success", Object.class, Cache.Entry.class));
38 | assertNotNull(Response.class.getMethod("error", VolleyError.class));
39 | assertNotNull(Response.class.getMethod("isSuccess"));
40 |
41 | assertNotNull(Response.Listener.class.getDeclaredMethod("onResponse", Object.class));
42 |
43 | assertNotNull(Response.ErrorListener.class.getDeclaredMethod("onErrorResponse",
44 | VolleyError.class));
45 |
46 | assertNotNull(NetworkResponse.class.getConstructor(int.class, byte[].class, Map.class,
47 | boolean.class, long.class));
48 | assertNotNull(NetworkResponse.class.getConstructor(int.class, byte[].class, Map.class,
49 | boolean.class));
50 | assertNotNull(NetworkResponse.class.getConstructor(byte[].class));
51 | assertNotNull(NetworkResponse.class.getConstructor(byte[].class, Map.class));
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/src/test/java/com/android/volley/toolbox/JsonRequestTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.volley.toolbox;
18 |
19 | import com.android.volley.Response;
20 | import org.json.JSONArray;
21 | import org.json.JSONObject;
22 | import org.junit.Test;
23 | import org.junit.runner.RunWith;
24 | import org.robolectric.RobolectricTestRunner;
25 |
26 | import static org.junit.Assert.assertNotNull;
27 |
28 | @RunWith(RobolectricTestRunner.class)
29 | public class JsonRequestTest {
30 |
31 | @Test
32 | public void publicMethods() throws Exception {
33 | // Catch-all test to find API-breaking changes.
34 | assertNotNull(JsonRequest.class.getConstructor(String.class, String.class,
35 | Response.Listener.class, Response.ErrorListener.class));
36 | assertNotNull(JsonRequest.class.getConstructor(int.class, String.class, String.class,
37 | Response.Listener.class, Response.ErrorListener.class));
38 |
39 | assertNotNull(JsonArrayRequest.class.getConstructor(String.class,
40 | Response.Listener.class, Response.ErrorListener.class));
41 | assertNotNull(JsonArrayRequest.class.getConstructor(int.class, String.class, JSONArray.class,
42 | Response.Listener.class, Response.ErrorListener.class));
43 |
44 | assertNotNull(JsonObjectRequest.class.getConstructor(String.class, JSONObject.class,
45 | Response.Listener.class, Response.ErrorListener.class));
46 | assertNotNull(JsonObjectRequest.class.getConstructor(int.class, String.class,
47 | JSONObject.class, Response.Listener.class, Response.ErrorListener.class));
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/src/main/java/com/android/volley/toolbox/ClearCacheRequest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.volley.toolbox;
18 |
19 | import com.android.volley.Cache;
20 | import com.android.volley.NetworkResponse;
21 | import com.android.volley.Request;
22 | import com.android.volley.Response;
23 |
24 | import android.os.Handler;
25 | import android.os.Looper;
26 |
27 | /**
28 | * A synthetic request used for clearing the cache.
29 | */
30 | public class ClearCacheRequest extends Request