BusBoy
2
|
Content of a file. More...
#include <DataFile.h>
Public Types | |
enum | Allocation { MALLOC, NEW } |
Public Member Functions | |
DataFile (char *bytes, size_t size, const std::string &contentType, Allocation alloc=NEW) | |
Create a new data file. More... | |
DataFile (std::shared_ptr< DataFileSource > &src, const std::string &contentType) | |
Create a new data file. More... | |
DataFile (const std::string &path, const std::string &contentType) | |
Create a new data file from a file on local disk. More... | |
DataFile (const std::string &contentType) | |
Create a new data file for chunked writing. More... | |
void | setFileSource (std::shared_ptr< DataFileSource > &src) |
For use by the framework after deserialization. More... | |
std::shared_ptr< DataFileSource > | getFileSource () |
For use by the framework during serialization. More... | |
void | setFileSink (DataFileSink *sink) |
For use by the framework. More... | |
DataFileSink * | getFileSink () |
For use by the framework. More... | |
std::string | getFileName () |
For input datasets only, returns the name of actual file on disk. More... | |
void | setFileName (const std::string &name) |
For use by the framework after deserialization. More... | |
bool | hasFileSource () const |
Returns true if a file source was assigned. More... | |
bool | hasFileSink () const |
Returns true if a file sink was assigned. More... | |
std::string | getContentType () const |
char * | getBytes () const |
Will throw exception if hasContent()==false. More... | |
size_t | getSize () const |
Will throw exception if hasContent()==false. More... | |
size_t | read (char *buf, size_t num) |
Reads the next chunk of the file. More... | |
size_t | skip (size_t num) |
Skips forward in the file Returns the number of bytes actually skipped. More... | |
void | write (char *buf, size_t num) |
Writes the next chunk of the file. More... | |
void | release () |
Free the memory containing the file bytes. More... | |
bool | hasContent () const |
Returns true if the DataFile is in a state that allows accessing content. More... | |
std::unique_lock < std::recursive_mutex > | getLock (bool doAcquire=true) |
Framework only: Returns a unique_lock with ownership over the DataFile's mutex object. More... | |
bool | operator== (const DataFile &file) const |
bool | operator!= (const DataFile &file) const |
~DataFile () | |
Content of a file.
Consists of bytes and a MIME content type.
BUSBOY::DataFile::DataFile | ( | char * | bytes, |
size_t | size, | ||
const std::string & | contentType, | ||
Allocation | alloc = NEW |
||
) |
Create a new data file.
The byte array must be allocated on the heap. This class takes ownership of the byte array.
alloc | Indicate if malloc or new was used to allocate the array. |
BUSBOY::DataFile::DataFile | ( | std::shared_ptr< DataFileSource > & | src, |
const std::string & | contentType | ||
) |
Create a new data file.
The DataFileSource is responsible for managing the underlying data
BUSBOY::DataFile::DataFile | ( | const std::string & | path, |
const std::string & | contentType | ||
) |
Create a new data file from a file on local disk.
All content should be in the file BEFORE the DataFile object is instantiated.
path | Path to the local file. |
BUSBOY::DataFile::DataFile | ( | const std::string & | contentType | ) |
Create a new data file for chunked writing.
BUSBOY::DataFile::~DataFile | ( | ) |
char * BUSBOY::DataFile::getBytes | ( | ) | const |
Will throw exception if hasContent()==false.
std::string BUSBOY::DataFile::getContentType | ( | ) | const |
std::string BUSBOY::DataFile::getFileName | ( | ) |
For input datasets only, returns the name of actual file on disk.
DataFileSink * BUSBOY::DataFile::getFileSink | ( | ) |
For use by the framework.
shared_ptr< DataFileSource > BUSBOY::DataFile::getFileSource | ( | ) |
For use by the framework during serialization.
std::unique_lock< std::recursive_mutex > BUSBOY::DataFile::getLock | ( | bool | doAcquire = true | ) |
Framework only: Returns a unique_lock with ownership over the DataFile's mutex object.
The lock is released either on destruction or by explicitly calling the .unlock() method. Call with doAcquire=false to return a lock without attempting to acquire it.
size_t BUSBOY::DataFile::getSize | ( | ) | const |
Will throw exception if hasContent()==false.
bool BUSBOY::DataFile::hasContent | ( | ) | const |
Returns true if the DataFile is in a state that allows accessing content.
bool BUSBOY::DataFile::hasFileSink | ( | ) | const |
Returns true if a file sink was assigned.
bool BUSBOY::DataFile::hasFileSource | ( | ) | const |
Returns true if a file source was assigned.
bool BUSBOY::DataFile::operator!= | ( | const DataFile & | file | ) | const |
bool BUSBOY::DataFile::operator== | ( | const DataFile & | file | ) | const |
size_t BUSBOY::DataFile::read | ( | char * | buf, |
size_t | num | ||
) |
Reads the next chunk of the file.
Returns the number of bytes actually read. Returns 0 for EOF reached. Call release() to close the underlying resource if a series of calls will not go to EOF. Will throw exception if hasContent()==false.
void BUSBOY::DataFile::release | ( | ) |
Free the memory containing the file bytes.
Subsequent calls to read(), getBytes() and getSize() will fail.
void BUSBOY::DataFile::setFileName | ( | const std::string & | name | ) |
For use by the framework after deserialization.
void BUSBOY::DataFile::setFileSink | ( | DataFileSink * | sink | ) |
For use by the framework.
void BUSBOY::DataFile::setFileSource | ( | std::shared_ptr< DataFileSource > & | src | ) |
For use by the framework after deserialization.
size_t BUSBOY::DataFile::skip | ( | size_t | num | ) |
Skips forward in the file Returns the number of bytes actually skipped.
Will throw exception if hasContent()==false.
void BUSBOY::DataFile::write | ( | char * | buf, |
size_t | num | ||
) |
Writes the next chunk of the file.
Copyright 2014 Google Inc. All rights reserved.