diff options
author | 2015-11-25 14:33:36 +0000 | |
---|---|---|
committer | 2015-11-30 18:19:44 +0000 | |
commit | 10c13565474de2786aad7c2e79757ea250747a15 (patch) | |
tree | 759bdf7aab97ab45e1a3e09f5d627e568f6e7084 /compiler/buffered_output_stream.cc | |
parent | e928dc587718d00d234768f76d1efb2ffe74e885 (diff) |
Refactor oat file writing to give Dex2Oat more control.
This is the first step towards writing dex files to oat file
and mapping them from there for the actual AOT compilation.
Change-Id: Icb0d27487eaf6ba3a66c157e695f9bdc5bb9cf9a
Diffstat (limited to 'compiler/buffered_output_stream.cc')
-rw-r--r-- | compiler/buffered_output_stream.cc | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/compiler/buffered_output_stream.cc b/compiler/buffered_output_stream.cc index 3ca518b686..4c66c764a9 100644 --- a/compiler/buffered_output_stream.cc +++ b/compiler/buffered_output_stream.cc @@ -20,18 +20,24 @@ namespace art { -BufferedOutputStream::BufferedOutputStream(OutputStream* out) - : OutputStream(out->GetLocation()), out_(out), used_(0) {} +BufferedOutputStream::BufferedOutputStream(std::unique_ptr<OutputStream> out) + : OutputStream(out->GetLocation()), // Before out is moved to out_. + out_(std::move(out)), + used_(0) {} + +BufferedOutputStream::~BufferedOutputStream() { + FlushBuffer(); +} bool BufferedOutputStream::WriteFully(const void* buffer, size_t byte_count) { if (byte_count > kBufferSize) { - if (!Flush()) { + if (!FlushBuffer()) { return false; } return out_->WriteFully(buffer, byte_count); } if (used_ + byte_count > kBufferSize) { - if (!Flush()) { + if (!FlushBuffer()) { return false; } } @@ -42,6 +48,10 @@ bool BufferedOutputStream::WriteFully(const void* buffer, size_t byte_count) { } bool BufferedOutputStream::Flush() { + return FlushBuffer() && out_->Flush(); +} + +bool BufferedOutputStream::FlushBuffer() { bool success = true; if (used_ > 0) { success = out_->WriteFully(&buffer_[0], used_); @@ -51,7 +61,7 @@ bool BufferedOutputStream::Flush() { } off_t BufferedOutputStream::Seek(off_t offset, Whence whence) { - if (!Flush()) { + if (!FlushBuffer()) { return -1; } return out_->Seek(offset, whence); |