1 /*
2  * Copyright 2015 Google Inc.
3  *
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  */
7 
8 #include "SkDmuxWStream.h"
9 
SkDmuxWStream(SkWStream * const streamArray[],size_t count)10 SkDmuxWStream::SkDmuxWStream(SkWStream* const streamArray[], size_t count)
11     : fWStreams(streamArray, static_cast<int>(count)), fBytesWritten(0) {}
12 
~SkDmuxWStream()13 SkDmuxWStream::~SkDmuxWStream() {
14     for (int i = 0; i < fWStreams.count(); ++i) {
15         fWStreams[i]->flush();
16     }
17 }
18 
write(const void * buffer,size_t size)19 bool SkDmuxWStream::write(const void* buffer, size_t size) {
20     for (int i = 0; i < fWStreams.count(); ++i) {
21         if (!fWStreams[i]->write(buffer, size)) {
22             return false;
23         }
24     }
25     fBytesWritten += size;
26     return true;
27 }
28 
newline()29 void SkDmuxWStream::newline() {
30     for (int i = 0; i < fWStreams.count(); ++i) {
31         fWStreams[i]->newline();
32     }
33     fBytesWritten += 1;  // This may be a lie.
34 }
35 
flush()36 void SkDmuxWStream::flush() {
37     for (int i = 0; i < fWStreams.count(); ++i) {
38         fWStreams[i]->flush();
39     }
40 }
41 
bytesWritten() const42 size_t SkDmuxWStream::bytesWritten() const { return fBytesWritten; }
43