/** * receive whole pack * * @param in input stream * @param expect_cmd expect response command * @param expect_body_len expect response package body length * @return RecvPackageInfo: errno and reponse body(byte buff) */ public static RecvPackageInfo recvPackage(InputStream in, byte expect_cmd, long expect_body_len) throws IOException { RecvHeaderInfo header = recvHeader(in, expect_cmd, expect_body_len); if (header.errno != 0) { return new RecvPackageInfo(header.errno, null); } byte[] body = new byte[(int) header.body_len]; int totalBytes = 0; int remainBytes = (int) header.body_len; int bytes; while (totalBytes < header.body_len) { if ((bytes = in.read(body, totalBytes, remainBytes)) < 0) { break; } totalBytes += bytes; remainBytes -= bytes; } if (totalBytes != header.body_len) { throw new IOException("recv package size " + totalBytes + " != " + header.body_len); } return new RecvPackageInfo((byte) 0, body); }
if (header.errno != 0) return new RecvPackageInfo(header.errno, null); return new RecvPackageInfo((byte)0, body);
/** * receive whole pack * * @param in input stream * @param expect_cmd expect response command * @param expect_body_len expect response package body length * @return RecvPackageInfo: errno and reponse body(byte buff) */ public static RecvPackageInfo recvPackage(InputStream in, byte expect_cmd, long expect_body_len) throws IOException { RecvHeaderInfo header = recvHeader(in, expect_cmd, expect_body_len); if (header.errno != 0) { return new RecvPackageInfo(header.errno, null); } byte[] body = new byte[(int) header.body_len]; int totalBytes = 0; int remainBytes = (int) header.body_len; int bytes; while (totalBytes < header.body_len) { if ((bytes = in.read(body, totalBytes, remainBytes)) < 0) { break; } totalBytes += bytes; remainBytes -= bytes; } if (totalBytes != header.body_len) { throw new IOException("recv package size " + totalBytes + " != " + header.body_len); } return new RecvPackageInfo((byte) 0, body); }
/** * receive whole pack * * @param in input stream * @param expect_cmd expect response command * @param expect_body_len expect response package body length * @return RecvPackageInfo: errno and reponse body(byte buff) */ public static RecvPackageInfo recvPackage(InputStream in, byte expect_cmd, long expect_body_len) throws IOException { RecvHeaderInfo header = recvHeader(in, expect_cmd, expect_body_len); if (header.errno != 0) { return new RecvPackageInfo(header.errno, null); } byte[] body = new byte[(int) header.body_len]; int totalBytes = 0; int remainBytes = (int) header.body_len; int bytes; while (totalBytes < header.body_len) { if ((bytes = in.read(body, totalBytes, remainBytes)) < 0) { break; } totalBytes += bytes; remainBytes -= bytes; } if (totalBytes != header.body_len) { throw new IOException("recv package size " + totalBytes + " != " + header.body_len); } return new RecvPackageInfo((byte) 0, body); }
/** * receive whole pack * @param in input stream * @param expect_cmd expect response command * @param expect_body_len expect response package body length * @return RecvPackageInfo: errno and reponse body(byte buff) */ public static RecvPackageInfo recvPackage(InputStream in, byte expect_cmd, long expect_body_len) throws IOException { RecvHeaderInfo header = recvHeader(in, expect_cmd, expect_body_len); if (header.errno != 0) { return new RecvPackageInfo(header.errno, null); } byte[] body = new byte[(int) header.body_len]; int totalBytes = 0; int remainBytes = (int) header.body_len; int bytes; while (totalBytes < header.body_len) { if ((bytes = in.read(body, totalBytes, remainBytes)) < 0) { break; } totalBytes += bytes; remainBytes -= bytes; } if (totalBytes != header.body_len) { throw new IOException("recv package size " + totalBytes + " != " + header.body_len); } return new RecvPackageInfo((byte) 0, body); }