kandi background
Explore Kits

NoHttp | Android实现Http标准协议框架,支持多种缓存模式,底层可动态切换OkHttp、URLConnection。 | REST library

 by   yanzhenjie Java Version: Current License: Apache-2.0

 by   yanzhenjie Java Version: Current License: Apache-2.0

Download this library from

kandi X-RAY | NoHttp Summary

NoHttp is a Java library typically used in Web Services, REST applications. NoHttp has no bugs, it has no vulnerabilities, it has build file available, it has a Permissive License and it has medium support. You can download it from GitHub, Maven.
:lemon: Android实现Http标准协议框架,支持多种缓存模式,底层可动态切换OkHttp、URLConnection。
Support
Support
Quality
Quality
Security
Security
License
License
Reuse
Reuse

kandi-support Support

  • NoHttp has a medium active ecosystem.
  • It has 3708 star(s) with 875 fork(s). There are 196 watchers for this library.
  • It had no major release in the last 12 months.
  • There are 75 open issues and 153 have been closed. On average issues are closed in 17 days. There are no pull requests.
  • It has a neutral sentiment in the developer community.
  • The latest version of NoHttp is current.
NoHttp Support
Best in #REST
Average in #REST
NoHttp Support
Best in #REST
Average in #REST

quality kandi Quality

  • NoHttp has 0 bugs and 0 code smells.
NoHttp Quality
Best in #REST
Average in #REST
NoHttp Quality
Best in #REST
Average in #REST

securitySecurity

  • NoHttp has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
  • NoHttp code analysis shows 0 unresolved vulnerabilities.
  • There are 0 security hotspots that need review.
NoHttp Security
Best in #REST
Average in #REST
NoHttp Security
Best in #REST
Average in #REST

license License

  • NoHttp is licensed under the Apache-2.0 License. This license is Permissive.
  • Permissive licenses have the least restrictions, and you can use them in most projects.
NoHttp License
Best in #REST
Average in #REST
NoHttp License
Best in #REST
Average in #REST

buildReuse

  • NoHttp releases are not available. You will need to build from source code and install.
  • Deployable package is available in Maven.
  • Build file is available. You can build the component from source.
  • Installation instructions are not available. Examples and code snippets are available.
NoHttp Reuse
Best in #REST
Average in #REST
NoHttp Reuse
Best in #REST
Average in #REST
Top functions reviewed by kandi - BETA

kandi has reviewed NoHttp and discovered the below as its top functions. This is intended to give you an instant insight into NoHttp implemented functionality, and help decide if they suit your requirements.

  • Execute the given request
  • Get the protocol for the cache or network mode .
  • Executes the upload .
  • Get the value associated with the given key .
  • Try to download the app .
  • Creates a connection to the specified URL .
  • Writes data to the specified output stream .
  • Calculate the dimensions of a rectangle that should be scaled .
  • Get the local expiration time from the cache .
  • Creates a new instance of the URL .

NoHttp Key Features

:lemon: Android实现Http标准协议框架,支持多种缓存模式,底层可动态切换OkHttp、URLConnection。

添加依赖

copy iconCopydownload iconDownload
implementation 'com.yanzhenjie.nohttp:nohttp:1.1.11'

一般初始化

copy iconCopydownload iconDownload
NoHttp.initialize(this);

高级初始化

copy iconCopydownload iconDownload
InitializationConfig config = InitializationConfig.newBuilder(context)
    // 其它配置。
    ...
    .build();

NoHttp.initialize(config);

需要的权限

copy iconCopydownload iconDownload
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />

调试模式

copy iconCopydownload iconDownload
Logger.setDebug(true);// 开启NoHttp的调试模式, 配置后可看到请求过程、日志和错误信息。
Logger.setTag("NoHttpSample");// 打印Log的tag。

第三方异步框架

copy iconCopydownload iconDownload
StringRequest request = new String(url, RequestMethod.GET);
Response<String> response = SyncRequestExecutor.INSTANCE.execute(request);
if (response.isSucceed()) {
    // 请求成功。
} else {
    // 请求失败,拿到错误:
    Exception e = response.getException();
}

