Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members  

BufferedInputStream

00001 /*
00002  * NOTE: "zlib/libpng" style License
00003  *
00004  *                 ----=== s t d n e t ===----
00005  *
00006  * Copyright (c) 2002 Warwick Molloy   w-molloy@users.sf.net
00007  *
00008  * Copyright (c) 2002 Stdnet Community
00009  * HTTP://Sourceforge.net/projects/stdnet
00010  *
00011  * All references to "software" refer to the stdnet.
00012  *
00013  * This software is provided 'as-is', without any express or
00014  * implied warranty. In no event will the authors be held liable
00015  * for any damages arising from the use of this software.
00016  *
00017  * Permission is granted to anyone to use this software for any
00018  * purpose, including commercial applications, and to alter it
00019  * and redistribute it freely, subject to the following
00020  * restrictions:
00021  *
00022  * 1.  The origin of this software must not be misrepresented;
00023  *     you must not claim that you wrote the original software.
00024  *     If you use this software in a product, an acknowledgment
00025  *     in the product documentation would be appreciated but
00026  *     is not required.
00027  *
00028  * 2.  Altered source versions must be plainly marked as such,
00029  *     and must not be misrepresented as being the original
00030  *     software.
00031  *
00032  * 3.  This notice may not be removed or altered from any source
00033  *     distribution.
00034  */
00035 
00036 #ifndef __io_BufferedInputStream__
00037 #define __io_BufferedInputStream__
00038 
00039 #include <stdnet/system/Abstract>
00040 #include <stdnet/io/IOException>
00041 #include <stdnet/io/FilterInputStream>
00042 #include <stdnet/config.h>
00043 
00044 namespace stdbase {
00045     namespace io {
00046 
00054 class BufferedInputStream
00055     : public FilterInputStream
00056 {
00057 protected:
00058     BufferedInputStream( InputStreamRef input);
00059     virtual ~BufferedInputStream() {};
00060 
00061 public:
00062     static system::reference< BufferedInputStream >
00063         create( InputStreamRef r);
00064 
00065     virtual int
00066         available() throw (IOException);
00067     
00071     //virtual void
00072     //    close() throw (IOException);
00073 
00082     virtual void
00083         mark( int readlimit);
00084 
00093     virtual void
00094         reset() throw (IOException);
00095 
00100     virtual bool
00101         markSupported();
00102 
00106     virtual int
00107         read( byte buffer[], int len) throw (IOException);
00108         
00115     virtual int
00116         read() throw (IOException);
00117 
00123     //virtual long
00124     //    skip( long n ) throw (IOException);
00125 
00126 private:
00127     void    prepare_buffer() throw (IOException);
00128 
00129     void    advance_start_pos( int count) throw (IOException);
00130 
00131 private:
00132     enum {  
00133         BUFFER_MAX = 2048,
00134         BUFF_CHUNK = 512
00135     };
00136 
00137     char    buffer[ BUFFER_MAX ];
00138     int     start_pos;
00139     int     end_pos;
00140     int     mark_pos;
00141     int     mark_read_limit;
00142     int     mark_read_count;
00143 
00144     enum {
00145         MARK_READ_LIMIT_NULL = 0,
00146         MARK_READ_LIMIT_EXCEEDED = -1,
00147         MARK_POS_UNSET = -1,
00148         MARK_POS_OVERWRITTEN = -2
00149     };
00150 };
00151 
00152 typedef system::reference< BufferedInputStream >
00153             BufferedInputStreamRef;
00154 
00155 
00156     } // -- end io --
00157 } // -- end stdbase --
00158 
00159 #endif  //  __io_BufferedInputStream__
00160 

Generated at Tue Aug 13 14:19:39 2002 for stdnet2 by doxygen1.2.9.1 written by Dimitri van Heesch, © 1997-2001