@Override
    public GroupStat[] listGroups() throws FdfsException {
        Socket socket = getSocket();
        byte[] header = Messages.createHeader(0L, TRACKER_PROTO_CMD_SERVER_LIST_GROUP);
        InputStream is = null;
        OutputStream os = null;
        GroupStat[] groupStatArr = null;
        try {
            os = socket.getOutputStream();
            is = socket.getInputStream();
            os.write(header);
            ResponseBody responseBody = Messages.readResponse(is, -1);
            byte errorNo = responseBody.getErrorNo();
            if (errorNo != 0) {
                return null;
            }
            byte[] body = responseBody.getBody();
            int fieldTotal = GroupStat.getFieldsTotalSize();
            if (body.length % fieldTotal != 0) {
                throw new IllegalStateException("invalid body.length");
            }
            groupStatArr =
                    Messages.decode(body, GroupStat.class, GroupStat.getFieldsTotalSize(),
                        fdfsClientConfig.getCharset());
            return groupStatArr;
        } catch (Exception e) {
            String msg = "listGroups fail, groupName=[{}], fileName=[{}] socket=[{}]";
            msg = Strings.format(msg, socket);
            throw new FdfsException(msg + e.getMessage(), e);
        } finally {
            closeSocket(socket, is, os);
        }
    }