同步请求

copy iconCopydownload iconDownload
StringRequest req = new String("http://api.nohttp.net", RequestMethod.POST);
Response<String> response = SyncRequestExecutor.INSTANCE.execute(req);
if (response.isSucceed()) {
    // 请求成功。
} else {
    // 请求失败,拿到错误:
    Exception e = response.getException();
}

异步请求-AsyncRequestExecutor

copy iconCopydownload iconDownload
StringRequest request = new StringRequest("http://api.nohttp.net");
Cancelable cancel = AsyncRequestExecutor.INSTANCE.execute(0, request, new SimpleResponseListener<String>() {
    @Override
    public void onSucceed(int what, Response<String> response) {
        // 请求成功。
    }

    @Override
    public void onFailed(int what, Response<String> response) {
        // 请求失败。
    }
});

// 如果想取消请求:
cancel.cancel();

// 判断是否取消:
boolean isCancelled = cancel.isCancelled();

异步请求-RequestQueue

copy iconCopydownload iconDownload
RequestQueue queue = NoHttp.newRequestQueue(); // 默认三个并发,此处可以传入并发数量。

...
// 发起请求:
queue.add(what, request, listener);

...
// 使用完后需要关闭队列释放CPU:
queue.stop();

队列的正确用法

copy iconCopydownload iconDownload
public class BaseActivity extends Activity {

    private RequestQueue queue;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        queue = NoHttp.newRequestQueue();
    }
    
    // 提供给子类请求使用。
    public <T> void request(int what, Request<T> request, SimpleResponseListener<T> listener) {
        queue.add(what, request, listener);
    }

    @Override
    public void onDestory() {
        queue.stop();
    }

}

请求不同数据的几种Request

copy iconCopydownload iconDownload
// 请求String:
StringRequest request = new StringRequest(url, method);

// 请求Bitmap:
ImageRequest request = new ImageRequest(url, method);

// 请求JSONObject:
JsonObjectRequest request = new JsonObjectRequest(url, method);

// 请求JSONArray:
JsonArrayRequest request = new JsonArrayRequest(url, method);

拼装URL

copy iconCopydownload iconDownload
http://api.nohttp.net/rest/<userid>/userinfo

添加请求头

copy iconCopydownload iconDownload
StringRequest request = new StringRequest(url, RequestMethod.POST);
   .addHeader("name", "yanzhenjie") // String类型。
   .addHeader("age", "18") // int类型。
   .setHeader("sex", "男") // setHeader将会覆盖已经存在的key。
   ...

添加参数

copy iconCopydownload iconDownload
StringRequest request = new StringRequest(url, RequestMethod.POST);
   .add("name", "严振杰") // String类型
   .add("age", 18) // int类型
   .add("age", "20") // add方法不会覆盖已经存在key,所以age将会有两个值:18, 20。
   .set("sex", "女") // set会覆盖已存在的key。
   .set("sex", "男") // 比如最终sex就只有一个值:男。

    // 添加File
   .add("head", file)
   .add("head", new FileBinary(file))
   // 添加Bitmap
   .add("head", new BitmapBinary(bitmap))
   // 添加ByteArray
   .add("head", new ByteArrayBinary(byte[]))
   // 添加InputStream
   .add("head", new InputStreamBinary(inputStream));

提交请求包体

copy iconCopydownload iconDownload
// 提交普通String
request.setDefineRequestBody(String, ContentType);

// 提交json字符串
request.setDefineRequestBodyForJson(JsonString)

// 提交jsonObject对象,其实还是json字符串
request.setDefineRequestBodyForJson(JSONObject)

// 提交xml字符串
request.setDefineRequestBodyForXML(XmlString)

// 提交字体Body,比如File(这跟表单上传不一样的),可以转为InputStream来提交
request.setDefineRequestBody(InputStream, ContentType)

五大缓存模式

copy iconCopydownload iconDownload
StringRequest request = new StringRequest(url, method);
request.setCacheMode(CacheMode.DEFAULT);

