• 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 #pragma once
18 
19 #include "BigBuffer.h"
20 #include "Streams.h"
21 
22 namespace android {
23 
24 class BigBufferInputStream : public KnownSizeInputStream {
25  public:
BigBufferInputStream(const BigBuffer * buffer)26   inline explicit BigBufferInputStream(const BigBuffer* buffer)
27       : owning_buffer_(0), buffer_(buffer), iter_(buffer->begin()) {
28   }
29 
BigBufferInputStream(android::BigBuffer && buffer)30   inline explicit BigBufferInputStream(android::BigBuffer&& buffer)
31       : owning_buffer_(std::move(buffer)), buffer_(&owning_buffer_), iter_(buffer_->begin()) {
32   }
33 
34   virtual ~BigBufferInputStream() = default;
35 
36   bool Next(const void** data, size_t* size) override;
37 
38   void BackUp(size_t count) override;
39 
40   bool CanRewind() const override;
41 
42   bool Rewind() override;
43 
44   size_t ByteCount() const override;
45 
46   bool HadError() const override;
47 
48   size_t TotalSize() const override;
49 
50   bool ReadFullyAtOffset(void* data, size_t byte_count, off64_t offset) override;
51 
52  private:
53   DISALLOW_COPY_AND_ASSIGN(BigBufferInputStream);
54 
55   android::BigBuffer owning_buffer_;
56   const BigBuffer* buffer_;
57   BigBuffer::const_iterator iter_;
58   size_t offset_ = 0;
59   size_t bytes_read_ = 0;
60 };
61 
62 class BigBufferOutputStream : public OutputStream {
63  public:
BigBufferOutputStream(BigBuffer * buffer)64   inline explicit BigBufferOutputStream(BigBuffer* buffer) : buffer_(buffer) {
65   }
66   virtual ~BigBufferOutputStream() = default;
67 
68   bool Next(void** data, size_t* size) override;
69 
70   void BackUp(size_t count) override;
71 
72   size_t ByteCount() const override;
73 
74   bool HadError() const override;
75 
76  private:
77   DISALLOW_COPY_AND_ASSIGN(BigBufferOutputStream);
78 
79   BigBuffer* buffer_;
80 };
81 
82 }  // namespace android