• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 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/BigBufferInputStream.h"
18 #include "io/BigBufferOutputStream.h"
19 
20 namespace aapt {
21 namespace io {
22 
23 //
24 // BigBufferInputStream
25 //
26 
Next(const void ** data,size_t * size)27 bool BigBufferInputStream::Next(const void** data, size_t* size) {
28   if (iter_ == buffer_->end()) {
29     return false;
30   }
31 
32   if (offset_ == iter_->size) {
33     ++iter_;
34     if (iter_ == buffer_->end()) {
35       return false;
36     }
37     offset_ = 0;
38   }
39 
40   *data = iter_->buffer.get() + offset_;
41   *size = iter_->size - offset_;
42   bytes_read_ += iter_->size - offset_;
43   offset_ = iter_->size;
44   return true;
45 }
46 
BackUp(size_t count)47 void BigBufferInputStream::BackUp(size_t count) {
48   if (count > offset_) {
49     bytes_read_ -= offset_;
50     offset_ = 0;
51   } else {
52     offset_ -= count;
53     bytes_read_ -= count;
54   }
55 }
56 
CanRewind() const57 bool BigBufferInputStream::CanRewind() const { return true; }
58 
Rewind()59 bool BigBufferInputStream::Rewind() {
60   iter_ = buffer_->begin();
61   offset_ = 0;
62   bytes_read_ = 0;
63   return true;
64 }
65 
ByteCount() const66 size_t BigBufferInputStream::ByteCount() const { return bytes_read_; }
67 
HadError() const68 bool BigBufferInputStream::HadError() const { return false; }
69 
70 //
71 // BigBufferOutputStream
72 //
73 
Next(void ** data,size_t * size)74 bool BigBufferOutputStream::Next(void** data, size_t* size) {
75   *data = buffer_->NextBlock(size);
76   return true;
77 }
78 
BackUp(size_t count)79 void BigBufferOutputStream::BackUp(size_t count) { buffer_->BackUp(count); }
80 
ByteCount() const81 size_t BigBufferOutputStream::ByteCount() const { return buffer_->size(); }
82 
HadError() const83 bool BigBufferOutputStream::HadError() const { return false; }
84 
85 }  // namespace io
86 }  // namespace aapt
87