1#include <string>
2
3#include <IO/ReadBufferFromFileDescriptor.h>
4#include <IO/LimitReadBuffer.h>
5#include <IO/WriteBufferFromFileDescriptor.h>
6#include <IO/copyData.h>
7#include <IO/WriteHelpers.h>
8
9
10int main(int argc, char ** argv)
11{
12 using namespace DB;
13
14 if (argc < 2)
15 {
16 std::cerr << "Usage: program limit < in > out\n";
17 return 1;
18 }
19
20 UInt64 limit = std::stol(argv[1]);
21
22 ReadBufferFromFileDescriptor in(STDIN_FILENO);
23 WriteBufferFromFileDescriptor out(STDOUT_FILENO);
24
25 writeCString("--- first ---\n", out);
26 {
27 LimitReadBuffer limit_in(in, limit, false);
28 copyData(limit_in, out);
29 }
30
31 writeCString("\n--- second ---\n", out);
32 {
33 LimitReadBuffer limit_in(in, limit, false);
34 copyData(limit_in, out);
35 }
36
37 writeCString("\n--- the rest ---\n", out);
38 copyData(in, out);
39
40 return 0;
41}
42