106460ef0d7072114ea3280e1650f77f55e7223f4Adam Lesinski/*
206460ef0d7072114ea3280e1650f77f55e7223f4Adam Lesinski * Copyright (C) 2017 The Android Open Source Project
306460ef0d7072114ea3280e1650f77f55e7223f4Adam Lesinski *
406460ef0d7072114ea3280e1650f77f55e7223f4Adam Lesinski * Licensed under the Apache License, Version 2.0 (the "License");
506460ef0d7072114ea3280e1650f77f55e7223f4Adam Lesinski * you may not use this file except in compliance with the License.
606460ef0d7072114ea3280e1650f77f55e7223f4Adam Lesinski * You may obtain a copy of the License at
706460ef0d7072114ea3280e1650f77f55e7223f4Adam Lesinski *
806460ef0d7072114ea3280e1650f77f55e7223f4Adam Lesinski *      http://www.apache.org/licenses/LICENSE-2.0
906460ef0d7072114ea3280e1650f77f55e7223f4Adam Lesinski *
1006460ef0d7072114ea3280e1650f77f55e7223f4Adam Lesinski * Unless required by applicable law or agreed to in writing, software
1106460ef0d7072114ea3280e1650f77f55e7223f4Adam Lesinski * distributed under the License is distributed on an "AS IS" BASIS,
1206460ef0d7072114ea3280e1650f77f55e7223f4Adam Lesinski * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1306460ef0d7072114ea3280e1650f77f55e7223f4Adam Lesinski * See the License for the specific language governing permissions and
1406460ef0d7072114ea3280e1650f77f55e7223f4Adam Lesinski * limitations under the License.
1506460ef0d7072114ea3280e1650f77f55e7223f4Adam Lesinski */
1606460ef0d7072114ea3280e1650f77f55e7223f4Adam Lesinski
1706460ef0d7072114ea3280e1650f77f55e7223f4Adam Lesinski#ifndef AAPT_IO_BIGBUFFERINPUTSTREAM_H
1806460ef0d7072114ea3280e1650f77f55e7223f4Adam Lesinski#define AAPT_IO_BIGBUFFERINPUTSTREAM_H
1906460ef0d7072114ea3280e1650f77f55e7223f4Adam Lesinski
2006460ef0d7072114ea3280e1650f77f55e7223f4Adam Lesinski#include "io/Io.h"
2106460ef0d7072114ea3280e1650f77f55e7223f4Adam Lesinski#include "util/BigBuffer.h"
2206460ef0d7072114ea3280e1650f77f55e7223f4Adam Lesinski
2306460ef0d7072114ea3280e1650f77f55e7223f4Adam Lesinskinamespace aapt {
2406460ef0d7072114ea3280e1650f77f55e7223f4Adam Lesinskinamespace io {
2506460ef0d7072114ea3280e1650f77f55e7223f4Adam Lesinski
2606460ef0d7072114ea3280e1650f77f55e7223f4Adam Lesinskiclass BigBufferInputStream : public InputStream {
2706460ef0d7072114ea3280e1650f77f55e7223f4Adam Lesinski public:
2806460ef0d7072114ea3280e1650f77f55e7223f4Adam Lesinski  inline explicit BigBufferInputStream(const BigBuffer* buffer)
2906460ef0d7072114ea3280e1650f77f55e7223f4Adam Lesinski      : buffer_(buffer), iter_(buffer->begin()) {}
3006460ef0d7072114ea3280e1650f77f55e7223f4Adam Lesinski  virtual ~BigBufferInputStream() = default;
3106460ef0d7072114ea3280e1650f77f55e7223f4Adam Lesinski
3206460ef0d7072114ea3280e1650f77f55e7223f4Adam Lesinski  bool Next(const void** data, size_t* size) override;
3306460ef0d7072114ea3280e1650f77f55e7223f4Adam Lesinski
3406460ef0d7072114ea3280e1650f77f55e7223f4Adam Lesinski  void BackUp(size_t count) override;
3506460ef0d7072114ea3280e1650f77f55e7223f4Adam Lesinski
3606460ef0d7072114ea3280e1650f77f55e7223f4Adam Lesinski  bool CanRewind() const override;
3706460ef0d7072114ea3280e1650f77f55e7223f4Adam Lesinski
3806460ef0d7072114ea3280e1650f77f55e7223f4Adam Lesinski  bool Rewind() override;
3906460ef0d7072114ea3280e1650f77f55e7223f4Adam Lesinski
4006460ef0d7072114ea3280e1650f77f55e7223f4Adam Lesinski  size_t ByteCount() const override;
4106460ef0d7072114ea3280e1650f77f55e7223f4Adam Lesinski
4206460ef0d7072114ea3280e1650f77f55e7223f4Adam Lesinski  bool HadError() const override;
4306460ef0d7072114ea3280e1650f77f55e7223f4Adam Lesinski
4406460ef0d7072114ea3280e1650f77f55e7223f4Adam Lesinski private:
4506460ef0d7072114ea3280e1650f77f55e7223f4Adam Lesinski  DISALLOW_COPY_AND_ASSIGN(BigBufferInputStream);
4606460ef0d7072114ea3280e1650f77f55e7223f4Adam Lesinski
4706460ef0d7072114ea3280e1650f77f55e7223f4Adam Lesinski  const BigBuffer* buffer_;
4806460ef0d7072114ea3280e1650f77f55e7223f4Adam Lesinski  BigBuffer::const_iterator iter_;
4906460ef0d7072114ea3280e1650f77f55e7223f4Adam Lesinski  size_t offset_ = 0;
5006460ef0d7072114ea3280e1650f77f55e7223f4Adam Lesinski  size_t bytes_read_ = 0;
5106460ef0d7072114ea3280e1650f77f55e7223f4Adam Lesinski};
5206460ef0d7072114ea3280e1650f77f55e7223f4Adam Lesinski
5306460ef0d7072114ea3280e1650f77f55e7223f4Adam Lesinski}  // namespace io
5406460ef0d7072114ea3280e1650f77f55e7223f4Adam Lesinski}  // namespace aapt
5506460ef0d7072114ea3280e1650f77f55e7223f4Adam Lesinski
5606460ef0d7072114ea3280e1650f77f55e7223f4Adam Lesinski#endif  // AAPT_IO_BIGBUFFERINPUTSTREAM_H
57