diff options
Diffstat (limited to 'src/stable/stream.cpp')
-rw-r--r-- | src/stable/stream.cpp | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/src/stable/stream.cpp b/src/stable/stream.cpp new file mode 100644 index 0000000..58641cc --- /dev/null +++ b/src/stable/stream.cpp | |||
@@ -0,0 +1,53 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2007-2011 Xagasoft, All rights reserved. | ||
3 | * | ||
4 | * This file is part of the libbu++ library and is released under the | ||
5 | * terms of the license contained in the file LICENSE. | ||
6 | */ | ||
7 | |||
8 | #include "bu/stream.h" | ||
9 | |||
10 | Bu::Stream::Stream() | ||
11 | { | ||
12 | } | ||
13 | |||
14 | Bu::Stream::~Stream() | ||
15 | { | ||
16 | } | ||
17 | |||
18 | Bu::String Bu::Stream::readLine() | ||
19 | { | ||
20 | Bu::String sRet; | ||
21 | |||
22 | for(;;) | ||
23 | { | ||
24 | char s; | ||
25 | if( read( &s, 1 ) == 0 ) | ||
26 | return sRet; | ||
27 | if( s == '\n' || s == '\r' ) | ||
28 | return sRet; | ||
29 | sRet.append( s ); | ||
30 | } | ||
31 | } | ||
32 | |||
33 | Bu::String Bu::Stream::readAll() | ||
34 | { | ||
35 | Bu::String sRet; | ||
36 | char buf[4096]; | ||
37 | |||
38 | while( !isEos() ) | ||
39 | { | ||
40 | int iRead = read( buf, 4096 ); | ||
41 | if( iRead == 0 ) | ||
42 | return sRet; | ||
43 | sRet.append( buf, iRead ); | ||
44 | } | ||
45 | |||
46 | return sRet; | ||
47 | } | ||
48 | |||
49 | Bu::size Bu::Stream::write( const Bu::String &sBuf ) | ||
50 | { | ||
51 | return write( sBuf.getStr(), sBuf.getSize() ); | ||
52 | } | ||
53 | |||