mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2024-12-28 14:32:38 +03:00
closing gz file
This commit is contained in:
parent
a1721d9801
commit
ebc33f63e9
@ -12,7 +12,7 @@ exe extract-rules : tables-core.o SentenceAlignment.cpp SentenceAlignmentWithSyn
|
||||
|
||||
exe extract-lex : extract-lex.cpp InputFileStream ;
|
||||
|
||||
exe score : tables-core.o AlignmentPhrase.o score.cpp PhraseAlignment.cpp InputFileStream ../../..//boost_iostreams ;
|
||||
exe score : tables-core.o AlignmentPhrase.o score.cpp PhraseAlignment.cpp OutputFileStream.cpp InputFileStream ../../..//boost_iostreams ;
|
||||
|
||||
exe consolidate : consolidate.cpp tables-core.o InputFileStream ;
|
||||
|
||||
|
@ -30,11 +30,13 @@ namespace Moses
|
||||
OutputFileStream::OutputFileStream()
|
||||
:boost::iostreams::filtering_ostream()
|
||||
,m_outFile(NULL)
|
||||
,m_isGZ(false)
|
||||
{
|
||||
}
|
||||
|
||||
OutputFileStream::OutputFileStream(const std::string &filePath)
|
||||
: m_outFile(NULL)
|
||||
, m_isGZ(false)
|
||||
{
|
||||
Open(filePath);
|
||||
}
|
||||
@ -42,16 +44,16 @@ OutputFileStream::OutputFileStream(const std::string &filePath)
|
||||
OutputFileStream::~OutputFileStream()
|
||||
{
|
||||
Close();
|
||||
delete m_outFile;
|
||||
m_outFile = NULL;
|
||||
}
|
||||
|
||||
bool OutputFileStream::Open(const std::string &filePath)
|
||||
{
|
||||
m_outFile = new ofstream(filePath.c_str(), ios_base::out | ios_base::binary);
|
||||
|
||||
if (filePath.size() > 3 && filePath.substr(filePath.size() - 3, 3) == ".gz") {
|
||||
if (filePath.size() > 3 && filePath.substr(filePath.size() - 3, 3) == ".gz")
|
||||
{
|
||||
this->push(boost::iostreams::gzip_compressor());
|
||||
m_isGZ = true;
|
||||
}
|
||||
this->push(*m_outFile);
|
||||
|
||||
@ -60,7 +62,19 @@ bool OutputFileStream::Open(const std::string &filePath)
|
||||
|
||||
void OutputFileStream::Close()
|
||||
{
|
||||
this->pop();
|
||||
this->flush();
|
||||
if (m_outFile == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_isGZ) {
|
||||
this->pop();
|
||||
}
|
||||
|
||||
//this->close();
|
||||
m_outFile->close();
|
||||
delete m_outFile;
|
||||
m_outFile = NULL;
|
||||
}
|
||||
|
||||
|
||||
|
@ -35,6 +35,7 @@ namespace Moses
|
||||
class OutputFileStream : public boost::iostreams::filtering_ostream
|
||||
{
|
||||
protected:
|
||||
bool m_isGZ;
|
||||
std::ofstream *m_outFile;
|
||||
public:
|
||||
OutputFileStream();
|
||||
|
@ -190,12 +190,9 @@ int main(int argc, char* argv[])
|
||||
}
|
||||
else {
|
||||
Moses::OutputFileStream *outputFile = new Moses::OutputFileStream();
|
||||
//ofstream *outputFile = new ofstream();
|
||||
//outputFile->open(fileNamePhraseTable);
|
||||
|
||||
//if (outputFile->fail()) {
|
||||
|
||||
{
|
||||
bool success = outputFile->Open(fileNamePhraseTable);
|
||||
|
||||
if (!success) {
|
||||
cerr << "ERROR: could not open file phrase table file "
|
||||
<< fileNamePhraseTable << endl;
|
||||
exit(1);
|
||||
@ -250,7 +247,7 @@ int main(int argc, char* argv[])
|
||||
|
||||
phraseTableFile->flush();
|
||||
if (phraseTableFile != &cout) {
|
||||
(dynamic_cast<ofstream*>(phraseTableFile))->close();
|
||||
//(dynamic_cast<ofstream*>(phraseTableFile))->close();
|
||||
delete phraseTableFile;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user