1 /*
2 * Copyright 2009-2017 Alibaba Cloud All rights reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17
18 #include <alibabacloud/oss/model/GetBucketStatResult.h>
19 #include <external/tinyxml2/tinyxml2.h>
20 #include "utils/Utils.h"
21 using namespace AlibabaCloud::OSS;
22 using namespace tinyxml2;
23
24
GetBucketStatResult()25 GetBucketStatResult::GetBucketStatResult() :
26 OssResult(),
27 storage_(0),
28 objectCount_(0),
29 multipartUploadCount_(0)
30 {
31 }
32
GetBucketStatResult(const std::string & result)33 GetBucketStatResult::GetBucketStatResult(const std::string& result):
34 GetBucketStatResult()
35 {
36 *this = result;
37 }
38
GetBucketStatResult(const std::shared_ptr<std::iostream> & result)39 GetBucketStatResult::GetBucketStatResult(const std::shared_ptr<std::iostream>& result):
40 GetBucketStatResult()
41 {
42 std::istreambuf_iterator<char> isb(*result.get()), end;
43 std::string str(isb, end);
44 *this = str;
45 }
46
operator =(const std::string & result)47 GetBucketStatResult& GetBucketStatResult::operator =(const std::string& result)
48 {
49 XMLDocument doc;
50 XMLError xml_err;
51 if ((xml_err = doc.Parse(result.c_str(), result.size())) == XML_SUCCESS) {
52 XMLElement* root =doc.RootElement();
53 if (root && !std::strncmp("BucketStat", root->Name(), 10)) {
54 XMLElement *node;
55 node = root->FirstChildElement("Storage");
56 if (node && node->GetText()) storage_ = atoll(node->GetText());
57
58 node = root->FirstChildElement("ObjectCount");
59 if (node && node->GetText()) objectCount_ = atoll(node->GetText());
60
61 node = root->FirstChildElement("MultipartUploadCount");
62 if (node && node->GetText()) multipartUploadCount_ = atoll(node->GetText());
63
64 parseDone_ = true;
65 }
66 }
67 return *this;
68 }
69
70