|
From: <ust...@us...> - 2009-03-30 21:34:24
|
Revision: 2976
http://clucene.svn.sourceforge.net/clucene/?rev=2976&view=rev
Author: ustramooner
Date: 2009-03-30 21:34:13 +0000 (Mon, 30 Mar 2009)
Log Message:
-----------
various cleanups to the streams
Modified Paths:
--------------
branches/lucene2_3_2/src/contribs-lib/CLucene/util/gzipcompressstream.cpp
branches/lucene2_3_2/src/contribs-lib/CLucene/util/gzipcompressstream.h
branches/lucene2_3_2/src/contribs-lib/CLucene/util/gzipinputstream.h
branches/lucene2_3_2/src/contribs-lib/CMakeLists.txt
Added Paths:
-----------
branches/lucene2_3_2/src/contribs-lib/CLucene/util/
branches/lucene2_3_2/src/contribs-lib/CLucene/util/gzipinputstream.cpp
Removed Paths:
-------------
branches/lucene2_3_2/src/contribs-lib/CLucene/jstreams/
branches/lucene2_3_2/src/contribs-lib/CLucene/util/Reader.h
branches/lucene2_3_2/src/contribs-lib/CLucene/util/bufferedstream.h
branches/lucene2_3_2/src/contribs-lib/CLucene/util/bz2inputstream.cpp
branches/lucene2_3_2/src/contribs-lib/CLucene/util/bz2inputstream.h
branches/lucene2_3_2/src/contribs-lib/CLucene/util/dostime.cpp
branches/lucene2_3_2/src/contribs-lib/CLucene/util/dostime.h
branches/lucene2_3_2/src/contribs-lib/CLucene/util/fileinputstream.cpp
branches/lucene2_3_2/src/contribs-lib/CLucene/util/fileinputstream.h
branches/lucene2_3_2/src/contribs-lib/CLucene/util/filereader.cpp
branches/lucene2_3_2/src/contribs-lib/CLucene/util/filereader.h
branches/lucene2_3_2/src/contribs-lib/CLucene/util/gzipinputstream.cpp
branches/lucene2_3_2/src/contribs-lib/CLucene/util/inputstream.h
branches/lucene2_3_2/src/contribs-lib/CLucene/util/inputstreambuffer.h
branches/lucene2_3_2/src/contribs-lib/CLucene/util/inputstreamreader.cpp
branches/lucene2_3_2/src/contribs-lib/CLucene/util/inputstreamreader.h
branches/lucene2_3_2/src/contribs-lib/CLucene/util/jstreamsconfig.h.cmake
branches/lucene2_3_2/src/contribs-lib/CLucene/util/streambase.h
branches/lucene2_3_2/src/contribs-lib/CLucene/util/streamreader.h
branches/lucene2_3_2/src/contribs-lib/CLucene/util/stringreader.h
branches/lucene2_3_2/src/contribs-lib/CLucene/util/subinputstream.cpp
branches/lucene2_3_2/src/contribs-lib/CLucene/util/subinputstream.h
branches/lucene2_3_2/src/contribs-lib/CLucene/util/substreamprovider.h
branches/lucene2_3_2/src/contribs-lib/CLucene/util/tarinputstream.cpp
branches/lucene2_3_2/src/contribs-lib/CLucene/util/tarinputstream.h
branches/lucene2_3_2/src/contribs-lib/CLucene/util/zipinputstream.cpp
branches/lucene2_3_2/src/contribs-lib/CLucene/util/zipinputstream.h
Property changes on: branches/lucene2_3_2/src/contribs-lib/CLucene/util
___________________________________________________________________
Added: svn:mergeinfo
+
Deleted: branches/lucene2_3_2/src/contribs-lib/CLucene/util/Reader.h
===================================================================
--- branches/lucene2_3_2/src/contribs-lib/CLucene/jstreams/Reader.h 2009-01-10 17:17:55 UTC (rev 2949)
+++ branches/lucene2_3_2/src/contribs-lib/CLucene/util/Reader.h 2009-03-30 21:34:13 UTC (rev 2976)
@@ -1,18 +0,0 @@
-/*------------------------------------------------------------------------------
-* Copyright (C) 2003-2006 Jos van den Oever
-*
-* 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 READER_H
-#define READER_H
-
-#include "streambase.h"
-
-namespace jstreams {
-
-typedef StreamBase<wchar_t> Reader;
-
-} // end namespace jstreams
-
-#endif
Deleted: branches/lucene2_3_2/src/contribs-lib/CLucene/util/bufferedstream.h
===================================================================
--- branches/lucene2_3_2/src/contribs-lib/CLucene/jstreams/bufferedstream.h 2009-01-10 17:17:55 UTC (rev 2949)
+++ branches/lucene2_3_2/src/contribs-lib/CLucene/util/bufferedstream.h 2009-03-30 21:34:13 UTC (rev 2976)
@@ -1,137 +0,0 @@
-/*------------------------------------------------------------------------------
-* Copyright (C) 2003-2006 Jos van den Oever
-*
-* 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 BUFFEREDSTREAM_H
-#define BUFFEREDSTREAM_H
-
-#include "streambase.h"
-#include "inputstreambuffer.h"
-#include <cassert>
-
-namespace jstreams {
-
-template <class T>
-class BufferedInputStream : public StreamBase<T> {
-private:
- bool finishedWritingToBuffer;
- InputStreamBuffer<T> buffer;
-
- void writeToBuffer(int32_t minsize);
- int32_t read_(const T*& start, int32_t min, int32_t max);
-protected:
- /**
- * This function must be implemented by the subclasses.
- * It should write a maximum of @p space characters at the buffer
- * position pointed to by @p start. If no more data is avaiable due to
- * end of file, -1 should be returned. If an error occurs, the status
- * should be set to Error, an error message should be set and the function
- * must return -1.
- **/
- virtual int32_t fillBuffer(T* start, int32_t space) = 0;
- // this function might be useful if you want to reuse a bufferedstream
- void resetBuffer() {printf("implement 'resetBuffer'\n");}
- BufferedInputStream<T>();
-public:
- int32_t read(const T*& start, int32_t min, int32_t max);
- int64_t reset(int64_t);
- virtual int64_t skip(int64_t ntoskip);
-};
-
-template <class T>
-BufferedInputStream<T>::BufferedInputStream() {
- finishedWritingToBuffer = false;
-}
-
-template <class T>
-void
-BufferedInputStream<T>::writeToBuffer(int32_t ntoread) {
- int32_t missing = ntoread - buffer.avail;
- int32_t nwritten = 0;
- while (missing > 0 && nwritten >= 0) {
- int32_t space;
- space = buffer.makeSpace(missing);
- T* start = buffer.readPos + buffer.avail;
- nwritten = fillBuffer(start, space);
- assert(StreamBase<T>::status != Eof);
- if (nwritten > 0) {
- buffer.avail += nwritten;
- missing = ntoread - buffer.avail;
- }
- }
- if (nwritten < 0) {
- finishedWritingToBuffer = true;
- }
-}
-template <class T>
-int32_t
-BufferedInputStream<T>::read(const T*& start, int32_t min, int32_t max) {
- if (StreamBase<T>::status == Error) return -2;
- if (StreamBase<T>::status == Eof) return -1;
-
- // do we need to read data into the buffer?
- if (!finishedWritingToBuffer && min > buffer.avail) {
- // do we have enough space in the buffer?
- writeToBuffer(min);
- if (StreamBase<T>::status == Error) return -2;
- }
-
- int32_t nread = buffer.read(start, max);
-
- BufferedInputStream<T>::position += nread;
- if (BufferedInputStream<T>::position > BufferedInputStream<T>::size
- && BufferedInputStream<T>::size > 0) {
- // error: we read more than was specified in size
- // this is an error because all dependent code might have been labouring
- // under a misapprehension
- BufferedInputStream<T>::status = Error;
- BufferedInputStream<T>::error = "Stream is longer than specified.";
- nread = -2;
- } else if (BufferedInputStream<T>::status == Ok && buffer.avail == 0
- && finishedWritingToBuffer) {
- BufferedInputStream<T>::status = Eof;
- if (BufferedInputStream<T>::size == -1) {
- BufferedInputStream<T>::size = BufferedInputStream<T>::position;
- }
- // save one call to read() by already returning -1 if no data is there
- if (nread == 0) nread = -1;
- }
- return nread;
-}
-template <class T>
-int64_t
-BufferedInputStream<T>::reset(int64_t newpos) {
- assert(newpos >= 0);
- if (StreamBase<T>::status == Error) return -2;
- // check to see if we have this position
- int64_t d = BufferedInputStream<T>::position - newpos;
- if (buffer.readPos - d >= buffer.start && -d < buffer.avail) {
- BufferedInputStream<T>::position -= d;
- buffer.avail += d;
- buffer.readPos -= d;
- StreamBase<T>::status = Ok;
- }
- return StreamBase<T>::position;
-}
-template <class T>
-int64_t
-BufferedInputStream<T>::skip(int64_t ntoskip) {
- const T *begin;
- int32_t nread;
- int64_t skipped = 0;
- while (ntoskip) {
- int32_t step = (int32_t)((ntoskip > buffer.size) ?buffer.size :ntoskip);
- nread = read(begin, 1, step);
- if (nread <= 0) {
- return skipped;
- }
- ntoskip -= nread;
- skipped += nread;
- }
- return skipped;
-}
-}
-
-#endif
Deleted: branches/lucene2_3_2/src/contribs-lib/CLucene/util/bz2inputstream.cpp
===================================================================
--- branches/lucene2_3_2/src/contribs-lib/CLucene/jstreams/bz2inputstream.cpp 2009-01-10 17:17:55 UTC (rev 2949)
+++ branches/lucene2_3_2/src/contribs-lib/CLucene/util/bz2inputstream.cpp 2009-03-30 21:34:13 UTC (rev 2976)
@@ -1,138 +0,0 @@
-/*------------------------------------------------------------------------------
-* Copyright (C) 2003-2006 Jos van den Oever
-*
-* 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.
-------------------------------------------------------------------------------*/
-#include "CLucene/jstreams/jstreamsconfig.h"
-#include "bz2inputstream.h"
-using namespace jstreams;
-
-bool
-BZ2InputStream::checkHeader(const char* data, int32_t datasize) {
- static const char magic[] = {0x42, 0x5a, 0x68, 0x39, 0x31};
- if (datasize < 5) return false;
- return memcmp(data, magic, 5) == 0;
-}
-BZ2InputStream::BZ2InputStream(StreamBase<char>* input) {
- // initialize values that signal state
- this->input = input;
-
- // TODO: check first bytes of stream before allocating buffer
- // 0x42 0x5a 0x68 0x39 0x31
- if (!checkMagic()) {
- error = "Magic bytes are wrong.";
- status = Error;
- allocatedBz = false;
- return;
- }
-
- bzstream = (bz_stream*)malloc(sizeof(bz_stream));
- bzstream->bzalloc = NULL;
- bzstream->bzfree = NULL;
- bzstream->opaque = NULL;
- bzstream->avail_in = 0;
- bzstream->next_in = NULL;
- int r;
- r = BZ2_bzDecompressInit(bzstream, 1, 0);
- if (r != BZ_OK) {
- error = "Error initializing BZ2InputStream.";
- fprintf(stderr, "Error initializing BZ2InputStream.\n");
- dealloc();
- status = Error;
- return;
- }
- allocatedBz = true;
- // signal that we need to read into the buffer
- bzstream->avail_out = 1;
-
- // set the minimum size for the output buffer
- mark(262144);
-}
-BZ2InputStream::~BZ2InputStream() {
- dealloc();
-}
-void
-BZ2InputStream::dealloc() {
- if (allocatedBz) {
- BZ2_bzDecompressEnd(bzstream);
- free(bzstream);
- bzstream = 0;
- }
-}
-bool
-BZ2InputStream::checkMagic() {
- const char* begin;
- int32_t nread;
-
- int64_t pos = input->getPosition();
- nread = input->read(begin, 5, 5);
- input->reset(pos);
- if (nread != 5) {
- return false;
- }
-
- return checkHeader(begin, 5);
-}
-void
-BZ2InputStream::readFromStream() {
- // read data from the input stream
- const char* inStart;
- int32_t nread;
- nread = input->read(inStart, 1, 0);
- if (nread <= -1) {
- status = Error;
- error = input->getError();
- } else if (nread < 1) {
- status = Error;
- error = "unexpected end of stream";
- } else {
- bzstream->next_in = (char*)inStart;
- bzstream->avail_in = nread;
- }
-}
-int32_t
-BZ2InputStream::fillBuffer(char* start, int32_t space) {
- if (bzstream == 0) return -1;
- // make sure there is data to decompress
- if (bzstream->avail_out != 0) {
- readFromStream();
- if (status != Ok) {
- // no data was read
- return -1;
- }
- }
- // make sure we can write into the buffer
- bzstream->avail_out = space;
- bzstream->next_out = start;
- // decompress
- int r = BZ2_bzDecompress(bzstream);
- // inform the buffer of the number of bytes that was read
- int32_t nwritten = space - bzstream->avail_out;
- switch (r) {
- case BZ_PARAM_ERROR:
- error = "BZ_PARAM_ERROR";
- status = Error;
- return -1;
- case BZ_DATA_ERROR:
- error = "BZ_DATA_ERROR";
- status = Error;
- return -1;
- case BZ_DATA_ERROR_MAGIC:
- error = "BZ_DATA_ERROR_MAGIC";
- status = Error;
- return -1;
- case BZ_MEM_ERROR:
- error = "BZ_MEM_ERROR";
- status = Error;
- return -1;
- case BZ_STREAM_END:
- if (bzstream->avail_in) {
- input->reset(input->getPosition()-bzstream->avail_in);
- }
- // we are finished decompressing,
- // (but this stream is not yet finished)
- dealloc();
- }
- return nwritten;
-}
Deleted: branches/lucene2_3_2/src/contribs-lib/CLucene/util/bz2inputstream.h
===================================================================
--- branches/lucene2_3_2/src/contribs-lib/CLucene/jstreams/bz2inputstream.h 2009-01-10 17:17:55 UTC (rev 2949)
+++ branches/lucene2_3_2/src/contribs-lib/CLucene/util/bz2inputstream.h 2009-03-30 21:34:13 UTC (rev 2976)
@@ -1,35 +0,0 @@
-/*------------------------------------------------------------------------------
-* Copyright (C) 2003-2006 Jos van den Oever
-*
-* 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 BZ2INPUTSTREAM_H
-#define BZ2INPUTSTREAM_H
-
-#include "bufferedstream.h"
-
-#include <bzlib.h>
-
-namespace jstreams {
-
-class BZ2InputStream : public BufferedInputStream<char> {
-private:
- bool allocatedBz;
- bz_stream* bzstream;
- StreamBase<char> *input;
-
- void dealloc();
- void readFromStream();
- bool checkMagic();
-protected:
- int32_t fillBuffer(char* start, int32_t space);
-public:
- BZ2InputStream(StreamBase<char>* input);
- ~BZ2InputStream();
- static bool checkHeader(const char* data, int32_t datasize);
-};
-
-} // end namespace jstreams
-
-#endif
Deleted: branches/lucene2_3_2/src/contribs-lib/CLucene/util/dostime.cpp
===================================================================
--- branches/lucene2_3_2/src/contribs-lib/CLucene/jstreams/dostime.cpp 2009-01-10 17:17:55 UTC (rev 2949)
+++ branches/lucene2_3_2/src/contribs-lib/CLucene/util/dostime.cpp 2009-03-30 21:34:13 UTC (rev 2976)
@@ -1,71 +0,0 @@
-/*------------------------------------------------------------------------------
-* Copyright (C) 2003-2006 Jos van den Oever
-*
-* 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.
-------------------------------------------------------------------------------*/
-/* dostime.c - convert dos time to/from time_t.
-
- Copyright (C) 2002 Free Software Foundation
-
- This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License
- as published by the Free Software Foundation; either version 2
- of the License, or (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-*/
-
-// #include <config.h>
-
-#include <time.h>
-
-#include <stddef.h>
-
-#include "dostime.h"
-
-/*
- * The specification to which this was written. From Joe Buck.
- * The DOS format appears to have only 2 second resolution. It is an
- * unsigned long, and ORs together
- *
- * (year-1980)<<25
- * month<<21 (month is tm_mon + 1, 1=Jan through 12=Dec)
- * day<<16 (day is tm_mday, 1-31)
- * hour<<11 (hour is tm_hour, 0-23)
- * min<<5 (min is tm_min, 0-59)
- * sec>>1 (sec is tm_sec, 0-59, that's right, we throw away the LSB)
- *
- * DOS uses local time, so the localtime() call is used to turn the time_t
- * into a struct tm.
- */
-
-time_t
-dos2unixtime (unsigned long dostime)
-{
- struct tm ltime;
- time_t now = time (NULL);
-
- /* Call localtime to initialize timezone in TIME. */
- ltime = *localtime (&now);
-
- ltime.tm_year = (dostime >> 25) + 80;
- ltime.tm_mon = ((dostime >> 21) & 0x0f) - 1;
- ltime.tm_mday = (dostime >> 16) & 0x1f;
- ltime.tm_hour = (dostime >> 11) & 0x0f;
- ltime.tm_min = (dostime >> 5) & 0x3f;
- ltime.tm_sec = (dostime & 0x1f) << 1;
-
- ltime.tm_wday = -1;
- ltime.tm_yday = -1;
- ltime.tm_isdst = -1;
-
- return mktime (<ime);
-}
Deleted: branches/lucene2_3_2/src/contribs-lib/CLucene/util/dostime.h
===================================================================
--- branches/lucene2_3_2/src/contribs-lib/CLucene/jstreams/dostime.h 2009-01-10 17:17:55 UTC (rev 2949)
+++ branches/lucene2_3_2/src/contribs-lib/CLucene/util/dostime.h 2009-03-30 21:34:13 UTC (rev 2976)
@@ -1,27 +0,0 @@
-/*------------------------------------------------------------------------------
-* Copyright (C) 2003-2006 Jos van den Oever
-*
-* 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.
-------------------------------------------------------------------------------*/
-/*
- dostime.h - function prototypes
- Copyright (C) 1999, 2002 Bryan Burns
-
- This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License
- as published by the Free Software Foundation; either version 2
- of the License, or (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-time_t dos2unixtime(unsigned long dostime);
-unsigned long unix2dostime(time_t*);
Deleted: branches/lucene2_3_2/src/contribs-lib/CLucene/util/fileinputstream.cpp
===================================================================
--- branches/lucene2_3_2/src/contribs-lib/CLucene/jstreams/fileinputstream.cpp 2009-01-10 17:17:55 UTC (rev 2949)
+++ branches/lucene2_3_2/src/contribs-lib/CLucene/util/fileinputstream.cpp 2009-03-30 21:34:13 UTC (rev 2976)
@@ -1,78 +0,0 @@
-/*------------------------------------------------------------------------------
-* Copyright (C) 2003-2006 Jos van den Oever
-*
-* 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.
-------------------------------------------------------------------------------*/
-#include "CLucene/jstreams/jstreamsconfig.h"
-#include "fileinputstream.h"
-#include <cerrno>
-#include <cstring>
-using namespace jstreams;
-
-const int32_t FileInputStream::defaultBufferSize = 1048576;
-FileInputStream::FileInputStream(const char *filepath, int32_t buffersize) {
- // try to open the file for reading
- file = fopen(filepath, "rb");
- this->filepath = filepath;
- if (file == 0) {
- // handle error
- error = "Could not read file '";
- error += filepath;
- error += "': ";
- error += strerror(errno);
- status = Error;
- return;
- }
- // determine file size. if the stream is not seekable, the size will be -1
- fseek(file, 0, SEEK_END);
- size = ftell(file);
- fseek(file, 0, SEEK_SET);
-
- // if the file has size 0, make sure that it's really empty
- // this is useful for filesystems like /proc that report files as size 0
- // for files that do contain content
- if (size == 0) {
- char dummy[1];
- size_t n = fread(dummy, 1, 1, file);
- if (n == 1) {
- size = -1;
- fseek(file, 0, SEEK_SET);
- } else {
- fclose(file);
- file = 0;
- return;
- }
- }
-
- // allocate memory in the buffer
- int32_t bufsize = (size <= buffersize) ?size+1 :buffersize;
- mark(bufsize);
-}
-FileInputStream::~FileInputStream() {
- if (file) {
- if (fclose(file)) {
- // handle error
- error = "Could not close file '" + filepath + "'.";
- }
- }
-}
-int32_t
-FileInputStream::fillBuffer(char* start, int32_t space) {
- if (file == 0) return -1;
- // read into the buffer
- int32_t nwritten = fread(start, 1, space, file);
- // check the file stream status
- if (ferror(file)) {
- error = "Could not read from file '" + filepath + "'.";
- fclose(file);
- file = 0;
- status = Error;
- return -1;
- }
- if (feof(file)) {
- fclose(file);
- file = 0;
- }
- return nwritten;
-}
Deleted: branches/lucene2_3_2/src/contribs-lib/CLucene/util/fileinputstream.h
===================================================================
--- branches/lucene2_3_2/src/contribs-lib/CLucene/jstreams/fileinputstream.h 2009-01-10 17:17:55 UTC (rev 2949)
+++ branches/lucene2_3_2/src/contribs-lib/CLucene/util/fileinputstream.h 2009-03-30 21:34:13 UTC (rev 2976)
@@ -1,30 +0,0 @@
-/*------------------------------------------------------------------------------
-* Copyright (C) 2003-2006 Jos van den Oever
-*
-* 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 FILEINPUTSTREAM_H
-#define FILEINPUTSTREAM_H
-
-#include "bufferedstream.h"
-
-namespace jstreams {
-
-class FileInputStream : public BufferedInputStream<char> {
-private:
- FILE *file;
- std::string filepath;
-
-public:
- static const int32_t defaultBufferSize;
- explicit FileInputStream(const char *filepath,
- int32_t buffersize=defaultBufferSize);
- ~FileInputStream();
- int32_t fillBuffer(char* start, int32_t space);
-};
-
-} // end namespace jstreams
-
-#endif
-
Deleted: branches/lucene2_3_2/src/contribs-lib/CLucene/util/filereader.cpp
===================================================================
--- branches/lucene2_3_2/src/contribs-lib/CLucene/jstreams/filereader.cpp 2009-01-10 17:17:55 UTC (rev 2949)
+++ branches/lucene2_3_2/src/contribs-lib/CLucene/util/filereader.cpp 2009-03-30 21:34:13 UTC (rev 2976)
@@ -1,37 +0,0 @@
-#include "CLucene/jstreams/jstreamsconfig.h"
-#include "filereader.h"
-#include "fileinputstream.h"
-#include "inputstreamreader.h"
-using namespace jstreams;
-
-FileReader::FileReader(const char* fname, const char* encoding_scheme,
- int32_t cachelen, int32_t /*cachebuff*/) {
- input = new FileInputStream(fname, cachelen);
- reader = new InputStreamReader(input, encoding_scheme);
-}
-FileReader::~FileReader() {
- if (reader) delete reader;
- if (input) delete input;
-}
-int32_t
-FileReader::read(const wchar_t*& start, int32_t min, int32_t max) {
- int32_t nread = reader->read(start, min, max);
- if (nread < -1) {
- error = reader->getError();
- status = Error;
- return nread;
- } else if (nread == -1) {
- status = Eof;
- }
- return nread;
-}
-int64_t
-FileReader::reset(int64_t newpos) {
- position = reader->reset(newpos);
- if (position < -1) {
- status = Error;
- error = reader->getError();
- }
- return position;
-}
-
Deleted: branches/lucene2_3_2/src/contribs-lib/CLucene/util/filereader.h
===================================================================
--- branches/lucene2_3_2/src/contribs-lib/CLucene/jstreams/filereader.h 2009-01-10 17:17:55 UTC (rev 2949)
+++ branches/lucene2_3_2/src/contribs-lib/CLucene/util/filereader.h 2009-03-30 21:34:13 UTC (rev 2976)
@@ -1,24 +0,0 @@
-#ifndef FILEREADER_H
-#define FILEREADER_H
-
-#include "streambase.h"
-
-namespace jstreams {
-
-class FileInputStream;
-class InputStreamReader;
-class FileReader : public StreamBase<wchar_t> {
- FileInputStream* input;
- InputStreamReader* reader;
-public:
- explicit FileReader(const char* fname, const char* encoding_scheme=NULL,
- const int32_t cachelen = 13,
- const int32_t cachebuff = 14 );
- ~FileReader();
- int32_t read(const wchar_t*& start, int32_t min, int32_t max);
- int64_t reset(int64_t);
-};
-
-} // end namespace jstreams
-
-#endif
Modified: branches/lucene2_3_2/src/contribs-lib/CLucene/util/gzipcompressstream.cpp
===================================================================
--- branches/lucene2_3_2/src/contribs-lib/CLucene/jstreams/gzipcompressstream.cpp 2009-01-10 17:17:55 UTC (rev 2949)
+++ branches/lucene2_3_2/src/contribs-lib/CLucene/util/gzipcompressstream.cpp 2009-03-30 21:34:13 UTC (rev 2976)
@@ -1,108 +1,120 @@
-#include "CLucene/jstreams/jstreamsconfig.h"
+#include "CLucene/_ApiHeader.h"
#include "gzipcompressstream.h"
+#include "CLucene/util/_bufferedstream.h"
#include <zlib.h>
+CL_NS_DEF(util)
-using namespace jstreams;
+class GZipCompressInputStream::Internal: public CL_NS(util)::BufferedInputStreamImpl{
+ z_stream_s* zstream;
+ InputStream* input;
+protected:
+ int32_t fillBuffer(signed char* start, int32_t space){
+ if (zstream == 0) return -1;
+ // make sure there is data to decompress
+ if (zstream->avail_in==0) {
+ // read data from the input stream
+ const signed char* inStart;
+ int32_t nread = input->read(inStart, 1, 0);
+ if (nread < 1) {
+ zstream->avail_in = 0; //bail...
+ if (deflate(zstream, Z_FINISH) != Z_STREAM_END) {
+ _CLTHROWA(CL_ERR_IO, "deflate should report Z_STREAM_END\n");
+ }
+ int32_t nwritten = space - zstream->avail_out;
+ dealloc();
+ return nwritten;
+ }
+ zstream->next_in = (Bytef*)inStart;
+ zstream->avail_in = nread;
+ }
+ // make sure we can write into the buffer
+ zstream->avail_out = space;
+ zstream->next_out = (Bytef*)start;
-GZipCompressInputStream::GZipCompressInputStream(StreamBase<char>* input, int level) {
- // initialize values that signal state
- status = Ok;
- zstream = 0;
- if ( level < 0 || level > 9 )
- level = Z_DEFAULT_COMPRESSION;
+ int r = deflate(zstream, Z_NO_FLUSH);
+ // inform the buffer of the number of bytes that was read
+ int32_t nwritten = space - zstream->avail_out;
+ switch (r) {
+ case Z_NEED_DICT:
+ _CLTHROWA(CL_ERR_IO, "Z_NEED_DICT while inflating stream.");
+ break;
+ case Z_DATA_ERROR:
+ _CLTHROWA(CL_ERR_IO, "Z_DATA_ERROR while inflating stream.");
+ break;
+ case Z_MEM_ERROR:
+ _CLTHROWA(CL_ERR_IO, "Z_MEM_ERROR while inflating stream.");
+ break;
+ }
+ return nwritten;
+ }
+public:
+ void dealloc(){
+ if (zstream) {
+ deflateEnd(zstream);
+ free(zstream);
+ zstream = 0;
+ }
+ }
+ void _setMinBufSize(int buf){
+ this->setMinBufSize(buf);
+ }
+ Internal(InputStream* input, int level){
+ if ( level < 0 || level > 9 )
+ level = Z_DEFAULT_COMPRESSION;
- this->input = input;
+ this->input = input;
- // initialize the z_stream
- zstream = (z_stream_s*)malloc(sizeof(z_stream_s));
- zstream->zalloc = Z_NULL;
- zstream->zfree = Z_NULL;
- zstream->opaque = Z_NULL;
- zstream->avail_in = 0;
-
- // initialize for writing gzip streams
- int r = deflateInit(zstream, level);
- if (r != Z_OK) {
- error = "Error initializing GZipCompressInputStream.";
- dealloc();
- status = Error;
- return;
- }
+ // initialize the z_stream
+ zstream = (z_stream_s*)malloc(sizeof(z_stream_s));
+ zstream->zalloc = Z_NULL;
+ zstream->zfree = Z_NULL;
+ zstream->opaque = Z_NULL;
+ zstream->avail_in = 0;
+
+ // initialize for writing gzip streams
+ int r = deflateInit(zstream, level);
+ if (r != Z_OK) {
+ dealloc();
+ _CLTHROWA(CL_ERR_IO, "Error initializing GZipCompressInputStream.");
+ }
- // signal that we need to read into the buffer
- zstream->avail_out = 1;
+ // signal that we need to read into the buffer
+ zstream->avail_out = 1;
+ }
- // initialize the buffer
- mark(262144);
+ ~Internal(){
+ dealloc();
+ }
+};
+
+
+GZipCompressInputStream::GZipCompressInputStream ( InputStream* input, int level)
+{
+ internal = new Internal(input,level);
}
-GZipCompressInputStream::~GZipCompressInputStream() {
- dealloc();
+size_t GZipCompressInputStream::size(){
+ return internal->size();
}
-void
-GZipCompressInputStream::dealloc() {
- if (zstream) {
- deflateEnd(zstream);
- free(zstream);
- zstream = 0;
- }
+GZipCompressInputStream::~GZipCompressInputStream ()
+{
+ delete internal;
}
-void
-GZipCompressInputStream::readFromStream() {
- // read data from the input stream
- const char* inStart;
- int32_t nread;
- nread = input->read(inStart, 1, 0);
- if (nread < -1) {
- status = Error;
- error = input->getError();
- } else if (nread < 1) {
- zstream->avail_in = 0; //bail...
- } else {
- zstream->next_in = (Bytef*)inStart;
- zstream->avail_in = nread;
- }
+int32_t GZipCompressInputStream::read(const signed char*& start, int32_t min, int32_t max){
+ return internal->read(start,min,max);
}
-int32_t
-GZipCompressInputStream::fillBuffer(char* start, int32_t space) {
- if (zstream == 0) return -1;
- // make sure there is data to decompress
- if (zstream->avail_in==0) {
- readFromStream();
- if (status == Error) {
- // no data was read
- return -1;
- }else if ( zstream->avail_in == 0 ){
- if (deflate(zstream, Z_FINISH) != Z_STREAM_END) {
- fprintf(stderr, "deflate should report Z_STREAM_END\n");
- exit(1);
- }
- int32_t nwritten = space - zstream->avail_out;
- dealloc();
- return nwritten;
- }
- }
- // make sure we can write into the buffer
- zstream->avail_out = space;
- zstream->next_out = (Bytef*)start;
+int64_t GZipCompressInputStream::position(){
+ return internal->position();
+}
+int64_t GZipCompressInputStream::reset(int64_t to){
+ return internal->reset(to);
+}
+int64_t GZipCompressInputStream::skip(int64_t ntoskip){
+ return internal->skip(ntoskip);
+}
+void GZipCompressInputStream::setMinBufSize(int32_t minbufsize){
+ internal->_setMinBufSize(minbufsize);
+}
- int r = deflate(zstream, Z_NO_FLUSH);
- // inform the buffer of the number of bytes that was read
- int32_t nwritten = space - zstream->avail_out;
- switch (r) {
- case Z_NEED_DICT:
- error = "Z_NEED_DICT while inflating stream.";
- status = Error;
- break;
- case Z_DATA_ERROR:
- error = "Z_DATA_ERROR while inflating stream.";
- status = Error;
- break;
- case Z_MEM_ERROR:
- error = "Z_MEM_ERROR while inflating stream.";
- status = Error;
- break;
- }
- return nwritten;
-}
+CL_NS_END
Modified: branches/lucene2_3_2/src/contribs-lib/CLucene/util/gzipcompressstream.h
===================================================================
--- branches/lucene2_3_2/src/contribs-lib/CLucene/jstreams/gzipcompressstream.h 2009-01-10 17:17:55 UTC (rev 2949)
+++ branches/lucene2_3_2/src/contribs-lib/CLucene/util/gzipcompressstream.h 2009-03-30 21:34:13 UTC (rev 2976)
@@ -17,29 +17,31 @@
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
-#ifndef GZIPCOMPRESSSTREAM_H
-#define GZIPCOMPRESSSTREAM_H
+#ifndef CLUENE_UTIL_GZIPCOMPRESSSTREAM_H
+#define CLUENE_UTIL_GZIPCOMPRESSSTREAM_H
-#include "bufferedstream.h"
+#include "CLucene/util/CLStreams.h"
struct z_stream_s;
-namespace jstreams {
+CL_NS_DEF(util)
-class GZipCompressInputStream : public BufferedInputStream<char> {
+class GZipCompressInputStream : public InputStream{
private:
- z_stream_s* zstream;
- StreamBase<char>* input;
-
- void dealloc();
- void readFromStream();
- void compressFromStream();
+ class Internal;
+ Internal* internal;
public:
- explicit GZipCompressInputStream(StreamBase<char>* input, int level=-1);
- ~GZipCompressInputStream();
- int32_t fillBuffer(char* start, int32_t space);
+ LUCENE_STATIC_CONSTANT(int32_t, DEFAULT_BUFFER_SIZE=4096);
+ explicit GZipCompressInputStream(InputStream* input, int level=-1);
+ virtual ~GZipCompressInputStream();
+
+ 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);
};
-} // end namespace jstreams
-
+CL_NS_END
#endif
Deleted: branches/lucene2_3_2/src/contribs-lib/CLucene/util/gzipinputstream.cpp
===================================================================
--- branches/lucene2_3_2/src/contribs-lib/CLucene/jstreams/gzipinputstream.cpp 2009-01-10 17:17:55 UTC (rev 2949)
+++ branches/lucene2_3_2/src/contribs-lib/CLucene/util/gzipinputstream.cpp 2009-03-30 21:34:13 UTC (rev 2976)
@@ -1,145 +0,0 @@
-/*------------------------------------------------------------------------------
-* Copyright (C) 2003-2006 Jos van den Oever
-*
-* 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.
-------------------------------------------------------------------------------*/
-#include "CLucene/jstreams/jstreamsconfig.h"
-#include "gzipinputstream.h"
-#include <zlib.h>
-using namespace jstreams;
-
-GZipInputStream::GZipInputStream(StreamBase<char>* input, ZipFormat format) {
- // initialize values that signal state
- status = Ok;
- zstream = 0;
-
- this->input = input;
-
- // check first bytes of stream before allocating buffer
- if (format == GZIPFORMAT && !checkMagic()) {
- error = "Magic bytes are wrong.";
- status = Error;
- return;
- }
-
- // initialize the z_stream
- zstream = (z_stream_s*)malloc(sizeof(z_stream_s));
- zstream->zalloc = Z_NULL;
- zstream->zfree = Z_NULL;
- zstream->opaque = Z_NULL;
- zstream->avail_in = 0;
- zstream->next_in = Z_NULL;
- // initialize for reading gzip streams
- // for reading libz streams, you need inflateInit(zstream)
- int r;
- switch(format) {
- case ZLIBFORMAT:
- r = inflateInit(zstream);
- break;
- case GZIPFORMAT:
- r = inflateInit2(zstream, 15+16);
- break;
- case ZIPFORMAT:
- default:
- r = inflateInit2(zstream, -MAX_WBITS);
- break;
- }
- if (r != Z_OK) {
- error = "Error initializing GZipInputStream.";
- dealloc();
- status = Error;
- return;
- }
-
- // signal that we need to read into the buffer
- zstream->avail_out = 1;
-
- // initialize the buffer
- mark(262144);
-}
-GZipInputStream::~GZipInputStream() {
- dealloc();
-}
-void
-GZipInputStream::dealloc() {
- if (zstream) {
- inflateEnd(zstream);
- free(zstream);
- zstream = 0;
- }
-}
-bool
-GZipInputStream::checkMagic() {
- const unsigned char* buf;
- const char* begin;
- int32_t nread;
-
- int64_t pos = input->getPosition();
- nread = input->read(begin, 2, 2);
- input->reset(pos);
- if (nread != 2) {
- return false;
- }
-
- buf = (const unsigned char*)begin;
- return buf[0] == 0x1f && buf[1] == 0x8b;
-}
-void
-GZipInputStream::readFromStream() {
- // read data from the input stream
- const char* inStart;
- int32_t nread;
- nread = input->read(inStart, 1, 0);
- if (nread < -1) {
- status = Error;
- error = input->getError();
- } else if (nread < 1) {
- status = Error;
- error = "unexpected end of stream";
- } else {
- zstream->next_in = (Bytef*)inStart;
- zstream->avail_in = nread;
- }
-}
-int32_t
-GZipInputStream::fillBuffer(char* start, int32_t space) {
- if (zstream == 0) return -1;
- // make sure there is data to decompress
- if (zstream->avail_out) {
- readFromStream();
- if (status == Error) {
- // no data was read
- return -1;
- }
- }
- // make sure we can write into the buffer
- zstream->avail_out = space;
- zstream->next_out = (Bytef*)start;
- // decompress
- int r = inflate(zstream, Z_SYNC_FLUSH);
- // inform the buffer of the number of bytes that was read
- int32_t nwritten = space - zstream->avail_out;
- switch (r) {
- case Z_NEED_DICT:
- error = "Z_NEED_DICT while inflating stream.";
- status = Error;
- break;
- case Z_DATA_ERROR:
- error = "Z_DATA_ERROR while inflating stream.";
- status = Error;
- break;
- case Z_MEM_ERROR:
- error = "Z_MEM_ERROR while inflating stream.";
- status = Error;
- break;
- case Z_STREAM_END:
- if (zstream->avail_in) {
- input->reset(input->getPosition()-zstream->avail_in);
- }
- // we are finished decompressing,
- // (but this stream is not yet finished)
- dealloc();
- }
- return nwritten;
-}
Copied: branches/lucene2_3_2/src/contribs-lib/CLucene/util/gzipinputstream.cpp (from rev 2949, branches/lucene2_3_2/src/contribs-lib/CLucene/jstreams/gzipinputstream.cpp)
===================================================================
--- branches/lucene2_3_2/src/contribs-lib/CLucene/util/gzipinputstream.cpp (rev 0)
+++ branches/lucene2_3_2/src/contribs-lib/CLucene/util/gzipinputstream.cpp 2009-03-30 21:34:13 UTC (rev 2976)
@@ -0,0 +1,184 @@
+/*------------------------------------------------------------------------------
+* Copyright (C) 2003-2006 Jos van den Oever
+*
+* 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.
+------------------------------------------------------------------------------*/
+#include "CLucene/_ApiHeader.h"
+#include "gzipinputstream.h"
+#include "CLucene/util/_bufferedstream.h"
+#include <zlib.h>
+
+CL_NS_DEF(util)
+
+
+class GZipInputStream::Internal{
+public:
+ class JStreamsBuffer: public BufferedInputStreamImpl{
+ z_stream_s* zstream;
+ BufferedInputStream* input;
+ protected:
+
+ int32_t fillBuffer(signed char* start, int32_t space) {
+ if (zstream == 0) return -1;
+ // make sure there is data to decompress
+ if (zstream->avail_out) {
+ // read data from the input stream
+ const signed char* inStart;
+ int32_t nread = input->read(inStart, 1, 0);
+ if (nread < 1) {
+ _CLTHROWA(CL_ERR_IO, "unexpected end of stream");
+ } else {
+ zstream->next_in = (Bytef*)inStart;
+ zstream->avail_in = nread;
+ }
+ }
+ // make sure we can write into the buffer
+ zstream->avail_out = space;
+ zstream->next_out = (Bytef*)start;
+ // decompress
+ int r = inflate(zstream, Z_SYNC_FLUSH);
+ // inform the buffer of the number of bytes that was read
+ int32_t nwritten = space - zstream->avail_out;
+ switch (r) {
+ case Z_NEED_DICT:
+ _CLTHROWA(CL_ERR_IO, "Z_NEED_DICT while inflating stream.");
+ break;
+ case Z_DATA_ERROR:
+ _CLTHROWA(CL_ERR_IO, "Z_DATA_ERROR while inflating stream.");
+ break;
+ case Z_MEM_ERROR:
+ _CLTHROWA(CL_ERR_IO, "Z_MEM_ERROR while inflating stream.");
+ break;
+ case Z_STREAM_END:
+ if (zstream->avail_in) {
+ input->reset(input->getPosition()-zstream->avail_in);
+ }
+ // we are finished decompressing,
+ // (but this stream is not yet finished)
+ dealloc();
+ }
+ return nwritten;
+ }
+ void dealloc() {
+ if (zstream) {
+ inflateEnd(zstream);
+ free(zstream);
+ zstream = 0;
+ }
+ }
+ bool checkMagic() {
+ const unsigned char* buf;
+ const signed char* begin;
+ int32_t nread;
+
+ int64_t pos = input->getPosition();
+ nread = input->read(begin, 2, 2);
+ input->reset(pos);
+ if (nread != 2) {
+ return false;
+ }
+
+ buf = (const unsigned char*)begin;
+ return buf[0] == 0x1f && buf[1] == 0x8b;
+ }
+
+ public:
+ int encoding;
+
+ JStreamsBuffer(BufferedInputStream* input, GZipInputStream::ZipFormat format){
+ this->input = input;
+
+ // check first bytes of stream before allocating buffer
+ if (format == GZipInputStream::GZIPFORMAT && !checkMagic()) {
+ _CLTHROWA(CL_ERR_IO, "Magic bytes are wrong.");
+ }
+
+ // initialize the z_stream
+ zstream = (z_stream_s*)malloc(sizeof(z_stream_s));
+ zstream->zalloc = Z_NULL;
+ zstream->zfree = Z_NULL;
+ zstream->opaque = Z_NULL;
+ zstream->avail_in = 0;
+ zstream->next_in = Z_NULL;
+ // initialize for reading gzip streams
+ // for reading libz streams, you need inflateInit(zstream)
+ int r;
+ switch(format) {
+ case GZipInputStream::ZLIBFORMAT:
+ r = inflateInit(zstream);
+ break;
+ case GZipInputStream::GZIPFORMAT:
+ r = inflateInit2(zstream, 15+16);
+ break;
+ case GZipInputStream::ZIPFORMAT:
+ default:
+ r = inflateInit2(zstream, -MAX_WBITS);
+ break;
+ }
+ if (r != Z_OK) {
+ dealloc();
+ _CLTHROWA(CL_ERR_IO, "Error initializing GZipInputStream.");
+ }
+
+ // signal that we need to read into the buffer
+ zstream->avail_out = 1;
+ }
+ void _setMinBufSize(int32_t bufsize){
+ this->setMinBufSize(bufsize);
+ }
+
+ ~JStreamsBuffer(){
+ dealloc();
+ }
+ };
+
+ JStreamsBuffer* jsbuffer;
+
+ Internal(BufferedInputStream* input, GZipInputStream::ZipFormat format){
+ jsbuffer = new JStreamsBuffer(input, format);
+ }
+ ~Internal(){
+ delete jsbuffer;
+ }
+};
+
+GZipInputStream::GZipInputStream(InputStream* input, ZipFormat format) {
+ internal = new Internal(_CLNEW FilteredBufferedInputStream(input, false), format);
+}
+GZipInputStream::GZipInputStream(BufferedInputStream* input, ZipFormat format) {
+ internal = new Internal(input, format);
+}
+
+GZipInputStream::~GZipInputStream() {
+ delete internal;
+}
+
+
+int32_t GZipInputStream::read(const signed char*& start, int32_t min, int32_t max){
+ return internal->jsbuffer->read(start,min,max);
+}
+int32_t GZipInputStream::read(const unsigned char*& _start, int32_t min, int32_t max){
+ const signed char* start = 0;
+ int32_t ret = internal->jsbuffer->read(start,min,max);
+ _start = (const unsigned char*)start;
+ return ret;
+}
+int64_t GZipInputStream::position(){
+ return internal->jsbuffer->position();
+}
+int64_t GZipInputStream::reset(int64_t to){
+ return internal->jsbuffer->reset(to);
+}
+int64_t GZipInputStream::skip(int64_t ntoskip){
+ return internal->jsbuffer->skip(ntoskip);
+}
+void GZipInputStream::setMinBufSize(int32_t minbufsize){
+ internal->jsbuffer->_setMinBufSize(minbufsize);
+}
+size_t GZipInputStream::size(){
+ return internal->jsbuffer->size();
+}
+
+
+CL_NS_END
Property changes on: branches/lucene2_3_2/src/contribs-lib/CLucene/util/gzipinputstream.cpp
___________________________________________________________________
Added: svn:mergeinfo
+
Modified: branches/lucene2_3_2/src/contribs-lib/CLucene/util/gzipinputstream.h
===================================================================
--- branches/lucene2_3_2/src/contribs-lib/CLucene/jstreams/gzipinputstream.h 2009-01-10 17:17:55 UTC (rev 2949)
+++ branches/lucene2_3_2/src/contribs-lib/CLucene/util/gzipinputstream.h 2009-03-30 21:34:13 UTC (rev 2976)
@@ -4,32 +4,36 @@
* 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 GZIPINPUTSTREAM_H
-#define GZIPINPUTSTREAM_H
+#ifndef CLUENE_UTIL_GZIPINPUTSTREAM_H
+#define CLUENE_UTIL_GZIPINPUTSTREAM_H
-#include "bufferedstream.h"
+#include "CLucene/util/CLStreams.h"
struct z_stream_s;
-namespace jstreams {
+CL_NS_DEF(util)
-class GZipInputStream : public BufferedInputStream<char> {
+class GZipInputStream : public CL_NS(util)::BufferedInputStream {
+public:
+ enum ZipFormat { ZLIBFORMAT, GZIPFORMAT, ZIPFORMAT};
private:
- z_stream_s* zstream;
- StreamBase<char>* input;
-
- void dealloc();
- void readFromStream();
- void decompressFromStream();
- bool checkMagic();
+ class Internal;
+ Internal* internal;
public:
- enum ZipFormat { ZLIBFORMAT, GZIPFORMAT, ZIPFORMAT};
- explicit GZipInputStream(StreamBase<char>* input,
+ explicit GZipInputStream(BufferedInputStream* input,
ZipFormat format=GZIPFORMAT);
+ explicit GZipInputStream(InputStream* input,
+ ZipFormat format=GZIPFORMAT);
~GZipInputStream();
- int32_t fillBuffer(char* start, int32_t space);
+
+ 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);
+ size_t size();
+ void setMinBufSize(int32_t minbufsize);
};
-} // end namespace jstreams
-
+CL_NS_END
#endif
Deleted: branches/lucene2_3_2/src/contribs-lib/CLucene/util/inputstream.h
===================================================================
--- branches/lucene2_3_2/src/contribs-lib/CLucene/jstreams/inputstream.h 2009-01-10 17:17:55 UTC (rev 2949)
+++ branches/lucene2_3_2/src/contribs-lib/CLucene/util/inputstream.h 2009-03-30 21:34:13 UTC (rev 2976)
@@ -1,18 +0,0 @@
-/*------------------------------------------------------------------------------
-* Copyright (C) 2003-2006 Jos van den Oever
-*
-* 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 INPUTSTREAM_H
-#define INPUTSTREAM_H
-
-#include "streambase.h"
-
-namespace jstreams {
-
-typedef StreamBase<char> InputStream;
-
-} // end namespace jstreams
-
-#endif
Deleted: branches/lucene2_3_2/src/contribs-lib/CLucene/util/inputstreambuffer.h
===================================================================
--- branches/lucene2_3_2/src/contribs-lib/CLucene/jstreams/inputstreambuffer.h 2009-01-10 17:17:55 UTC (rev 2949)
+++ branches/lucene2_3_2/src/contribs-lib/CLucene/util/inputstreambuffer.h 2009-03-30 21:34:13 UTC (rev 2976)
@@ -1,102 +0,0 @@
-/*------------------------------------------------------------------------------
-* Copyright (C) 2003-2006 Jos van den Oever
-*
-* 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 INPUTSTREAMBUFFER_H
-#define INPUTSTREAMBUFFER_H
-
-namespace jstreams {
-
-template <class T>
-class InputStreamBuffer {
-private:
-public:
- T* start;
- int32_t size;
- T* readPos;
- int32_t avail;
-
- InputStreamBuffer();
- ~InputStreamBuffer();
- void setSize(int32_t size);
- int32_t read(const T*& start, int32_t max=0);
-
- /**
- * This function prepares the buffer for a new write.
- * returns the number of available places.
- **/
- int32_t makeSpace(int32_t needed);
-};
-
-template <class T>
-InputStreamBuffer<T>::InputStreamBuffer() {
- readPos = start = 0;
- size = avail = 0;
-}
-template <class T>
-InputStreamBuffer<T>::~InputStreamBuffer() {
- free(start);
-}
-template <class T>
-void
-InputStreamBuffer<T>::setSize(int32_t size) {
- // store pointer information
- int32_t offset = readPos - start;
-
- // allocate memory in the buffer
- start = (T*)realloc(start, size*sizeof(T));
- this->size = size;
-
- // restore pointer information
- readPos = start + offset;
-}
-template <class T>
-int32_t
-InputStreamBuffer<T>::makeSpace(int32_t needed) {
- // determine how much space is available for writing
- int32_t space = size - (readPos - start) - avail;
- if (space >= needed) {
- // there's enough space
- return space;
- }
-
- if (avail) {
- if (readPos != start) {
-// printf("moving\n");
- // move data to the start of the buffer
- memmove(start, readPos, avail*sizeof(T));
- space += readPos - start;
- readPos = start;
- }
- } else {
- // we may start writing at the start of the buffer
- readPos = start;
- space = size;
- }
- if (space >= needed) {
- // there's enough space now
- return space;
- }
-
- // still not enough space, we have to allocate more
-// printf("resize %i %i %i %i %i\n", avail, needed, space, size + needed - space, size);
- setSize(size + needed - space);
- return needed;
-}
-template <class T>
-int32_t
-InputStreamBuffer<T>::read(const T*& start, int32_t max) {
- start = readPos;
- if (max <= 0 || max > avail) {
- max = avail;
- }
- readPos += max;
- avail -= max;
- return max;
-}
-
-} // end namespace jstreams
-
-#endif
Deleted: branches/lucene2_3_2/src/contribs-lib/CLucene/util/inputstreamreader.cpp
===================================================================
--- branches/lucene2_3_2/src/contribs-lib/CLucene/jstreams/inputstreamreader.cpp 2009-01-10 17:17:55 UTC (rev 2949)
+++ branches/lucene2_3_2/src/contribs-lib/CLucene/util/inputstreamreader.cpp 2009-03-30 21:34:13 UTC (rev 2976)
@@ -1,132 +0,0 @@
-/*------------------------------------------------------------------------------
-* Copyright (C) 2003-2006 Jos van den Oever
-*
-* 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.
-------------------------------------------------------------------------------*/
-#include "CLucene/jstreams/jstreamsconfig.h"
-#include "inputstreamreader.h"
-#include "CLucene/jstreams/jstreamsconfig.h"
-#include <cerrno>
-using namespace jstreams;
-
-#ifndef ICONV_CONST
- //we try to guess whether the iconv function requires
- //a const char. We have no way of automatically figuring
- //this out if we did not use autoconf, so we guess based
- //on certain parameters:
- #ifdef _LIBICONV_H
- #define ICONV_CONST const
- #else
- #define ICONV_CONST
- #endif
-#endif
-
-InputStreamReader::InputStreamReader(StreamBase<char>* i, const char* enc) {
- status = Ok;
- finishedDecoding = false;
- input = i;
- if (enc == 0) enc = "UTF-8";
-#ifdef _LIBICONV_H
- if (sizeof(wchar_t) == 4) {
- converter = iconv_open("UCS-4-INTERNAL", enc);
- } if (sizeof(wchar_t) == 2) {
- converter = iconv_open("UCS-2-INTERNAL", enc);
-#else
- if (sizeof(wchar_t) > 1) {
- converter = iconv_open("WCHAR_T", enc);
-#endif
- } else {
- converter = iconv_open("ASCII", enc);
- }
-
- // check if the converter is valid
- if (converter == (iconv_t) -1) {
- error = "conversion from '";
- error += enc;
- error += "' not available.";
- status = Error;
- return;
- }
- charbuf.setSize(262);
- //mark(262);
- charsLeft = 0;
-}
-InputStreamReader::~InputStreamReader() {
- if (converter != (iconv_t) -1) {
- iconv_close(converter);
- }
-}
-int32_t
-InputStreamReader::decode(wchar_t* start, int32_t space) {
- // decode from charbuf
- ICONV_CONST char *inbuf = charbuf.readPos;
- size_t inbytesleft = charbuf.avail;
- size_t outbytesleft = sizeof(wchar_t)*space;
- char *outbuf = (char*)start;
- size_t r = iconv(converter, &inbuf, &inbytesleft, &outbuf, &outbytesleft);
- int32_t nwritten;
- if (r == (size_t)-1) {
- switch (errno) {
- case EILSEQ: //invalid multibyte sequence
- error = "Invalid multibyte sequence.";
- status = Error;
- return -1;
- case EINVAL: // last character is incomplete
- // move from inbuf to the end to the start of
- // the buffer
- memmove(charbuf.start, inbuf, inbytesleft);
- charbuf.readPos = charbuf.start;
- charbuf.avail = inbytesleft;
- nwritten = ((wchar_t*)outbuf) - start;
- break;
- case E2BIG: // output buffer is full
- charbuf.readPos += charbuf.avail - inbytesleft;
- charbuf.avail = inbytesleft;
- nwritten = space;
- break;
- default:
- printf("InputStreamReader::error %d\n", errno);
- }
- } else { //input sequence was completely converted
- charbuf.readPos = charbuf.start;
- charbuf.avail = 0;
- nwritten = ((wchar_t*)outbuf) - start;
- if (input == 0) {
- finishedDecoding = true;
- }
- }
- return nwritten;
-}
-int32_t
-InputStreamReader::fillBuffer(wchar_t* start, int32_t space) {
- // fill up charbuf
- if (input && charbuf.readPos == charbuf.start) {
- const char *begin;
- int32_t numRead;
- numRead = input->read(begin, 1, charbuf.size - charbuf.avail);
- //printf("filled up charbuf\n");
- if (numRead < -1) {
- error = input->getError();
- status = Error;
- input = 0;
- return numRead;
- }
- if (numRead < 1) {
- // signal end of input buffer
- input = 0;
- if (charbuf.avail) {
- error = "stream ends on incomplete character";
- status = Error;
- }
- return -1;
- }
- // copy data into other buffer
- memmove(charbuf.start + charbuf.avail, begin, numRead);
- charbuf.avail = numRead + charbuf.avail;
- }
- // decode
- int32_t n = decode(start, space);
- //printf("decoded %i\n", n);
- return n;
-}
Deleted: branches/lucene2_3_2/src/contribs-lib/CLucene/util/inputstreamreader.h
===================================================================
--- branches/lucene2_3_2/src/contribs-lib/CLucene/jstreams/inputstreamreader.h 2009-01-10 17:17:55 UTC (rev 2949)
+++ branches/lucene2_3_2/src/contribs-lib/CLucene/util/inputstreamreader.h 2009-03-30 21:34:13 UTC (rev 2976)
@@ -1,39 +0,0 @@
-/*------------------------------------------------------------------------------
-* Copyright (C) 2003-2006 Jos van den Oever
-*
-* 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 INPUTSTREAMREADER_H
-#define INPUTSTREAMREADER_H
-
-#include <string>
-#include <iconv.h>
-#include "bufferedstream.h"
-
-namespace jstreams {
-
-/**
- * Info on conversions:
-http://www.gnu.org/software/libc/manual/html_node/iconv-Examples.html
-http://tangentsoft.net/mysql++/doc/userman/html/unicode.html
- **/
-class InputStreamReader : public BufferedInputStream<wchar_t> {
-private:
- iconv_t converter;
- bool finishedDecoding;
- StreamBase<char>* input;
- int32_t charsLeft;
-
- InputStreamBuffer<char> charbuf;
- void readFromStream();
- int32_t decode(wchar_t* start, int32_t space);
-public:
- explicit InputStreamReader(StreamBase<char> *i, const char *enc=0);
- ~InputStreamReader();
- int32_t fillBuffer(wchar_t* start, int32_t space);
-};
-
-} // end namespace jstreams
-
-#endif
Deleted: branches/lucene2_3_2/src/contribs-lib/CLucene/util/jstreamsconfig.h.cmake
===================================================================
--- branches/lucene2_3_2/src/contribs-lib/CLucene/jstreams/jstreamsconfig.h.cmake 2009-01-10 17:17:55 UTC (rev 2949)
+++ branches/lucene2_3_2/src/contribs-lib/CLucene/util/jstreamsconfig.h.cmake 2009-03-30 21:34:13 UTC (rev 2976)
@@ -1,12 +0,0 @@
-#ifndef JSTREAMS_JSTREAMCONFIG_H
-#define JSTREAMS_JSTREAMCONFIG_H
-
-#include "CLucene/_ApiHeader.h"
-
-#if @ICONV_SECOND_ARGUMENT_IS_CONST@
- #define _CL_ICONV_CONST const
-#else
- #define _CL_ICONV_CONST
-#endif
-
-#endif
Deleted: branches/lucene2_3_2/src/contribs-lib/CLucene/util/streambase.h
===================================================================
--- branches/lucene2_3_2/src/contribs-lib/CLucene/jstreams/streambase.h 2009-01-10 17:17:55 UTC (rev 2949)
+++ branches/lucene2_3_2/src/contribs-lib/CLucene/util/streambase.h 2009-03-30 21:34:13 UTC (rev 2976)
@@ -1,124 +0,0 @@
-/*------------------------------------------------------------------------------
-* Copyright (C) 2003-2006 Jos van den Oever
-*
-* 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 STREAMBASE_H
-#define STREAMBASE_H
-
-#include <string>
-
-namespace jstreams {
-
-enum StreamStatus { Ok, Eof, Error };
-
-/**
- * @short Base class for stream read access to many different file types.
- *
- * This class is based on the interface java.io.InputStream. It allows
- * for uniform access to streamed resources.
- * The main difference with the java equivalent is a performance improvement.
- * When reading data, data is not copied into a buffer provided by the caller,
- * but a pointer to the read data is provided. This makes this interface
- * especially useful for deriving from it and implementing filterers or
- * transformers.
- */
-// java mapping: long=int64, int=int32, byte=uint8_t
-template <class T>
-class StreamBase {
-protected:
- int64_t size;
- int64_t position;
- std::string error;
- StreamStatus status;
-public:
- StreamBase() :size(-1), position(0), status(Ok){ }
- virtual ~StreamBase(){}
- /**
- * @brief Return a string representation of the last error.
- * If no error has occurred, an empty string is returned.
- **/
- const char* getError() const { return error.c_str(); }
- StreamStatus getStatus() const { return status; }
- /**
- * @brief Get the current position in the stream.
- * The value obtained from this function can be used to reset the stream.
- **/
- int64_t getPosition() const { return position; }
- /**
- * @brief Return the size of the stream.
- * If the size of the stream is unknown, -1
- * is returned. If the end of the stream has been reached the size is
- * always known.
- **/
- int64_t getSize() const { return size; }
- /**
- * @brief Reads characters from the stream and sets \a start to
- * the first character that was read.
- *
- * If @p ntoread is @c 0, then at least one character will be read.
- *
- * @param start Pointer passed by reference that will be set to point to
- * the retrieved array of characters. If the end of the stream
- * is encountered or an error occurs, the value of @p start
- * is undefined.
- * @param ntoread The number of characters to read from the stream. If
- * @p is @c 0 the stream reads at least 1 character.
- * @return the number of characters that were read. If -1 is returned, the
- * end of the stream has been reached. If -2 is returned, an error
- * has occurred.
- **/
- virtual int32_t read(const T*& start, int32_t min, int32_t max) = 0;
- /**
- * Skip @param ntoskip bytes. Unless an error occurs or the end of file is
- * encountered, this amount of bytes is skipped.
- * This function returns new position in the stream.
- **/
- virtual int64_t skip(int64_t ntoskip);
- /**
- * @brief Repositions this stream to gi...
[truncated message content] |