blob: 5befa717e8a0183c666af9a37be5d7ab71a6c716 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
#ifndef __SPOOLREWINDINPUTSTREAM_H
#define __SPOOLREWINDINPUTSTREAM_H
#include "RewindInputStream.hpp"
#include <iostream>
#include <fstream>
#include <vector>
class spool_streambuf : public std::streambuf
{
public:
explicit CRAWLER_DLL_VISIBLE spool_streambuf( size_t bufSize = 256, size_t putBack = 1, size_t spoolBufSize = 8192 );
CRAWLER_DLL_VISIBLE ~spool_streambuf( );
CRAWLER_DLL_VISIBLE void rewind( );
protected:
CRAWLER_DLL_VISIBLE virtual std::streambuf::int_type readFromSource( ) = 0;
CRAWLER_DLL_VISIBLE std::streambuf::int_type spoolSourceData( char *data, size_t n );
private:
CRAWLER_DLL_VISIBLE int_type underflow( );
CRAWLER_DLL_VISIBLE void spoolData( char *data, size_t n );
private:
const size_t m_putBack;
std::vector<char> m_spoolBuf;
size_t m_spoolBufPos;
size_t m_spoolBufSize;
std::fstream m_spoolFile;
enum { TO_SPOOL_MEMORY = 1, TO_SPOOL_FILE = 2, FROM_SPOOL_MEMORY = 3, FROM_SPOOL_FILE = 4 } m_state;
protected:
std::vector<char> m_buf;
char *m_base;
char *m_start;
};
class SpoolRewindInputStream : public RewindInputStream
{
public:
CRAWLER_DLL_VISIBLE SpoolRewindInputStream( const URL &url );
CRAWLER_DLL_VISIBLE virtual ~SpoolRewindInputStream( );
CRAWLER_DLL_VISIBLE virtual void rewind( );
protected:
spool_streambuf *m_buf;
};
#endif
|