blob: 66994e82a1c90ccd86c63bd56cf9e736577e5bd4 [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 {
Vladimir Marko74527972016-11-29 15:57:32 +000027namespace linker {
Brian Carlstromc6dfdac2013-08-26 18:57:31 -070028
Ian Rogers0279ebb2014-10-08 17:27:48 -070029class BufferedOutputStream FINAL : public OutputStream {
Brian Carlstromc6dfdac2013-08-26 18:57:31 -070030 public:
Vladimir Marko10c13562015-11-25 14:33:36 +000031 explicit BufferedOutputStream(std::unique_ptr<OutputStream> out);
Brian Carlstromc6dfdac2013-08-26 18:57:31 -070032
Vladimir Marko10c13562015-11-25 14:33:36 +000033 ~BufferedOutputStream() OVERRIDE;
Brian Carlstromc6dfdac2013-08-26 18:57:31 -070034
Vladimir Marko10c13562015-11-25 14:33:36 +000035 bool WriteFully(const void* buffer, size_t byte_count) OVERRIDE;
Brian Carlstromc6dfdac2013-08-26 18:57:31 -070036
Vladimir Marko10c13562015-11-25 14:33:36 +000037 off_t Seek(off_t offset, Whence whence) OVERRIDE;
Brian Carlstromc6dfdac2013-08-26 18:57:31 -070038
Vladimir Marko10c13562015-11-25 14:33:36 +000039 bool Flush() OVERRIDE;
David Srbecky6d8c8f02015-10-26 10:57:09 +000040
Brian Carlstromc6dfdac2013-08-26 18:57:31 -070041 private:
42 static const size_t kBufferSize = 8 * KB;
43
Vladimir Marko10c13562015-11-25 14:33:36 +000044 bool FlushBuffer();
Brian Carlstromc6dfdac2013-08-26 18:57:31 -070045
Vladimir Marko10c13562015-11-25 14:33:36 +000046 std::unique_ptr<OutputStream> const out_;
Brian Carlstromc6dfdac2013-08-26 18:57:31 -070047 uint8_t buffer_[kBufferSize];
Brian Carlstromc6dfdac2013-08-26 18:57:31 -070048 size_t used_;
49
50 DISALLOW_COPY_AND_ASSIGN(BufferedOutputStream);
51};
52
Vladimir Marko74527972016-11-29 15:57:32 +000053} // namespace linker
Brian Carlstromc6dfdac2013-08-26 18:57:31 -070054} // namespace art
55
Vladimir Marko131980f2015-12-03 18:29:23 +000056#endif // ART_COMPILER_LINKER_BUFFERED_OUTPUT_STREAM_H_