blob: e1e9107e388b876d5e92ffba2297a35245fa05e8 [file] [log] [blame]
Adam Lesinski21efb682016-09-14 17:35:43 -07001/*
2 * Copyright (C) 2016 The Android Open Source Project
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#ifndef AAPT_IO_IO_H
18#define AAPT_IO_IO_H
19
20#include <google/protobuf/io/zero_copy_stream_impl_lite.h>
21#include <string>
22
23namespace aapt {
24namespace io {
25
26/**
27 * InputStream interface that inherits from protobuf's ZeroCopyInputStream,
28 * but adds error handling methods to better report issues.
29 *
30 * The code style here matches the protobuf style.
31 */
32class InputStream : public google::protobuf::io::ZeroCopyInputStream {
33public:
34 virtual std::string GetError() const {
35 return {};
36 }
37
38 virtual bool HadError() const = 0;
39};
40
41/**
42 * OutputStream interface that inherits from protobuf's ZeroCopyOutputStream,
43 * but adds error handling methods to better report issues.
44 *
45 * The code style here matches the protobuf style.
46 */
47class OutputStream : public google::protobuf::io::ZeroCopyOutputStream {
48public:
49 virtual std::string GetError() const {
50 return {};
51 }
52
53 virtual bool HadError() const = 0;
54};
55
56/**
57 * Copies the data from in to out. Returns true if there was no error.
58 * If there was an error, check the individual streams' HadError/GetError
59 * methods.
60 */
61bool copy(OutputStream* out, InputStream* in);
62
63} // namespace io
64} // namespace aapt
65
66#endif /* AAPT_IO_IO_H */