APIdia Launch Partner
Top Description Inners Fields Constructors Methods
com.badlogic.gdx.net

public Class NetJavaImpl

extends Object
Class Inheritance
Imports
java.io.IOException, .InputStream, .OutputStream, .OutputStreamWriter, java.net.HttpURLConnection, .URL, java.util.List, .Map, java.util.concurrent.atomic.AtomicInteger, java.util.concurrent.Future, .LinkedBlockingQueue, .SynchronousQueue, .ThreadFactory, .ThreadPoolExecutor, .TimeUnit, com.badlogic.gdx.Net, .Net.HttpMethods, .Net.HttpRequest, .Net.HttpResponse, .Net.HttpResponseListener, com.badlogic.gdx.utils.GdxRuntimeException, .ObjectMap, .StreamUtils

Implements part of the Net API using HttpURLConnection, to be easily reused between the Android and Desktop backends.
Author
acoppes

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class

Field Summary

Modifier and TypeField and Description
pack-priv final ObjectMap<Net.HttpRequest, HttpURLConnection>
private final ThreadPoolExecutor
pack-priv final ObjectMap<Net.HttpRequest, Net.HttpResponseListener>
pack-priv final ObjectMap<Net.HttpRequest, Future<?>>

Constructor Summary

AccessConstructor and Description
public
public
NetJavaImpl(int maxThreads)

Method Summary

Modifier and TypeMethod and Description
public void
private void
cancelTask(Net.HttpRequest httpRequest)

pack-priv synchronized Net.HttpResponseListener
public boolean
pack-priv synchronized void
putIntoConnectionsAndListeners(final Net.HttpRequest httpRequest, final Net.HttpResponseListener httpResponseListener, final HttpURLConnection connection)

pack-priv synchronized void
public void
sendHttpRequest(final Net.HttpRequest httpRequest, final Net.HttpResponseListener httpResponseListener)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

connectionsback to summary
pack-priv final ObjectMap<Net.HttpRequest, HttpURLConnection> connections
executorServiceback to summary
private final ThreadPoolExecutor executorService
listenersback to summary
pack-priv final ObjectMap<Net.HttpRequest, Net.HttpResponseListener> listeners
tasksback to summary
pack-priv final ObjectMap<Net.HttpRequest, Future<?>> tasks

Constructor Detail

NetJavaImplback to summary
public NetJavaImpl()
NetJavaImplback to summary
public NetJavaImpl(int maxThreads)

Method Detail

cancelHttpRequestback to summary
public void cancelHttpRequest(Net.HttpRequest httpRequest)
cancelTaskback to summary
private void cancelTask(Net.HttpRequest httpRequest)
getFromListenersback to summary
pack-priv synchronized Net.HttpResponseListener getFromListeners(Net.HttpRequest httpRequest)
isHttpRequestPendingback to summary
public boolean isHttpRequestPending(Net.HttpRequest httpRequest)
putIntoConnectionsAndListenersback to summary
pack-priv synchronized void putIntoConnectionsAndListeners(final Net.HttpRequest httpRequest, final Net.HttpResponseListener httpResponseListener, final HttpURLConnection connection)
removeFromConnectionsAndListenersback to summary
pack-priv synchronized void removeFromConnectionsAndListeners(final Net.HttpRequest httpRequest)
sendHttpRequestback to summary
public void sendHttpRequest(final Net.HttpRequest httpRequest, final Net.HttpResponseListener httpResponseListener)
com.badlogic.gdx.net back to summary

pack-priv Class NetJavaImpl.HttpClientResponse

extends Object
implements HttpResponse
Class Inheritance
All Implemented Interfaces
com.badlogic.gdx.Net.HttpResponse

Field Summary

Modifier and TypeField and Description
private final HttpURLConnection
private HttpStatus

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public String
getHeader(String name)

Implements com.badlogic.gdx.Net.HttpResponse.getHeader.

Returns the value of the header with the given name as a String, or null if the header is not set.

public Map<String, List<String>>
getHeaders()

Implements com.badlogic.gdx.Net.HttpResponse.getHeaders.

Returns a Map of the headers.

private InputStream
public byte[]
getResult()

Implements com.badlogic.gdx.Net.HttpResponse.getResult.

Returns the data of the HTTP response as a byte[].

public InputStream
getResultAsStream()

Implements com.badlogic.gdx.Net.HttpResponse.getResultAsStream.

Returns the data of the HTTP response as an InputStream.

public String
getResultAsString()

Implements com.badlogic.gdx.Net.HttpResponse.getResultAsString.

Returns the data of the HTTP response as a String.

public HttpStatus
getStatus()

Implements com.badlogic.gdx.Net.HttpResponse.getStatus.

Returns the HttpStatus containing the statusCode of the HTTP response.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

connectionback to summary
private final HttpURLConnection connection
statusback to summary
private HttpStatus status

Constructor Detail

HttpClientResponseback to summary
public HttpClientResponse(HttpURLConnection connection) throws IOException

Method Detail

getHeaderback to summary
public String getHeader(String name)

Implements com.badlogic.gdx.Net.HttpResponse.getHeader.

Doc from com.badlogic.gdx.Net.HttpResponse.getHeader.

Returns the value of the header with the given name as a String, or null if the header is not set. See HttpResponseHeader.

Annotations
@Override
getHeadersback to summary
public Map<String, List<String>> getHeaders()

Implements com.badlogic.gdx.Net.HttpResponse.getHeaders.

Doc from com.badlogic.gdx.Net.HttpResponse.getHeaders.

Returns a Map of the headers. The keys are Strings that represent the header name. Each values is a List of Strings that represent the corresponding header values. See HttpResponseHeader.

Annotations
@Override
getInputStreamback to summary
private InputStream getInputStream()
getResultback to summary
public byte[] getResult()

Implements com.badlogic.gdx.Net.HttpResponse.getResult.

Doc from com.badlogic.gdx.Net.HttpResponse.getResult.

Returns the data of the HTTP response as a byte[].

Note

This method may only be called once per response.

Annotations
@Override
getResultAsStreamback to summary
public InputStream getResultAsStream()

Implements com.badlogic.gdx.Net.HttpResponse.getResultAsStream.

Doc from com.badlogic.gdx.Net.HttpResponse.getResultAsStream.

Returns the data of the HTTP response as an InputStream.

Warning

Do not store a reference to this InputStream outside of HttpResponseListener#handleHttpResponse(HttpResponse). The underlying HTTP connection will be closed after that callback finishes executing. Reading from the InputStream after it's connection has been closed will lead to exception.

Annotations
@Override
getResultAsStringback to summary
public String getResultAsString()

Implements com.badlogic.gdx.Net.HttpResponse.getResultAsString.

Doc from com.badlogic.gdx.Net.HttpResponse.getResultAsString.

Returns the data of the HTTP response as a String.

Note

This method may only be called once per response.

Annotations
@Override
getStatusback to summary
public HttpStatus getStatus()

Implements com.badlogic.gdx.Net.HttpResponse.getStatus.

Doc from com.badlogic.gdx.Net.HttpResponse.getStatus.

Returns the HttpStatus containing the statusCode of the HTTP response.

Annotations
@Override