/** * Reads the length of the next message from a socket. * @param socket The {@link SocketChannel} to read from. * @return the length, or 0 (zero) if no data is available from the socket. * @throws IOException if the connection failed. */ private int readLength(SocketChannel socket, byte[] buffer) throws IOException { String msg = read(socket, buffer); if (msg != null) { try { return Integer.parseInt(msg, 16); } catch (NumberFormatException nfe) { // we'll throw an exception below. } } // we receive something we can't read. It's better to reset the connection at this point. throw new IOException("Unable to read length"); }
/** * Reads the length of the next message from a socket. * @param socket The {@link SocketChannel} to read from. * @return the length, or 0 (zero) if no data is available from the socket. * @throws IOException if the connection failed. */ private static int readLength(@NonNull SocketChannel socket, @NonNull byte[] buffer) throws IOException { String msg = read(socket, buffer); if (msg != null) { try { return Integer.parseInt(msg, 16); } catch (NumberFormatException nfe) { // we'll throw an exception below. } } // we receive something we can't read. It's better to reset the connection at this point. throw new IOException("Unable to read length"); }
/** * Reads the length of the next message from a socket. * @param socket The {@link SocketChannel} to read from. * @return the length, or 0 (zero) if no data is available from the socket. * @throws IOException if the connection failed. */ private static int readLength(@NonNull SocketChannel socket, @NonNull byte[] buffer) throws IOException { String msg = read(socket, buffer); if (msg != null) { try { return Integer.parseInt(msg, 16); } catch (NumberFormatException nfe) { // we'll throw an exception below. } } // we receive something we can't read. It's better to reset the connection at this point. throw new IOException("Unable to read length"); }
/** * Processes an incoming device message from the socket * @param socket * @param length * @throws IOException */ private void processIncomingDeviceData(int length) throws IOException { ArrayList<Device> list = new ArrayList<Device>(); if (length > 0) { byte[] buffer = new byte[length]; String result = read(mMainAdbConnection, buffer); String[] devices = result.split("\n"); //$NON-NLS-1$ for (String d : devices) { String[] param = d.split("\t"); //$NON-NLS-1$ if (param.length == 2) { // new adb uses only serial numbers to identify devices Device device = new Device(this, param[0] /*serialnumber*/, DeviceState.getState(param[1])); //add the device to the list list.add(device); } } } // now merge the new devices with the old ones. updateDevices(list); }
String result = read(monitorSocket, buffer);
String result = read(monitorSocket, buffer);