1cd60ac736bc7104785dc67671660d70fb434466fBrian Carlstrom/* 2cd60ac736bc7104785dc67671660d70fb434466fBrian Carlstrom * Copyright (C) 2013 The Android Open Source Project 3cd60ac736bc7104785dc67671660d70fb434466fBrian Carlstrom * 4cd60ac736bc7104785dc67671660d70fb434466fBrian Carlstrom * Licensed under the Apache License, Version 2.0 (the "License"); 5cd60ac736bc7104785dc67671660d70fb434466fBrian Carlstrom * you may not use this file except in compliance with the License. 6cd60ac736bc7104785dc67671660d70fb434466fBrian Carlstrom * You may obtain a copy of the License at 7cd60ac736bc7104785dc67671660d70fb434466fBrian Carlstrom * 8cd60ac736bc7104785dc67671660d70fb434466fBrian Carlstrom * http://www.apache.org/licenses/LICENSE-2.0 9cd60ac736bc7104785dc67671660d70fb434466fBrian Carlstrom * 10cd60ac736bc7104785dc67671660d70fb434466fBrian Carlstrom * Unless required by applicable law or agreed to in writing, software 11cd60ac736bc7104785dc67671660d70fb434466fBrian Carlstrom * distributed under the License is distributed on an "AS IS" BASIS, 12cd60ac736bc7104785dc67671660d70fb434466fBrian Carlstrom * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13cd60ac736bc7104785dc67671660d70fb434466fBrian Carlstrom * See the License for the specific language governing permissions and 14cd60ac736bc7104785dc67671660d70fb434466fBrian Carlstrom * limitations under the License. 15cd60ac736bc7104785dc67671660d70fb434466fBrian Carlstrom */ 16cd60ac736bc7104785dc67671660d70fb434466fBrian Carlstrom 17cd60ac736bc7104785dc67671660d70fb434466fBrian Carlstrom#include "vector_output_stream.h" 18cd60ac736bc7104785dc67671660d70fb434466fBrian Carlstrom 19cd60ac736bc7104785dc67671660d70fb434466fBrian Carlstrom#include "base/logging.h" 20cd60ac736bc7104785dc67671660d70fb434466fBrian Carlstrom 21cd60ac736bc7104785dc67671660d70fb434466fBrian Carlstromnamespace art { 22cd60ac736bc7104785dc67671660d70fb434466fBrian Carlstrom 23cd60ac736bc7104785dc67671660d70fb434466fBrian CarlstromVectorOutputStream::VectorOutputStream(const std::string& location, std::vector<uint8_t>& vector) 2449a0f158ed11974fa2cc12014c9f55a31dabd8dfBrian Carlstrom : OutputStream(location), offset_(vector.size()), vector_(vector) {} 25cd60ac736bc7104785dc67671660d70fb434466fBrian Carlstrom 2649a0f158ed11974fa2cc12014c9f55a31dabd8dfBrian Carlstromoff_t VectorOutputStream::Seek(off_t offset, Whence whence) { 2749a0f158ed11974fa2cc12014c9f55a31dabd8dfBrian Carlstrom CHECK(whence == kSeekSet || whence == kSeekCurrent || whence == kSeekEnd) << whence; 2849a0f158ed11974fa2cc12014c9f55a31dabd8dfBrian Carlstrom off_t new_offset = 0; 29cd60ac736bc7104785dc67671660d70fb434466fBrian Carlstrom switch (whence) { 3049a0f158ed11974fa2cc12014c9f55a31dabd8dfBrian Carlstrom case kSeekSet: { 31cd60ac736bc7104785dc67671660d70fb434466fBrian Carlstrom new_offset = offset; 32cd60ac736bc7104785dc67671660d70fb434466fBrian Carlstrom break; 33cd60ac736bc7104785dc67671660d70fb434466fBrian Carlstrom } 3449a0f158ed11974fa2cc12014c9f55a31dabd8dfBrian Carlstrom case kSeekCurrent: { 35cd60ac736bc7104785dc67671660d70fb434466fBrian Carlstrom new_offset = offset_ + offset; 36cd60ac736bc7104785dc67671660d70fb434466fBrian Carlstrom break; 37cd60ac736bc7104785dc67671660d70fb434466fBrian Carlstrom } 3849a0f158ed11974fa2cc12014c9f55a31dabd8dfBrian Carlstrom case kSeekEnd: { 39cd60ac736bc7104785dc67671660d70fb434466fBrian Carlstrom new_offset = vector_.size() + offset; 40cd60ac736bc7104785dc67671660d70fb434466fBrian Carlstrom break; 41cd60ac736bc7104785dc67671660d70fb434466fBrian Carlstrom } 42cd60ac736bc7104785dc67671660d70fb434466fBrian Carlstrom } 43cd60ac736bc7104785dc67671660d70fb434466fBrian Carlstrom EnsureCapacity(new_offset); 44cd60ac736bc7104785dc67671660d70fb434466fBrian Carlstrom offset_ = new_offset; 45cd60ac736bc7104785dc67671660d70fb434466fBrian Carlstrom return offset_; 46cd60ac736bc7104785dc67671660d70fb434466fBrian Carlstrom} 47cd60ac736bc7104785dc67671660d70fb434466fBrian Carlstrom 48cd60ac736bc7104785dc67671660d70fb434466fBrian Carlstrom} // namespace art 49