19 #ifndef avro_Stream_hh__    20 #define avro_Stream_hh__    26 #include "boost/utility.hpp"    29 #include "Exception.hh"    56     virtual bool next(
const uint8_t** data, 
size_t* len) = 0;
    63     virtual void backup(
size_t len) = 0;
    68     virtual void skip(
size_t len) = 0;
    75     virtual size_t byteCount() 
const = 0;
    78 typedef std::unique_ptr<InputStream> InputStreamPtr;
   102     virtual void seek(int64_t position) = 0;
   105 typedef std::unique_ptr<SeekableInputStream> SeekableInputStreamPtr;
   129     virtual bool next(uint8_t** data, 
size_t* len) = 0;
   135     virtual void backup(
size_t len) = 0;
   142     virtual uint64_t byteCount() 
const = 0;
   148     virtual void flush() = 0;
   151 typedef std::unique_ptr<OutputStream> OutputStreamPtr;
   189     size_t bufferSize = 8 * 1024);
   196     const char *filename, 
size_t bufferSize = 8 * 1024);
   197 AVRO_DECL SeekableInputStreamPtr fileSeekableInputStream(
   198     const char *filename, 
size_t bufferSize = 8 * 1024);
   206     size_t bufferSize = 8 * 1024);
   214     std::istream &in, 
size_t bufferSize = 8 * 1024);
   227     std::istream& is, 
size_t bufferSize = 8 * 1024);
   262         if (in_ != 0 && end_ != next_) {
   263             in_->
backup(end_ - next_);
   289             size_t q = end_ - next_;
   293             ::memcpy(b, next_, q);
   305         if (n > static_cast<size_t>(end_ - next_)) {
   322         while (in_->
next(&next_, &n)) {
   344         return (next_ == end_) ? fill() : 
true;
   355         in_->
backup(end_ - next_);
   394         if (out_ != 0 && end_ != next_) {
   395             out_->
backup(end_ - next_);
   419             size_t q = end_ - next_;
   423             ::memcpy(next_, b, q);
   436             out_->
backup(end_ - next_);
   455         while (out_->
next(&next_, &n)) {
   471     const uint8_t *p = 0;
   474     while (in.
next(&p, &n)) {
 void copy(InputStream &in, OutputStream &out)
A convenience function to copy all the contents of an input stream into an output stream...
Definition: Stream.hh:469
 
StreamWriter(OutputStream &out)
Constructs a new writer with the given underlying stream. 
Definition: Stream.hh:387
 
AVRO_DECL OutputStreamPtr memoryOutputStream(size_t chunkSize=4 *1024)
Returns a new OutputStream, which grows in memory chunks of specified size. 
 
const uint8_t * next_
The next location to read from. 
Definition: Stream.hh:240
 
int64_t byteCount() const
Return the number of bytes written so far. 
Definition: Stream.hh:446
 
void flush()
backs up upto the currently written data and flushes the underlying stream. 
Definition: Stream.hh:434
 
StreamReader(InputStream &in)
Constructs a reader with the given underlying stream. 
Definition: Stream.hh:255
 
uint8_t * end_
One past the last location one can write to. 
Definition: Stream.hh:377
 
StreamReader()
Constructs an empty reader. 
Definition: Stream.hh:250
 
virtual uint64_t byteCount() const =0
Number of bytes written so far into this stream. 
 
A bunch of templates and specializations for encoding and decoding specific types. 
Definition: AvroParse.hh:30
 
void skipBytes(size_t n)
Skips the given number of bytes. 
Definition: Stream.hh:304
 
void writeBytes(const uint8_t *b, size_t n)
Writes the specified number of bytes starting at b. 
Definition: Stream.hh:414
 
void readBytes(uint8_t *b, size_t n)
Reads the given number of bytes from the underlying stream. 
Definition: Stream.hh:284
 
bool hasMore()
Returns true if and only if the end of stream is not reached. 
Definition: Stream.hh:343
 
void more()
Gets more space to write to. 
Definition: Stream.hh:453
 
InputStream * in_
The underlying input stream. 
Definition: Stream.hh:235
 
void drain(bool unRead)
Returns unused bytes back to the underlying stream. 
Definition: Stream.hh:351
 
void write(uint8_t c)
Writes a single byte. 
Definition: Stream.hh:404
 
StreamWriter()
Constructs a writer with no underlying stream. 
Definition: Stream.hh:382
 
virtual bool next(uint8_t **data, size_t *len)=0
Returns a buffer that can be written into. 
 
void reset(OutputStream &os)
Replaces the current underlying stream with a new one. 
Definition: Stream.hh:393
 
virtual void backup(size_t len)=0
"Returns" back to the stream some of the buffer obtained from in the last call to next()...
 
AVRO_DECL InputStreamPtr nonSeekableIstreamInputStream(std::istream &is, size_t bufferSize=8 *1024)
Returns a new InputStream whose contents come from the given std::istream. 
 
AVRO_DECL OutputStreamPtr fileOutputStream(const char *filename, size_t bufferSize=8 *1024)
Returns a new OutputStream whose contents would be stored in a file. 
 
const uint8_t * end_
One past the last valid location. 
Definition: Stream.hh:245
 
uint8_t * next_
The next location to write to. 
Definition: Stream.hh:372
 
void reset(InputStream &is)
Replaces the current input stream with the given one after backing up the original one if required...
Definition: Stream.hh:261
 
A convenience class for reading from an InputStream. 
Definition: Stream.hh:231
 
AVRO_DECL InputStreamPtr fileInputStream(const char *filename, size_t bufferSize=8 *1024)
Returns a new InputStream whose contents come from the given file. 
 
A no-copy output stream. 
Definition: Stream.hh:110
 
Wrapper for std::runtime_error that provides convenience constructor for boost::format objects...
Definition: Exception.hh:31
 
AVRO_DECL std::shared_ptr< std::vector< uint8_t > > snapshot(const OutputStream &source)
Returns the contents written so far into the output stream, which should be a memory output stream...
 
AVRO_DECL InputStreamPtr istreamInputStream(std::istream &in, size_t bufferSize=8 *1024)
Returns a new InputStream whose contents come from the given std::istream. 
 
bool fill()
Get as many byes from the underlying stream as possible in a single chunk. 
Definition: Stream.hh:320
 
virtual void flush()=0
Flushes any data remaining in the buffer to the stream's underlying store, if any. 
 
OutputStream()
An empty constuctor. 
Definition: Stream.hh:116
 
OutputStream * out_
The underlying output stream for this writer. 
Definition: Stream.hh:367
 
AVRO_DECL OutputStreamPtr ostreamOutputStream(std::ostream &os, size_t bufferSize=8 *1024)
Returns a new OutputStream whose contents will be sent to the given std::ostream. ...
 
AVRO_DECL InputStreamPtr memoryInputStream(const uint8_t *data, size_t len)
Returns a new InputStream, with the data from the given byte array. 
 
A convinience class to write data into an OutputStream. 
Definition: Stream.hh:363
 
void more()
Tries to get more data and if it cannot, throws an exception. 
Definition: Stream.hh:334
 
virtual ~OutputStream()
Destructor. 
Definition: Stream.hh:122
 
uint8_t read()
Read just one byte from the underlying stream. 
Definition: Stream.hh:273