blob: cab4b65f2f5abb076c169ea3d51a4ba7eaeba35d [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#include "io/Io.h"
18
19#include <algorithm>
20#include <cstring>
21
22namespace aapt {
23namespace io {
24
Adam Lesinskice5e56e2016-10-21 17:56:45 -070025bool Copy(OutputStream* out, InputStream* in) {
26 const void* in_buffer;
27 int in_len;
28 while (in->Next(&in_buffer, &in_len)) {
29 void* out_buffer;
30 int out_len;
31 if (!out->Next(&out_buffer, &out_len)) {
32 return !out->HadError();
Adam Lesinski21efb682016-09-14 17:35:43 -070033 }
Adam Lesinskice5e56e2016-10-21 17:56:45 -070034
35 const int bytes_to_copy = std::min(in_len, out_len);
36 memcpy(out_buffer, in_buffer, bytes_to_copy);
37 out->BackUp(out_len - bytes_to_copy);
38 in->BackUp(in_len - bytes_to_copy);
39 }
40 return !in->HadError();
Adam Lesinski21efb682016-09-14 17:35:43 -070041}
42
Adam Lesinskice5e56e2016-10-21 17:56:45 -070043} // namespace io
44} // namespace aapt