Line | Count | Source |
1 | | // Licensed to the Apache Software Foundation (ASF) under one |
2 | | // or more contributor license agreements. See the NOTICE file |
3 | | // distributed with this work for additional information |
4 | | // regarding copyright ownership. The ASF licenses this file |
5 | | // to you under the Apache License, Version 2.0 (the |
6 | | // "License"); you may not use this file except in compliance |
7 | | // with the License. You may obtain a copy of the License at |
8 | | // |
9 | | // http://www.apache.org/licenses/LICENSE-2.0 |
10 | | // |
11 | | // Unless required by applicable law or agreed to in writing, |
12 | | // software distributed under the License is distributed on an |
13 | | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
14 | | // KIND, either express or implied. See the License for the |
15 | | // specific language governing permissions and limitations |
16 | | // under the License. |
17 | | |
18 | | #pragma once |
19 | | |
20 | | #include <aws/core/utils/memory/stl/AWSStreamFwd.h> |
21 | | #include <aws/core/utils/stream/PreallocatedStreamBuf.h> |
22 | | |
23 | | namespace doris { |
24 | | |
25 | | // A non-copying iostream. |
26 | | // See https://stackoverflow.com/questions/35322033/aws-c-sdk-uploadpart-times-out |
27 | | // https://stackoverflow.com/questions/13059091/creating-an-input-stream-from-constant-memory |
28 | | class StringViewStream : Aws::Utils::Stream::PreallocatedStreamBuf, public std::iostream { |
29 | | public: |
30 | | StringViewStream(const void* buf, int64_t nbytes) |
31 | 86.8k | : Aws::Utils::Stream::PreallocatedStreamBuf( |
32 | 86.8k | reinterpret_cast<unsigned char*>(const_cast<void*>(buf)), |
33 | 86.8k | static_cast<size_t>(nbytes)), |
34 | 86.8k | std::iostream(this) {} |
35 | | }; |
36 | | |
37 | | // By default, the AWS SDK reads object data into an auto-growing StringStream. |
38 | | // To avoid copies, read directly into our preallocated buffer instead. |
39 | | // See https://github.com/aws/aws-sdk-cpp/issues/64 for an alternative but |
40 | | // functionally similar recipe. |
41 | 42.0k | inline Aws::IOStreamFactory AwsWriteableStreamFactory(void* buf, int64_t nbytes) { |
42 | 42.0k | return [=]() { return Aws::New<StringViewStream>("", buf, nbytes); }; |
43 | 42.0k | } |
44 | | |
45 | | } // namespace doris |