/** * Creates the data array for a stat request. * @param command the 4 byte command (ID_STAT, ID_RECV, ...) * @param path The path of the remote file on which to execute the command * @return the byte[] to send to the device through adb */ private static byte[] createFileReq(byte[] command, String path) { byte[] pathContent; try { pathContent = path.getBytes(AdbHelper.DEFAULT_ENCODING); } catch (UnsupportedEncodingException e) { return null; } return createFileReq(command, pathContent); }
/** * Creates the data array for a stat request. * @param command the 4 byte command (ID_STAT, ID_RECV, ...) * @param path The path of the remote file on which to execute the command * @return the byte[] to send to the device through adb */ private static byte[] createFileReq(byte[] command, String path) { byte[] pathContent = null; try { pathContent = path.getBytes(AdbHelper.DEFAULT_ENCODING); } catch (UnsupportedEncodingException e) { return null; } return createFileReq(command, pathContent); }
/** * Creates the data array for a stat request. * @param command the 4 byte command (ID_STAT, ID_RECV, ...) * @param path The path of the remote file on which to execute the command * @return the byte[] to send to the device through adb */ private static byte[] createFileReq(byte[] command, String path) { byte[] pathContent = null; try { pathContent = path.getBytes(AdbHelper.DEFAULT_ENCODING); } catch (UnsupportedEncodingException e) { return null; } return createFileReq(command, pathContent); }
/** * Returns the mode of the remote file. * @param path the remote file * @return an Integer containing the mode if all went well or null * otherwise * @throws IOException * @throws TimeoutException in case of a timeout reading responses from the device. */ private Integer readMode(String path) throws TimeoutException, IOException { // create the stat request message. byte[] msg = createFileReq(ID_STAT, path); AdbHelper.write(mChannel, msg, -1 /* full length */, DdmPreferences.getTimeOut()); // read the result, in a byte array containing 4 ints // (id, mode, size, time) byte[] statResult = new byte[16]; AdbHelper.read(mChannel, statResult, -1 /* full length */, DdmPreferences.getTimeOut()); // check we have the proper data back if (!checkResult(statResult, ID_STAT)) { return null; } // we return the mode (2nd int in the array) return ArrayHelper.swap32bitFromArray(statResult, 4); }
/** * Returns the mode of the remote file. * @param path the remote file * @return an Integer containing the mode if all went well or null * otherwise * @throws IOException * @throws TimeoutException in case of a timeout reading responses from the device. */ private Integer readMode(String path) throws TimeoutException, IOException { // create the stat request message. byte[] msg = createFileReq(ID_STAT, path); AdbHelper.write(mChannel, msg, -1 /* full length */, DdmPreferences.getTimeOut()); // read the result, in a byte array containing 4 ints // (id, mode, size, time) byte[] statResult = new byte[16]; AdbHelper.read(mChannel, statResult, -1 /* full length */, DdmPreferences.getTimeOut()); // check we have the proper data back if (checkResult(statResult, ID_STAT) == false) { return null; } // we return the mode (2nd int in the array) return ArrayHelper.swap32bitFromArray(statResult, 4); }
msg = createFileReq(ID_RECV, remotePathContent);
msg = createFileReq(ID_RECV, remotePathContent);
msg = createFileReq(ID_RECV, remotePathContent);
/** * Returns the stat info of the remote file. * @param path the remote file * @return an FileStat containing the mode, size and last modified info if all went well or null * otherwise * @throws IOException * @throws TimeoutException in case of a timeout reading responses from the device. */ @Nullable public FileStat statFile(@NonNull String path) throws TimeoutException, IOException { // create the stat request message. byte[] msg = createFileReq(ID_STAT, path); AdbHelper.write(mChannel, msg, -1 /* full length */, DdmPreferences.getTimeOut()); // read the result, in a byte array containing 4 ints // (id, mode, size, time) byte[] statResult = new byte[16]; AdbHelper.read(mChannel, statResult, -1 /* full length */, DdmPreferences.getTimeOut()); // check we have the proper data back if (!checkResult(statResult, ID_STAT)) { return null; } final int mode = ArrayHelper.swap32bitFromArray(statResult, 4); final int size = ArrayHelper.swap32bitFromArray(statResult, 8); final int lastModifiedSecs = ArrayHelper.swap32bitFromArray(statResult, 12); return new FileStat(mode, size, lastModifiedSecs); }