自定义请求

copy iconCopydownload iconDownload
public class FastJsonRequest extends RestRequestor<JSONObject> {

    public FastJsonRequest(String url) {
	    this(url, RequestMethod.GET);
    }

    public FastJsonRequest(String url, RequestMethod requestMethod) {
	    super(url, requestMethod);
    }

    @Override
    public JSONObject parseResponse(Headers header, byte[] body) throws Throwable {
	    String result = StringRequest.parseResponseString(headers, body);
	    return JSON.parseObject(result);
    }
}

同步下载-SyncDownloadExecutor

copy iconCopydownload iconDownload
DownloadRequest request = new DownloadRequest(url, RequestMethod.GET, fileFolder, true, true);
    SyncDownloadExecutor.INSTANCE.execute(0, request, new SimpleDownloadListener() {
        @Override
        public void onStart(int what, boolean resume, long range, Headers headers, long size) {
            // 开始下载,回调的时候说明文件开始下载了。
            // 参数1:what。
            // 参数2:是否是断点续传,从中间开始下载的。
            // 参数3:如果是断点续传,这个参数非0,表示之前已经下载的文件大小。
            // 参数4:服务器响应头。
            // 参数5:文件总大小,可能为0,因为服务器可能不返回文件大小。
        }

        @Override
        public void onProgress(int what, int progress, long fileCount, long speed) {
            // 进度发生变化,服务器不返回文件总大小时不回调,因为没法计算进度。
            // 参数1:what。
            // 参数2:进度,[0-100]。
            // 参数3:文件总大小,可能为0,因为服务器可能不返回文件大小。
            // 参数4:下载的速度,含义为1S下载的byte大小,计算下载速度时:
            //        int xKB = (int) speed / 1024; // 单位:xKB/S
            //        int xM = (int) speed / 1024 / 1024; // 单位:xM/S
        }

        @Override
        public void onFinish(int what, String filePath) {
            // 下载完成,参数2为保存在本地的文件路径。
        }
});

异步下载-DownloadQueue

copy iconCopydownload iconDownload
DownloadQueue queue = NoHttp.newDownloadQueue(); // 默认三个并发,此处可以传入并发数量。

...
// 发起下载请求:
queue.add(what, request, listener);

...
// 使用完后需要关闭队列释放CPU:
queue.stop();

方式一:指定文件名

copy iconCopydownload iconDownload
DownloadRequest req = new DownloadRequest(url, method, folder, filename, range, deleteOld);
// 参数1,文件的url。
// 参数2,请求方法,一般为GET。
// 参数3,要保存的文件名路径,须是绝对路径。
// 参数4,文件最终的文件名,最终会用这个文件命名下载好的文件。
// 参数5,是否断点续传,比如之前已经下载了50%,是否继续从50%处开始下载,否则从0开始下载。
// 参数6,下载前检测到已存在你指定的相同文件名的文件时,是否删除重新下载,否则直接回调下载成功。

方式一:不指定文件名

copy iconCopydownload iconDownload
DownloadRequest req = new DownloadRequest(url, method, folder, range, deleteOld);
// 参数含义同上。

Nohttp暂停下载继续下载原理介绍

copy iconCopydownload iconDownload
DownloadRequest request;
String url = "http://...";

// 开始或者继续一个下载。
public void startDownload() {
    if(request != null)
        request = new DownloadRequest(url, RequestMethod.GET, "/sdcard/", "xx.apk", true, true);
    // 注意第5个参数,true表示断点续传。
}

// 暂停或者取消一个下载。
public void stopDownload() {
    if(downloadRequest != null)
        downloadRequest.cancel();
}

代码混淆

copy iconCopydownload iconDownload
-keepclassmembers class ** {
    private javax.net.ssl.SSLSocketFactory delegate;
}

License

copy iconCopydownload iconDownload
Copyright 2015 Yan Zhenjie

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Google Cloud Spring Boot InvocationTargetException

