blob: a2eefbbf175c08f4960ab3a20653bdc8d48a0c6e [file] [log] [blame]
Brian Carlstromc6dfdac2013-08-26 18:57:31 -07001/*
2 * Copyright (C) 2013 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
Vladimir Marko131980f2015-12-03 18:29:23 +000017#ifndef ART_COMPILER_LINKER_BUFFERED_OUTPUT_STREAM_H_
18#define ART_COMPILER_LINKER_BUFFERED_OUTPUT_STREAM_H_
Brian Carlstromc6dfdac2013-08-26 18:57:31 -070019
Vladimir Marko10c13562015-11-25 14:33:36 +000020#include <memory>
21
Brian Carlstromc6dfdac2013-08-26 18:57:31 -070022#include "output_stream.h"
23
24#include "globals.h"
25
26namespace art {
27
Ian Rogers0279ebb2014-10-08 17:27:48 -070028class BufferedOutputStream FINAL : public OutputStream {
Brian Carlstromc6dfdac2013-08-26 18:57:31 -070029 public:
Vladimir Marko10c13562015-11-25 14:33:36 +000030 explicit BufferedOutputStream(std::unique_ptr<OutputStream> out);
Brian Carlstromc6dfdac2013-08-26 18:57:31 -070031
Vladimir Marko10c13562015-11-25 14:33:36 +000032 ~BufferedOutputStream() OVERRIDE;
Brian Carlstromc6dfdac2013-08-26 18:57:31 -070033
Vladimir Marko10c13562015-11-25 14:33:36 +000034 bool WriteFully(const void* buffer, size_t byte_count) OVERRIDE;
Brian Carlstromc6dfdac2013-08-26 18:57:31 -070035
Vladimir Marko10c13562015-11-25 14:33:36 +000036 off_t Seek(off_t offset, Whence whence) OVERRIDE;
Brian Carlstromc6dfdac2013-08-26 18:57:31 -070037
Vladimir Marko10c13562015-11-25 14:33:36 +000038 bool Flush() OVERRIDE;
David Srbecky6d8c8f02015-10-26 10:57:09 +000039
Brian Carlstromc6dfdac2013-08-26 18:57:31 -070040 private:
41 static const size_t kBufferSize = 8 * KB;
42
Vladimir Marko10c13562015-11-25 14:33:36 +000043 bool FlushBuffer();
Brian Carlstromc6dfdac2013-08-26 18:57:31 -070044
Vladimir Marko10c13562015-11-25 14:33:36 +000045 std::unique_ptr<OutputStream> const out_;
Brian Carlstromc6dfdac2013-08-26 18:57:31 -070046 uint8_t buffer_[kBufferSize];
Brian Carlstromc6dfdac2013-08-26 18:57:31 -070047 size_t used_;
48
49 DISALLOW_COPY_AND_ASSIGN(BufferedOutputStream);
50};
51
52} // namespace art
53
Vladimir Marko131980f2015-12-03 18:29:23 +000054#endif // ART_COMPILER_LINKER_BUFFERED_OUTPUT_STREAM_H_