1 /*
2 * Copyright (C) 2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "ext_wstream.h"
17 #include "hilog/log.h"
18 #include "log_tags.h"
19
20 namespace {
21 constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_TAG_DOMAIN_ID_PLUGIN, "ExtWStream"};
22 constexpr static size_t SIZE_ZERO = 0;
23 }
24 namespace OHOS {
25 namespace ImagePlugin {
26 using namespace OHOS::HiviewDFX;
27
ExtWStream(OutputDataStream * stream)28 ExtWStream::ExtWStream(OutputDataStream *stream) : stream_(stream)
29 {
30 }
31
write(const void * buffer,size_t size)32 bool ExtWStream::write(const void* buffer, size_t size)
33 {
34 if (stream_ == nullptr) {
35 HiLog::Error(LABEL, "ExtWStream::write stream is nullptr");
36 return false;
37 }
38 return stream_->Write(static_cast<const uint8_t*>(buffer), size);
39 }
40
flush()41 void ExtWStream::flush()
42 {
43 if (stream_ == nullptr) {
44 HiLog::Error(LABEL, "ExtWStream::flush stream is nullptr");
45 return;
46 }
47 stream_->Flush();
48 }
49
bytesWritten() const50 size_t ExtWStream::bytesWritten() const
51 {
52 if (stream_ == nullptr) {
53 HiLog::Error(LABEL, "ExtWStream::bytesWritten stream is nullptr");
54 return SIZE_ZERO;
55 }
56 size_t written = SIZE_ZERO;
57 stream_->GetCurrentSize(written);
58 return written;
59 }
60 } // namespace ImagePlugin
61 } // namespace OHOS
62