00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include <mxcpcStreamFileDumper.h>
00018 #include <mxcpc_exceptions.h>
00019
00020
00021
00022 mxcpcStreamFileDumper::mxcpcStreamFileDumper(mxcpcStreamSource *stream_source,
00023 const char *filename) {
00024
00025 Source = stream_source;
00026
00027 OutFile = 0;
00028
00029 try {
00030
00031 OutFile = std::fopen(filename, "w");
00032 if(!OutFile) throw mxcpcIOFailure();
00033
00034 } catch(std::exception &e) {
00035
00036 MXCPC_RETHROW_UNHANDLED_EXCEPTION(e);
00037
00038 if(OutFile) std::fclose(OutFile);
00039
00040 throw;
00041 }
00042 }
00043
00044
00045 mxcpcStreamFileDumper::~mxcpcStreamFileDumper() {
00046
00047 delete Source;
00048
00049 std::fclose(OutFile);
00050 }
00051
00052
00053
00054 int mxcpcStreamFileDumper::fetchBytes(unsigned char *buffer, int num) {
00055
00056 int actually_fetched;
00057
00058 actually_fetched = Source->fetchBytes(buffer, num);
00059
00060 if(actually_fetched) {
00061
00062 fwrite(buffer, actually_fetched, 1, OutFile);
00063 }
00064
00065 return(actually_fetched);
00066 }