summaryrefslogtreecommitdiff
path: root/compiler/buffered_output_stream.cc
diff options
context:
space:
mode:
author Vladimir Marko <vmarko@google.com> 2015-12-01 10:16:19 +0000
committer Gerrit Code Review <noreply-gerritcodereview@google.com> 2015-12-01 10:16:19 +0000
commitd1744d449cf2b56af7e0896b3729fac2a414e3af (patch)
treecd23e1e0a3cea10cc9a9ae8269a01f75ada8ef0e /compiler/buffered_output_stream.cc
parente51e3f988ba91f0469757738fa55f835e16e37d9 (diff)
parent10c13565474de2786aad7c2e79757ea250747a15 (diff)
Merge "Refactor oat file writing to give Dex2Oat more control."
Diffstat (limited to 'compiler/buffered_output_stream.cc')
-rw-r--r--compiler/buffered_output_stream.cc20
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);