blob: 49b9fc36e293906abeb2de595f49a23b2406308a [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 {
Adam Lesinskicacb28f2016-10-19 12:18:14 -070033 public:
34 virtual std::string GetError() const { return {}; }
Adam Lesinski21efb682016-09-14 17:35:43 -070035
Adam Lesinskicacb28f2016-10-19 12:18:14 -070036 virtual bool HadError() const = 0;
Adam Lesinski21efb682016-09-14 17:35:43 -070037};
38
39/**
40 * OutputStream interface that inherits from protobuf's ZeroCopyOutputStream,
41 * but adds error handling methods to better report issues.
42 *
43 * The code style here matches the protobuf style.
44 */
45class OutputStream : public google::protobuf::io::ZeroCopyOutputStream {
Adam Lesinskicacb28f2016-10-19 12:18:14 -070046 public:
47 virtual std::string GetError() const { return {}; }
Adam Lesinski21efb682016-09-14 17:35:43 -070048
Adam Lesinskicacb28f2016-10-19 12:18:14 -070049 virtual bool HadError() const = 0;
Adam Lesinski21efb682016-09-14 17:35:43 -070050};
51
52/**
53 * Copies the data from in to out. Returns true if there was no error.
54 * If there was an error, check the individual streams' HadError/GetError
55 * methods.
56 */
57bool copy(OutputStream* out, InputStream* in);
58
Adam Lesinskicacb28f2016-10-19 12:18:14 -070059} // namespace io
60} // namespace aapt
Adam Lesinski21efb682016-09-14 17:35:43 -070061
62#endif /* AAPT_IO_IO_H */