Home || Visual Search || Applications || Architecture || Important Messages || OGL || Src

FileCopy.h

Go to the documentation of this file.
00001 #ifndef Impala_Util_FileCopy_h
00002 #define Impala_Util_FileCopy_h
00003 
00004 #include "Util/IOBufferFile.h"
00005 #include "Util/IOBufferChannel.h"
00006 
00007 namespace Impala
00008 {
00009 namespace Util
00010 {
00011 
00012 
00013 inline void
00014 FileCopyLocalToRemote(std::string localFileName, std::string remoteFileName)
00015 {
00016     ILOG_VAR(Util.FileCopyLocalToRemote);
00017     IOBufferFile local(localFileName, true, false);
00018     if (!local.Valid())
00019     {
00020         ILOG_ERROR("Unable to open local : " << localFileName);
00021         return;
00022     }
00023     IOBufferChannel remote(remoteFileName, false);
00024     if (!remote.Valid())
00025     {
00026         ILOG_ERROR("Unable to open remote : " << remoteFileName);
00027         return;
00028     }
00029     int bufSize = Channel::DATA_BUFFER_SIZE - 100; // leave room for comm info
00030     char* buf = new char[bufSize];
00031     while (local.Available() > 0)
00032     {
00033         int nrRead = local.Read(buf, bufSize);
00034         remote.Write(buf, nrRead);
00035     }
00036     delete buf;
00037 }
00038 
00039 inline void
00040 FileCopyLocalToRemote(std::string localFileName, IOBuffer* remoteBuffer)
00041 {
00042     ILOG_VAR(Util.FileCopyLocalToRemote);
00043     IOBufferFile local(localFileName, true, false);
00044     if (!local.Valid())
00045     {
00046         ILOG_ERROR("Unable to open local : " << localFileName);
00047         return;
00048     }
00049     if (!remoteBuffer->Valid())
00050     {
00051         ILOG_ERROR("Invalid remote buffer : " << remoteBuffer);
00052         return;
00053     }
00054     int bufSize = Channel::DATA_BUFFER_SIZE - 100; // leave room for comm info
00055     char* buf = new char[bufSize];
00056     while (local.Available() > 0)
00057     {
00058         int nrRead = local.Read(buf, bufSize);
00059         remoteBuffer->Write(buf, nrRead);
00060     }
00061     delete buf;
00062 }
00063 
00064 inline void
00065 FileCopyRemoteToLocal(std::string remoteFileName, std::string localFileName)
00066 {
00067     ILOG_VAR(Util.FileCopyRemoteToLocal);
00068     IOBufferFile local(localFileName, false, false);
00069     if (!local.Valid())
00070     {
00071         ILOG_ERROR("Unable to open local : " << localFileName);
00072         return;
00073     }
00074     IOBufferChannel remote(remoteFileName, true);
00075     if (!remote.Valid())
00076     {
00077         ILOG_ERROR("Unable to open remote : " << remoteFileName);
00078         return;
00079     }
00080     int bufSize = Channel::DATA_BUFFER_SIZE - 100; // leave room for comm info
00081     char* buf = new char[bufSize];
00082     while (remote.Available() > 0)
00083     {
00084         int nrRead = remote.Read(buf, bufSize);
00085         local.Write(buf, nrRead);
00086     }
00087     delete buf;
00088 }
00089 
00090 inline void
00091 FileCopyRemoteToLocal(IOBuffer* remoteBuffer, std::string localFileName)
00092 {
00093     ILOG_VAR(Util.FileCopyRemoteToLocal);
00094     IOBufferFile local(localFileName, false, false);
00095     if (!local.Valid())
00096     {
00097         ILOG_ERROR("Unable to open local : " << localFileName);
00098         return;
00099     }
00100     if (!remoteBuffer->Valid())
00101     {
00102         ILOG_ERROR("Invalid remoteBuffer : " << remoteBuffer);
00103         return;
00104     }
00105     int bufSize = Channel::DATA_BUFFER_SIZE - 100; // leave room for comm info
00106     char* buf = new char[bufSize];
00107     while (remoteBuffer->Available() > 0)
00108     {
00109         int nrRead = remoteBuffer->Read(buf, bufSize);
00110         local.Write(buf, nrRead);
00111     }
00112     delete buf;
00113 }
00114 
00115 } // namespace Util
00116 } // namespace Impala
00117 
00118 #endif

Generated on Thu Jan 13 09:05:15 2011 for ImpalaSrc by  doxygen 1.5.1