1e507721000647a7d8afe44c63ef7fd04ef8971b1Ruben Brunk/*
2e507721000647a7d8afe44c63ef7fd04ef8971b1Ruben Brunk * Copyright 2014 The Android Open Source Project
3e507721000647a7d8afe44c63ef7fd04ef8971b1Ruben Brunk *
4e507721000647a7d8afe44c63ef7fd04ef8971b1Ruben Brunk * Licensed under the Apache License, Version 2.0 (the "License");
5e507721000647a7d8afe44c63ef7fd04ef8971b1Ruben Brunk * you may not use this file except in compliance with the License.
6e507721000647a7d8afe44c63ef7fd04ef8971b1Ruben Brunk * You may obtain a copy of the License at
7e507721000647a7d8afe44c63ef7fd04ef8971b1Ruben Brunk *
8e507721000647a7d8afe44c63ef7fd04ef8971b1Ruben Brunk *      http://www.apache.org/licenses/LICENSE-2.0
9e507721000647a7d8afe44c63ef7fd04ef8971b1Ruben Brunk *
10e507721000647a7d8afe44c63ef7fd04ef8971b1Ruben Brunk * Unless required by applicable law or agreed to in writing, software
11e507721000647a7d8afe44c63ef7fd04ef8971b1Ruben Brunk * distributed under the License is distributed on an "AS IS" BASIS,
12e507721000647a7d8afe44c63ef7fd04ef8971b1Ruben Brunk * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13e507721000647a7d8afe44c63ef7fd04ef8971b1Ruben Brunk * See the License for the specific language governing permissions and
14e507721000647a7d8afe44c63ef7fd04ef8971b1Ruben Brunk * limitations under the License.
15e507721000647a7d8afe44c63ef7fd04ef8971b1Ruben Brunk */
16e507721000647a7d8afe44c63ef7fd04ef8971b1Ruben Brunk
17e507721000647a7d8afe44c63ef7fd04ef8971b1Ruben Brunk#include <img_utils/ByteArrayOutput.h>
18e507721000647a7d8afe44c63ef7fd04ef8971b1Ruben Brunk
19e507721000647a7d8afe44c63ef7fd04ef8971b1Ruben Brunk#include <utils/Log.h>
20e507721000647a7d8afe44c63ef7fd04ef8971b1Ruben Brunk
21e507721000647a7d8afe44c63ef7fd04ef8971b1Ruben Brunknamespace android {
22e507721000647a7d8afe44c63ef7fd04ef8971b1Ruben Brunknamespace img_utils {
23e507721000647a7d8afe44c63ef7fd04ef8971b1Ruben Brunk
24e507721000647a7d8afe44c63ef7fd04ef8971b1Ruben BrunkByteArrayOutput::ByteArrayOutput() {}
25e507721000647a7d8afe44c63ef7fd04ef8971b1Ruben Brunk
26e507721000647a7d8afe44c63ef7fd04ef8971b1Ruben BrunkByteArrayOutput::~ByteArrayOutput() {}
27e507721000647a7d8afe44c63ef7fd04ef8971b1Ruben Brunk
28e507721000647a7d8afe44c63ef7fd04ef8971b1Ruben Brunkstatus_t ByteArrayOutput::open() {
29e507721000647a7d8afe44c63ef7fd04ef8971b1Ruben Brunk    return OK;
30e507721000647a7d8afe44c63ef7fd04ef8971b1Ruben Brunk}
31e507721000647a7d8afe44c63ef7fd04ef8971b1Ruben Brunk
32e507721000647a7d8afe44c63ef7fd04ef8971b1Ruben Brunkstatus_t ByteArrayOutput::write(const uint8_t* buf, size_t offset, size_t count) {
33e507721000647a7d8afe44c63ef7fd04ef8971b1Ruben Brunk    if (mByteArray.appendArray(buf + offset, count) < 0) {
34e507721000647a7d8afe44c63ef7fd04ef8971b1Ruben Brunk        ALOGE("%s: Failed to write to ByteArrayOutput.", __FUNCTION__);
35e507721000647a7d8afe44c63ef7fd04ef8971b1Ruben Brunk        return BAD_VALUE;
36e507721000647a7d8afe44c63ef7fd04ef8971b1Ruben Brunk    }
37e507721000647a7d8afe44c63ef7fd04ef8971b1Ruben Brunk    return OK;
38e507721000647a7d8afe44c63ef7fd04ef8971b1Ruben Brunk}
39e507721000647a7d8afe44c63ef7fd04ef8971b1Ruben Brunk
40e507721000647a7d8afe44c63ef7fd04ef8971b1Ruben Brunkstatus_t ByteArrayOutput::close() {
41e507721000647a7d8afe44c63ef7fd04ef8971b1Ruben Brunk    mByteArray.clear();
42e507721000647a7d8afe44c63ef7fd04ef8971b1Ruben Brunk    return OK;
43e507721000647a7d8afe44c63ef7fd04ef8971b1Ruben Brunk}
44e507721000647a7d8afe44c63ef7fd04ef8971b1Ruben Brunk
45e507721000647a7d8afe44c63ef7fd04ef8971b1Ruben Brunksize_t ByteArrayOutput::getSize() const {
46e507721000647a7d8afe44c63ef7fd04ef8971b1Ruben Brunk    return mByteArray.size();
47e507721000647a7d8afe44c63ef7fd04ef8971b1Ruben Brunk}
48e507721000647a7d8afe44c63ef7fd04ef8971b1Ruben Brunk
49e507721000647a7d8afe44c63ef7fd04ef8971b1Ruben Brunkconst uint8_t* ByteArrayOutput::getArray() const {
50e507721000647a7d8afe44c63ef7fd04ef8971b1Ruben Brunk    return mByteArray.array();
51e507721000647a7d8afe44c63ef7fd04ef8971b1Ruben Brunk}
52e507721000647a7d8afe44c63ef7fd04ef8971b1Ruben Brunk
53e507721000647a7d8afe44c63ef7fd04ef8971b1Ruben Brunk} /*namespace img_utils*/
54e507721000647a7d8afe44c63ef7fd04ef8971b1Ruben Brunk} /*namespace android*/
55