Java源码示例:org.chromium.net.CronetEngine
示例1
private static synchronized CronetEngine getCronetEngine(Context context) {
// Lazily create the Cronet engine.
if (cronetEngine == null) {
CronetEngine.Builder myBuilder = new CronetEngine.Builder(context);
// Enable caching of HTTP data and
// other information like QUIC server information, HTTP/2 protocol and QUIC protocol.
cronetEngine = myBuilder
.enableHttpCache(CronetEngine.Builder.HTTP_CACHE_DISABLED, 100 * 1024)
//.addQuicHint("stgwhttps.kof.qq.com", 443, 443)
.enableHttp2(true)
//.enableQuic(true)
.build();
// .setUserAgent("clb_quic_demo")
}
return cronetEngine;
}
示例2
private static synchronized CronetEngine getCronetEngine(Context context) {
// Lazily create the Cronet engine.
if (cronetEngine == null) {
CronetEngine.Builder myBuilder = new CronetEngine.Builder(context);
// Enable caching of HTTP data and
// other information like QUIC server information, HTTP/2 protocol and QUIC protocol.
cronetEngine = myBuilder
.enableHttpCache(CronetEngine.Builder.HTTP_CACHE_DISABLED, 100 * 1024)
.addQuicHint("stgwhttps.kof.qq.com", 443, 443)
//.enableHttp2(true)
.enableQuic(true)
.build();
// .setUserAgent("clb_quic_demo")
}
return cronetEngine;
}
示例3
/**
* Performs a request to a Google Cloud Function that translates speech messages. Returns a JSON
* string with information about the response. The response includes information about the audio
* files that the client can download at a different time.
* @param context The application context
* @param base64EncodedAudioMessage The base64-encoded audio message
* @param sampleRateInHertz The sample rate in hertz
* @param translationListener The callback to deliver the results to.
*/
public void translateAudioMessage(Context context, CronetEngine cronetEngine,
String base64EncodedAudioMessage, int sampleRateInHertz,
SpeechTranslationListener translationListener) {
// [START json_request_body]
JSONObject requestBody = new JSONObject();
try {
requestBody.put("encoding", SPEECH_TRANSLATE_ENCODING);
requestBody.put("sampleRateHertz", sampleRateInHertz);
requestBody.put("languageCode", context.getResources().getConfiguration().getLocales().get(0));
requestBody.put("audioContent", base64EncodedAudioMessage);
} catch(JSONException e) {
Log.e(TAG, e.getLocalizedMessage());
translationListener.onTranslationFailed(e);
}
// [END json_request_body]
byte[] requestBodyBytes = requestBody.toString().getBytes();
UrlRequest request = buildSpeechTranslationRequest(context, cronetEngine, requestBodyBytes, translationListener);
request.start();
}
示例4
@Before
public void readSpeechRecording16khzb64File() throws IOException {
String file = "assets/speech-recording-16khz.b64";
InputStream in = this.getClass().getClassLoader().getResourceAsStream(file);
InputStreamReader inputStreamReader = new InputStreamReader(in);
BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
StringBuilder stringBuilder = new StringBuilder();
String line;
while((line = bufferedReader.readLine()) != null) {
stringBuilder.append(line);
}
base64EncodedAudioMessage = stringBuilder.toString();
context = InstrumentationRegistry.getInstrumentation().getTargetContext();
CronetEngine.Builder myBuilder = new CronetEngine.Builder(context);
cronetEngine = myBuilder.build();
}
示例5
TaggingStreamFactory(
CronetEngine cronetEngine,
boolean trafficStatsTagSet,
int trafficStatsTag,
boolean trafficStatsUidSet,
int trafficStatsUid) {
this.cronetEngine = cronetEngine;
this.trafficStatsTagSet = trafficStatsTagSet;
this.trafficStatsTag = trafficStatsTag;
this.trafficStatsUidSet = trafficStatsUidSet;
this.trafficStatsUid = trafficStatsUid;
}
示例6
public CronetHttpURLConnection(URL url, CronetEngine cronetEngine) {
super(url);
mCronetEngine = cronetEngine;
mMessageLoop = new MessageLoop();
mInputStream = new CronetInputStream(this);
mRequestHeaders = new ArrayList<Pair<String, String>>();
}
示例7
@Override
public CronetEngineBuilderImpl setLibraryLoader(CronetEngine.Builder.LibraryLoader loader) {
// |CronetEngineBuilderImpl| is an abstract class that is used by concrete builder
// implementations, including the Java Cronet engine builder; therefore, the implementation
// of this method should be "no-op". Subclasses that care about the library loader
// should override this method.
return this;
}
示例8
private static synchronized CronetEngine getCronetEngine(Context context) {
// Lazily create the Cronet engine.
if (cronetEngine == null) {
CronetEngine.Builder myBuilder = new CronetEngine.Builder(context);
// Enable caching of HTTP data and
// other information like QUIC server information, HTTP/2 protocol and QUIC protocol.
cronetEngine = myBuilder
.enableHttpCache(CronetEngine.Builder.HTTP_CACHE_IN_MEMORY, 100 * 1024)
.enableHttp2(true)
.enableQuic(true)
.build();
}
return cronetEngine;
}
示例9
/**
* Creates an instance of the CronetEngine class.
* Instances of CronetEngine require a lot of resources. Additionally, their creation is slow
* and expensive. It's recommended to delay the creation of CronetEngine instances until they
* are required and reuse them as much as possible.
* @return An instance of CronetEngine.
*/
private synchronized CronetEngine getCronetEngine() {
if(cronetEngine == null) {
CronetEngine.Builder myBuilder = new CronetEngine.Builder(this);
cronetEngine = myBuilder.build();
}
return cronetEngine;
}
示例10
TaggingStreamFactory(
CronetEngine cronetEngine,
boolean trafficStatsTagSet,
int trafficStatsTag,
boolean trafficStatsUidSet,
int trafficStatsUid) {
this.cronetEngine = cronetEngine;
this.trafficStatsTagSet = trafficStatsTagSet;
this.trafficStatsTag = trafficStatsTag;
this.trafficStatsUidSet = trafficStatsUidSet;
this.trafficStatsUid = trafficStatsUid;
}
示例11
/** Creates a new builder for the given server host, port and CronetEngine. */
public static CronetChannelBuilder forAddress(String host, int port, CronetEngine cronetEngine) {
Preconditions.checkNotNull(cronetEngine, "cronetEngine");
return new CronetChannelBuilder(host, port, cronetEngine);
}
示例12
private CronetChannelBuilder(String host, int port, CronetEngine cronetEngine) {
super(
InetSocketAddress.createUnresolved(host, port),
GrpcUtil.authorityFromHostAndPort(host, port));
this.cronetEngine = Preconditions.checkNotNull(cronetEngine, "cronetEngine");
}
示例13
@Override
public CronetEngine.Builder createBuilder() {
ICronetEngineBuilder impl = new NativeCronetEngineBuilderWithLibraryLoaderImpl(mContext);
return new ExperimentalCronetEngine.Builder(impl);
}
示例14
@Override
public CronetEngine.Builder createBuilder() {
ICronetEngineBuilder impl = new JavaCronetEngineBuilderImpl(mContext);
return new ExperimentalCronetEngine.Builder(impl);
}
示例15
public LibraryLoader(CronetEngine.Builder.LibraryLoader libraryLoader) {
mWrappedLoader = libraryLoader;
}
示例16
/** Creates a new builder for the given server host, port and CronetEngine. */
public static CronetChannelBuilder forAddress(String host, int port, CronetEngine cronetEngine) {
Preconditions.checkNotNull(cronetEngine, "cronetEngine");
return new CronetChannelBuilder(host, port, cronetEngine);
}
示例17
private CronetChannelBuilder(String host, int port, CronetEngine cronetEngine) {
super(
InetSocketAddress.createUnresolved(host, port),
GrpcUtil.authorityFromHostAndPort(host, port));
this.cronetEngine = Preconditions.checkNotNull(cronetEngine, "cronetEngine");
}