Loading...
Searching...
No Matches
juce_FileOutputStream.h
/*
==============================================================================
This file is part of the JUCE library.
Copyright (c) 2022 - Raw Material Software Limited
JUCE is an open source library subject to commercial or open-source
licensing.
The code included in this file is provided under the terms of the ISC license
http://www.isc.org/downloads/software-support-policy/isc-license. Permission
To use, copy, modify, and/or distribute this software for any purpose with or
without fee is hereby granted provided that the above copyright notice and
this permission notice appear in all copies.
JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
DISCLAIMED.
==============================================================================
*/
namespace juce
{
//==============================================================================
class JUCE_API FileOutputStream : public OutputStream
{
public:
//==============================================================================
FileOutputStream (const File& fileToWriteTo,
size_t bufferSizeToUse = 16384);
~FileOutputStream() override;
//==============================================================================
const File& getFile() const { return file; }
const Result& getStatus() const noexcept { return status; }
bool failedToOpen() const noexcept { return status.failed(); }
bool openedOk() const noexcept { return status.wasOk(); }
Result truncate();
//==============================================================================
void flush() override;
int64 getPosition() override;
bool setPosition (int64) override;
bool write (const void*, size_t) override;
bool writeRepeatedByte (uint8 byte, size_t numTimesToRepeat) override;
private:
//==============================================================================
File file;
void* fileHandle = nullptr;
Result status { Result::ok() };
int64 currentPosition = 0;
size_t bufferSize, bytesInBuffer = 0;
HeapBlock<char> buffer;
void openHandle();
void closeHandle();
void flushInternal();
bool flushBuffer();
int64 setPositionInternal (int64);
ssize_t writeInternal (const void*, size_t);
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (FileOutputStream)
};
} // namespace juce
juce::FileOutputStream
Definition juce_FileOutputStream.h:35
juce::FileOutputStream::getStatus
const Result & getStatus() const noexcept
Definition juce_FileOutputStream.h:81
juce::FileOutputStream::writeRepeatedByte
bool writeRepeatedByte(uint8 byte, size_t numTimesToRepeat) override
Definition juce_FileOutputStream.cpp:115
juce::FileOutputStream::write
bool write(const void *, size_t) override
Definition juce_FileOutputStream.cpp:76
juce::FileOutputStream::getFile
const File & getFile() const
Definition juce_FileOutputStream.h:75
juce::FileOutputStream::failedToOpen
bool failedToOpen() const noexcept
Definition juce_FileOutputStream.h:86
juce::FileOutputStream::setPosition
bool setPosition(int64) override
Definition juce_FileOutputStream.cpp:46
juce::FileOutputStream::openedOk
bool openedOk() const noexcept
Definition juce_FileOutputStream.h:91
juce::FileOutputStream::truncate
Result truncate()
juce::FileOutputStream::flush
void flush() override
Definition juce_FileOutputStream.cpp:70
juce::FileOutputStream::getPosition
int64 getPosition() override
Definition juce_FileOutputStream.cpp:41
juce::FileOutputStream::FileOutputStream
FileOutputStream(const File &fileToWriteTo, size_t bufferSizeToUse=16384)
Definition juce_FileOutputStream.cpp:27
juce::File
Definition juce_File.h:45
juce::HeapBlock
Definition juce_HeapBlock.h:87
juce::Result
Definition juce_Result.h:57
juce::Result::ok
static Result ok() noexcept
Definition juce_Result.h:61