copy iconCopydownload iconDownload
<configuration>
  <archive>
    <manifest>
       <addClasspath>true</addClasspath>
       <classpathPrefix>lib/</classpathPrefix>
       <mainClass>samuelb.capripol.CapripolApplication</mainClass>
    </manifest>
  </archive>
</configuration>
gcloud app instances ssh --service=s1 --version=v1 i1 --container=gaeapp
-----------------------
<configuration>
  <archive>
    <manifest>
       <addClasspath>true</addClasspath>
       <classpathPrefix>lib/</classpathPrefix>
       <mainClass>samuelb.capripol.CapripolApplication</mainClass>
    </manifest>
  </archive>
</configuration>
gcloud app instances ssh --service=s1 --version=v1 i1 --container=gaeapp

How does Gradle resolve plugins not listed in the Gradle Plugin Portal?

copy iconCopydownload iconDownload
gradlePlugin {
    plugins {
        sagan {
            id = "org.springframework.security.sagan"
            implementationClass = "org.springframework.gradle.sagan.SaganPlugin"
        }
    }
}

How to install the snapshot jar by Gradle?

copy iconCopydownload iconDownload
dependencies {
    compile 'org.springframework.security.experimental:spring-security-oauth2-authorization-server:0.1.0-SNAPSHOT'
}

repositories {
    maven { url 'https://repo.spring.io/snapshot' }
}

Gitlab CI failure with JHipster

copy iconCopydownload iconDownload
if (project.hasProperty("nodeInstall")) {
    node {
        version = "${node_version}"
        npmVersion = "${npm_version}"
        yarnVersion = "${yarn_version}"
        download = true
    }
}

Community Discussions

Trending Discussions on NoHttp
  • AppCompleteGenericCore &gt; 1Gb of memory
  • Google Cloud Spring Boot InvocationTargetException
  • How does Gradle resolve plugins not listed in the Gradle Plugin Portal?
  • How to install the snapshot jar by Gradle?
  • Gitlab CI failure with JHipster
Trending Discussions on NoHttp

QUESTION

AppCompleteGenericCore &gt; 1Gb of memory

Asked 2021-Nov-07 at 00:11

The monitoring of the Local MDrivenServer (cmd: AppCompleteGenericCore.exe -port=5050 -nohttps) shows that the process eats memory up to 1.2Gb regardless of the Model's size.
If I upload the simplest sample model with Class1 and Class2, no viewmodels, no serverside jobs - AppCompleteGenericCore process memory starts from 60Mb (there is no model) and stabilized at the ~1.2Gb (sample model is uploaded). Could you please advise is it normal behavior? FYI, I've tried "System.GC.Server": false, "System.GC.Concurrent": false in the AppCompleteGenericCore.runtimeconfig.json - no results.

Thank you!

ANSWER

Answered 2021-Nov-07 at 00:11

I deleted my LocalServers folder and downloaded the latest version of MDrivenServer—and the problem disappeared. The old server had CodeDress assembly, so I guess it was a root cause of the memory leak I had.

Source https://stackoverflow.com/questions/69846204

Community Discussions, Code Snippets contain sources that include Stack Exchange Network

Vulnerabilities

No vulnerabilities reported

Install NoHttp

You can download it from GitHub, Maven.
You can use NoHttp like any standard Java library. Please include the the jar files in your classpath. You can also use any IDE and you can run and debug the NoHttp component as you would do with any other Java program. Best practice is to use a build tool that supports dependency management such as Maven or Gradle. For Maven installation, please refer maven.apache.org. For Gradle installation, please refer gradle.org .

Support

For any new features, suggestions and bugs create an issue on GitHub. If you have any questions check and ask questions on community page Stack Overflow .

DOWNLOAD this Library from

Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from
over 430 million Knowledge Items
Find more libraries
Reuse Solution Kits and Libraries Curated by Popular Use Cases

Save this library and start creating your kit

Explore Related Topics

Share this Page

share link
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from
over 430 million Knowledge Items
Find more libraries
Reuse Solution Kits and Libraries Curated by Popular Use Cases

Save this library and start creating your kit

  • © 2022 Open Weaver Inc.