code: private static void decode(InputStream in, StringBuilder result) throws ApiDataException, ApiConnectionException {
          try {
              int len = readLen(in);
              if (len > 0) {
                  byte buf[] = new byte[len];
                  for (int i = 0; i < len; ++i) {
                      int c = in.read();
                      if (c < 0) {
                          throw new ApiDataException("Truncated data. Expected to read more bytes");
                      }
                      buf[i] = (byte) (c & 0xFF);
                  }
                  String res = new String(buf, Charset.forName("UTF-8"));
                  if (result.length() > 0) {
                      result.append("\n");
                  }
                  result.append(res);
                  decode(in, result);
              }
          } catch (IOException ex) {
              throw new ApiConnectionException(ex.getMessage(), ex);
          }
      }
docs: decode bytes from an input stream into Mikrotik protocol sentences