本文整理匯總了Java中android.net.LocalSocket.getInputStream方法的典型用法代碼示例。如果您正苦於以下問題:Java LocalSocket.getInputStream方法的具體用法?Java LocalSocket.getInputStream怎麽用?Java LocalSocket.getInputStream使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.net.LocalSocket
的用法示例。
在下文中一共展示了LocalSocket.getInputStream方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: onSecured
import android.net.LocalSocket; //導入方法依賴的package包/類
@Override
protected void onSecured(LocalSocket socket) throws IOException {
LeakyBufferedInputStream leakyIn = new LeakyBufferedInputStream(
socket.getInputStream(),
SENSING_BUFFER_SIZE);
if (mHandlers.isEmpty()) {
throw new IllegalStateException("No handlers added");
}
for (int i = 0, N = mHandlers.size(); i < N; i++) {
HandlerInfo handlerInfo = mHandlers.get(i);
leakyIn.mark(SENSING_BUFFER_SIZE);
boolean matches = handlerInfo.magicMatcher.matches(leakyIn);
leakyIn.reset();
if (matches) {
LogUtil.d("Matches!" + handlerInfo.handler.getClass().getSimpleName());
SocketLike socketLike = new SocketLike(socket, leakyIn);
handlerInfo.handler.onAccepted(socketLike);
return;
}
}
throw new IOException("No matching handler, firstByte=" + leakyIn.read());
}
示例2: onSecured
import android.net.LocalSocket; //導入方法依賴的package包/類
@Override
protected void onSecured(LocalSocket socket) throws IOException {
LeakyBufferedInputStream leakyIn = new LeakyBufferedInputStream(
socket.getInputStream(),
SENSING_BUFFER_SIZE);
if (mHandlers.isEmpty()) {
throw new IllegalStateException("No handlers added");
}
for (int i = 0, N = mHandlers.size(); i < N; i++) {
HandlerInfo handlerInfo = mHandlers.get(i);
leakyIn.mark(SENSING_BUFFER_SIZE);
boolean matches = handlerInfo.magicMatcher.matches(leakyIn);
leakyIn.reset();
if (matches) {
SocketLike socketLike = new SocketLike(socket, leakyIn);
handlerInfo.handler.onAccepted(socketLike);
return;
}
}
throw new IOException("No matching handler, firstByte=" + leakyIn.read());
}
示例3: simplestGet
import android.net.LocalSocket; //導入方法依賴的package包/類
@Test(timeout = 1000)
public void simplestGet() throws IOException, InterruptedException {
// given
Service service = startService();
// when
LocalSocket clientSocket = new LocalSocket();
clientSocket.connect(new LocalSocketAddress("doesn't matter now"));
OutputStream os = clientSocket.getOutputStream();
os.write(GET_1.getBytes());
os.close();
// then
InputStream is = clientSocket.getInputStream();
String response = IOUtils.toString(is);
System.out.println("response: " + response);
String expectedBody = new Test1().test();
assertThat(response, containsString(expectedBody));
}
示例4: simplestPost
import android.net.LocalSocket; //導入方法依賴的package包/類
@Test(timeout = 1000)
public void simplestPost() throws IOException, InterruptedException {
// given
Service service = startService();
// when
LocalSocket clientSocket = new LocalSocket();
clientSocket.connect(new LocalSocketAddress("doesn't matter now"));
OutputStream os = clientSocket.getOutputStream();
os.write(POST_1.getBytes());
os.close();
// then
InputStream is = clientSocket.getInputStream();
String response = IOUtils.toString(is);
System.out.println("response: " + response);
String expectedBody = new TestPost().post(11, "somename");
assertThat(response, containsString(expectedBody));
}
示例5: shouldParseLongGetRequests
import android.net.LocalSocket; //導入方法依賴的package包/類
@Test(timeout = 1000)
public void shouldParseLongGetRequests() throws IOException {
// given
Service service = startService();
// when
LocalSocket clientSocket = new LocalSocket();
clientSocket.connect(new LocalSocketAddress("doesn't matter now"));
OutputStream os = clientSocket.getOutputStream();
os.write(GET_LONG_1.getBytes()); // two long requests
os.write(GET_LONG_1.getBytes());
os.close();
// then
InputStream is = clientSocket.getInputStream();
String response = IOUtils.toString(is);
System.out.println("response: " + response);
String expectedBody = new Test1().test();
assertThat(response, containsString(expectedBody));
}
示例6: headersShouldBeDecoded
import android.net.LocalSocket; //導入方法依賴的package包/類
@Test(timeout = 1000)
public void headersShouldBeDecoded() throws IOException {
// given
Service service = new Service();
service.onCreate();
service.onStartCommand(new Intent(), 0, 0);
// when
LocalSocket clientSocket = new LocalSocket();
clientSocket.connect(new LocalSocketAddress("doesn't matter now"));
OutputStream os = clientSocket.getOutputStream();
os.write(GET_1.getBytes());
os.close();
// then
InputStream is = clientSocket.getInputStream();
String response = IOUtils.toString(is);
System.out.println("response: " + response);
assertThat(response, containsString("localhost"));
assertThat(response, containsString("b=2"));
assertThat(response, containsString("a=1"));
}
示例7: cookieShouldBeReturned
import android.net.LocalSocket; //導入方法依賴的package包/類
@Test(timeout = 1000)
public void cookieShouldBeReturned() throws IOException, InterruptedException {
// given
Service service = new Service();
service.onCreate();
service.onStartCommand(new Intent(), 0, 0);
// when
LocalSocket clientSocket = new LocalSocket();
clientSocket.connect(new LocalSocketAddress("doesn't matter now"));
OutputStream os = clientSocket.getOutputStream();
os.write(GET_1.getBytes());
os.close();
// then
InputStream is = clientSocket.getInputStream();
String response = IOUtils.toString(is);
System.out.println("response: " + response);
String expectedBody = "Set-Cookie: COOKIE_NAME=cookieValuecookieValue";
assertThat(response, containsString(expectedBody));
}
示例8: cookieShouldBeAccepted
import android.net.LocalSocket; //導入方法依賴的package包/類
@Test(timeout = 1000)
public void cookieShouldBeAccepted() throws IOException, InterruptedException {
// given
Service service = new Service();
service.onCreate();
service.onStartCommand(new Intent(), 0, 0);
// when
LocalSocket clientSocket = new LocalSocket();
clientSocket.connect(new LocalSocketAddress("doesn't matter now"));
OutputStream os = clientSocket.getOutputStream();
os.write(GET_2.getBytes());
os.close();
// then
InputStream is = clientSocket.getInputStream();
String response = IOUtils.toString(is);
System.out.println("response: " + response);
String expectedBody = "cookieValuecookieValue";
assertThat(response, containsString(expectedBody));
}
示例9: receive
import android.net.LocalSocket; //導入方法依賴的package包/類
/**
* Receives data from the socket.
*
* @param socket Socket from where to receive data.
* @param data Array where to save received data.
* @param len Number of bytes to receive.
* @throws IOException
*/
public static void receive(LocalSocket socket, byte[] data, int len) throws IOException {
final InputStream is = socket.getInputStream();
int received = 0;
while (received != len) {
final int chunk = is.read(data, received, len - received);
if (chunk < 0) {
throw new IOException(
"I/O failure while receiving SDK controller data from socket.");
}
received += chunk;
}
}
示例10: connect
import android.net.LocalSocket; //導入方法依賴的package包/類
public boolean connect() {
mSocket = new LocalSocket();
try {
mSocket.connect(new LocalSocketAddress("fota", LocalSocketAddress.Namespace.RESERVED));
mIn = mSocket.getInputStream();
mOut = mSocket.getOutputStream();
return true;
} catch (IOException e) {
e.printStackTrace();
}
return false;
}
示例11: connectLoop
import android.net.LocalSocket; //導入方法依賴的package包/類
private boolean connectLoop() {
LocalSocket s = new LocalSocket();
if (!TextUtils.isEmpty(mBindpoint)) {
try {
s.bind(new LocalSocketAddress(mBindpoint));
} catch (IOException e1) {
e1.printStackTrace();
}
}
while(!cancelRequested) {
try {
s.connect(mSocketPath);
synchronized(this) {
mSocket = s;
mInputStream = s.getInputStream();
mOutputStream = s.getOutputStream();
}
return true;
}catch (IOException e) {
synchronized(this) {
if (cancelRequested) {
return false;
}
if (!isDeviceReady()) {
return true;
}
setState(STATE_RECONNECTING);
try {
wait(mReconnectTimeout);
} catch(InterruptedException ie) {
return false;
}
}
}
}
return false;
}
示例12: startLocalClient
import android.net.LocalSocket; //導入方法依賴的package包/類
private void startLocalClient(String name, String message) throws Exception {
// Construct a local socket
LocalSocket clientSocket = new LocalSocket();
try {
// Set the socket namespace
LocalSocketAddress.Namespace namespace;
if (isFilesystemSocket(name)) {
namespace = LocalSocketAddress.Namespace.FILESYSTEM;
} else {
namespace = LocalSocketAddress.Namespace.ABSTRACT;
}
// Construct local socket address
LocalSocketAddress address = new LocalSocketAddress(name, namespace);
// Connect to local socket
Log.i(TAG, "Connecting to " + name);
clientSocket.connect(address);
Log.i(TAG, "Connected.");
// Get message as bytes
byte[] messageBytes = message.getBytes();
// Send message bytes to the socket
Log.i(TAG, "Sending to the socket...");
OutputStream outputStream = clientSocket.getOutputStream();
outputStream.write(messageBytes);
Log.i(TAG, String.format("Sent %d bytes: %s",messageBytes.length, message));
// Receive the message back from the socket
Log.i(TAG, "Receiving from the socket...");
InputStream inputStream = clientSocket.getInputStream();
int readSize = inputStream.read(messageBytes);
String receivedMessage = new String(messageBytes, 0, readSize);
Log.i(TAG, String.format("Received %d bytes: %s",
readSize, receivedMessage));
// Close streams
outputStream.close();
inputStream.close();
} finally {
// Close the local socket
clientSocket.close();
}
}