comparison Core/Compression/ZipWriter.cpp @ 2954:d924f9bb61cc

taking advantage of details in OrthancException
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 03 Dec 2018 14:35:34 +0100
parents 878b59270859
children 4e43e67f8ecf
comparison
equal deleted inserted replaced
2953:210d5afd8f2b 2954:d924f9bb61cc
122 return; 122 return;
123 } 123 }
124 124
125 if (path_.size() == 0) 125 if (path_.size() == 0)
126 { 126 {
127 LOG(ERROR) << "Please call SetOutputPath() before creating the file"; 127 throw OrthancException(ErrorCode_BadSequenceOfCalls,
128 throw OrthancException(ErrorCode_BadSequenceOfCalls); 128 "Please call SetOutputPath() before creating the file");
129 } 129 }
130 130
131 hasFileInZip_ = false; 131 hasFileInZip_ = false;
132 132
133 int mode = APPEND_STATUS_CREATE; 133 int mode = APPEND_STATUS_CREATE;
166 166
167 void ZipWriter::SetCompressionLevel(uint8_t level) 167 void ZipWriter::SetCompressionLevel(uint8_t level)
168 { 168 {
169 if (level >= 10) 169 if (level >= 10)
170 { 170 {
171 LOG(ERROR) << "ZIP compression level must be between 0 (no compression) and 9 (highest compression)"; 171 throw OrthancException(ErrorCode_ParameterOutOfRange,
172 throw OrthancException(ErrorCode_ParameterOutOfRange); 172 "ZIP compression level must be between 0 (no compression) and 9 (highest compression)");
173 } 173 }
174 174
175 Close(); 175 Close();
176 compressionLevel_ = level; 176 compressionLevel_ = level;
177 } 177 }
226 226
227 void ZipWriter::Write(const char* data, size_t length) 227 void ZipWriter::Write(const char* data, size_t length)
228 { 228 {
229 if (!hasFileInZip_) 229 if (!hasFileInZip_)
230 { 230 {
231 LOG(ERROR) << "Call first OpenFile()"; 231 throw OrthancException(ErrorCode_BadSequenceOfCalls, "Call first OpenFile()");
232 throw OrthancException(ErrorCode_BadSequenceOfCalls);
233 } 232 }
234 233
235 const size_t maxBytesInAStep = std::numeric_limits<int32_t>::max(); 234 const size_t maxBytesInAStep = std::numeric_limits<int32_t>::max();
236 235
237 while (length > 0) 236 while (length > 0)