/usr/include/CLucene/util/CLStreams.h is in libclucene-dev 2.3.3.4+dfsg-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 | /*------------------------------------------------------------------------------
* Copyright (C) 2003-2006 Ben van Klinken and the CLucene Team
*
* Distributable under the terms of either the Apache License (Version 2.0) or
* the GNU Lesser General Public License, as specified in the COPYING file.
------------------------------------------------------------------------------*/
#ifndef _lucene_util_CLStreams_
#define _lucene_util_CLStreams_
CL_NS_DEF(util)
template <typename T>
class CLUCENE_EXPORT CLStream{
public:
virtual ~CLStream(){}
inline int read(){
const T* buffer;
const int32_t nread = read(buffer,1, 1);
if ( nread < 0 )
return -1;
else
return buffer[0];
}
/** Read one line, return the length of the line read.
* If the string is longer than len, only len of that line will be copied
*/
inline int32_t readLine(T* buffer, size_t len){
size_t i = 0;
while (true && i<len-1) {
int32_t b = read();
if (b < 1)
break;
if (b == '\n' || b == '\r') {
if (i > 0)
break;
else
continue;
}
buffer[i++] = b;
}
buffer[i] = 0;
return i;
}
/**
* @brief Reads items from the stream and sets @p start to point to
* the first item that was read.
*
* Note: unless stated otherwise in the documentation for that method,
* this pointer will no longer be valid after calling another method of
* this class. The pointer will also no longer be valid after the class
* is destroyed.
*
* At least @p min items will be read from the stream, unless an error occurs
* or the end of the stream is reached. Under no circumstances will more than
* @p max items be read.
*
* If the end of the stream is reached before @p min items are read, the
* read is still considered successful and the number of items read will
* be returned.
*
* @param start pointer passed by reference that will be set to point to
* the retrieved array of items. If the end of the stream
* is encountered or an error occurs, the value of @p start
* is undefined
* @param min the minimal number of items to read from the stream. This
* value should be larger than 0. If it is 0 or smaller, the
* result is undefined
* @param max the maximal number of items to read from the stream.
* If this value is smaller than @p min, there is no limit on
* the number of items that can be read
* @return the number of items that were read. @c -1 is returned if
* end of the stream has already been reached. An error is thrown
* if an error occurs.
**/
virtual int32_t read(const T*& start, int32_t min, int32_t max) = 0;
/**
* @brief Skip @p ntoskip items.
*
* If an error occurs, or the end of the stream is encountered, fewer
* than @p ntoskip items may be skipped. This can be checked by comparing
* the return value to @p ntoskip.
*
* Calling this function invalidates the data pointer that was obtained from
* StreamBase::read.
*
* @param ntoskip the number of items that should be skipped
* @return the number of items skipped
**/
virtual int64_t skip(int64_t ntoskip) = 0;
/**
* @brief Get the current position in the stream.
* The value obtained from this function can be used to reset the stream.
**/
virtual int64_t position() = 0;
int64_t getPosition(){ return this->position(); }
virtual size_t size() = 0;
};
template <class T>
class CLUCENE_EXPORT BufferedStream{
public:
virtual ~BufferedStream(){}
/**
* @brief Repositions this stream to a given position.
*
* A call to reset is only guaranteed to be successful when
* the requested position lies within the segment of a stream
* corresponding to a valid pointer obtained from read.
* In this case, the pointer will not be invalidated.
*
* Calling this function invalidates the data pointer that was obtained from
* StreamBase::read unless the conditions outlined above apply.
*
* To read n items, leaving the stream at the same position as before, you
* can do the following:
* @code
* int64_t start = stream.position();
* if ( stream.read(data, min, max) > 0 ) {
* stream.reset(start);
* // The data pointer is still valid here
* }
* @endcode
*
* @param pos the position in the stream you want to go to, relative to
* the start of the stream
* @return the new position in the stream
**/
virtual int64_t reset(int64_t) = 0;
/**
* @brief Sets the minimum size of the buffer
*/
virtual void setMinBufSize(int32_t s) = 0;
};
class BufferedReader;
class CLUCENE_EXPORT Reader: public CLStream<TCHAR>{
public:
~Reader(){}
virtual BufferedReader* __asBufferedReader(){ return NULL; }
};
class CLUCENE_EXPORT BufferedReader: public Reader, public BufferedStream<TCHAR>{
public:
_CL_DEPRECATED( setMinBufSize ) int64_t mark(int32_t readAheadlimit){
this->setMinBufSize(readAheadlimit);
return this->position();
}
~BufferedReader(){}
BufferedReader* __asBufferedReader(){ return this; }
};
typedef CLStream<signed char> InputStream;
class CLUCENE_EXPORT BufferedInputStream: public InputStream, public BufferedStream<signed char>{
public:
virtual ~BufferedInputStream(){}
};
class CLUCENE_EXPORT FilteredBufferedReader: public BufferedReader{
class Internal;
Internal* _internal;
public:
FilteredBufferedReader(Reader* reader, bool deleteReader);
virtual ~FilteredBufferedReader();
int32_t read(const TCHAR*& start, int32_t min, int32_t max);
int64_t position();
int64_t reset(int64_t);
int64_t skip(int64_t ntoskip);
size_t size();
void setMinBufSize(int32_t minbufsize);
};
class CLUCENE_EXPORT FilteredBufferedInputStream: public BufferedInputStream{
class Internal;
Internal* _internal;
public:
FilteredBufferedInputStream(InputStream* input, bool deleteInput);
virtual ~FilteredBufferedInputStream();
int32_t read(const signed char*& start, int32_t min, int32_t max);
int64_t position();
int64_t reset(int64_t);
int64_t skip(int64_t ntoskip);
size_t size();
void setMinBufSize(int32_t minbufsize);
};
class CLUCENE_EXPORT StringReader: public BufferedReader{
protected:
const TCHAR* value;
bool ownValue;
int64_t pos;
size_t m_size;
size_t buffer_size;
public:
StringReader ( const TCHAR* value, const int32_t length = -1, bool copyData = true );
void init ( const TCHAR* value, const int32_t length, bool copyData = true );
virtual ~StringReader();
int32_t read(const TCHAR*& start, int32_t min, int32_t max);
int64_t position();
int64_t reset(int64_t);
int64_t skip(int64_t ntoskip);
void setMinBufSize(int32_t s);
size_t size();
};
class CLUCENE_EXPORT AStringReader: public BufferedInputStream{
signed char* value;
bool ownValue;
int64_t pos;
protected:
size_t m_size;
public:
AStringReader ( const char* value, const int32_t length = -1 );
AStringReader ( char* value, const int32_t length, bool copyData = true );
virtual ~AStringReader();
int32_t read(const signed char*& start, int32_t min, int32_t max);
int32_t read(const unsigned char*& start, int32_t min, int32_t max);
int64_t position();
int64_t reset(int64_t);
int64_t skip(int64_t ntoskip);
void setMinBufSize(int32_t s);
size_t size();
};
/**
* A helper class which constructs a FileReader with a specified
* simple encodings, or a given inputstreamreader
*/
class CLUCENE_EXPORT FileInputStream: public BufferedInputStream {
class Internal;
Internal* _internal;
protected:
void init(InputStream *i, int encoding);
public:
LUCENE_STATIC_CONSTANT(int32_t, DEFAULT_BUFFER_SIZE=4096);
FileInputStream ( const char* path, int32_t buflen = -1 );
virtual ~FileInputStream ();
int32_t read(const signed char*& start, int32_t min, int32_t max);
int64_t position();
int64_t reset(int64_t);
int64_t skip(int64_t ntoskip);
size_t size();
void setMinBufSize(int32_t minbufsize);
};
class CLUCENE_EXPORT SimpleInputStreamReader: public BufferedReader{
class Internal;
Internal* _internal;
protected:
void init(InputStream *i, int encoding);
public:
enum{
ASCII=1,
UTF8=2,
UCS2_LE=3
};
SimpleInputStreamReader();
SimpleInputStreamReader(InputStream *i, int encoding);
virtual ~SimpleInputStreamReader();
int32_t read(const TCHAR*& start, int32_t min, int32_t max);
int64_t position();
int64_t reset(int64_t);
int64_t skip(int64_t ntoskip);
void setMinBufSize(int32_t s);
size_t size();
};
/**
* A helper class which constructs a FileReader with a specified
* simple encodings, or a given inputstreamreader.
* It is recommended that you use the contribs package for proper
* decoding using iconv. This class is provided only as a dependency-less
* replacement.
*/
class CLUCENE_EXPORT FileReader: public SimpleInputStreamReader{
public:
FileReader(const char* path, int encoding, int32_t buflen = -1);
FileReader(const char* path, const char* encoding, int32_t buflen = -1);
virtual ~FileReader();
};
CL_NS_END
#define jstreams CL_NS(util)
#endif
|