Home || Architecture || Video Search || Visual Search || Scripts || Applications || 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 FileCopyRemoteToLocal(std::string remoteFileName, std::string localFileName)
00041 {
00042     ILOG_VAR(Util.FileCopyRemoteToLocal);
00043     IOBufferFile local(localFileName, false, false);
00044     if (!local.Valid())
00045     {
00046         ILOG_ERROR("Unable to open local : " << localFileName);
00047         return;
00048     }
00049     IOBufferChannel remote(remoteFileName, true);
00050     if (!remote.Valid())
00051     {
00052         ILOG_ERROR("Unable to open remote : " << remoteFileName);
00053         return;
00054     }
00055     int bufSize = Channel::DATA_BUFFER_SIZE - 100; // leave room for comm info
00056     char* buf = new char[bufSize];
00057     while (remote.Available() > 0)
00058     {
00059         int nrRead = remote.Read(buf, bufSize);
00060         local.Write(buf, nrRead);
00061     }
00062     delete buf;
00063 }
00064 
00065 inline void
00066 FileCopyRemoteToLocal(IOBuffer* remoteBuffer, std::string localFileName)
00067 {
00068     ILOG_VAR(Util.FileCopyRemoteToLocal);
00069     IOBufferFile local(localFileName, false, false);
00070     if (!local.Valid())
00071     {
00072         ILOG_ERROR("Unable to open local : " << localFileName);
00073         return;
00074     }
00075     if (!remoteBuffer->Valid())
00076     {
00077         ILOG_ERROR("Invalid remoteBuffer : " << remoteBuffer);
00078         return;
00079     }
00080     int bufSize = Channel::DATA_BUFFER_SIZE - 100; // leave room for comm info
00081     char* buf = new char[bufSize];
00082     while (remoteBuffer->Available() > 0)
00083     {
00084         int nrRead = remoteBuffer->Read(buf, bufSize);
00085         local.Write(buf, nrRead);
00086     }
00087     delete buf;
00088 }
00089 
00090 } // namespace Util
00091 } // namespace Impala
00092 
00093 #endif

Generated on Fri Mar 19 09:31:46 2010 for ImpalaSrc by  doxygen 1.5.1