final String sRemoteTmp = p_sRemoteName + TMP_SUFFIX;
final OutputStream os = m_oConn.storeFileStream(sRemoteTmp) ;
if (os == null)
{
throw new RemoteFileSystemException("Failed to obtain output stream: " + m_oConn.getReplyString()) ;
}
try
{
final FileInputStream fis = new FileInputStream(p_oFile) ;
try
{
copyStream(fis, os) ;
}
finally
{
fis.close() ;
}
}
finally
{
os.flush() ;
os.close() ;
}
if (!m_oConn.completePendingCommand())
{
throw new RemoteFileSystemException("Failed to upload contents: " + m_oConn.getReplyString()) ;
}
boolean retryProblem = true; // https://jira.jboss.org/jira/browse/JBESB-1995
for (int i = 0; i < m_iRenameRetry; i++)
{
if (m_oConn.rename(sRemoteTmp, p_sRemoteName))
{
retryProblem = false;
break;
}
else
{
if (i+1 < m_iRenameRetry)
{
try
{
Thread.sleep(1000L); // 1 second
}
catch (final Exception ex)
{
}
}
}
}
if (retryProblem)
throw new RemoteFileSystemException("Failed to rename file: " + m_oConn.getReplyString());
}
catch (final IOException ioe)
{
throw new RemoteFileSystemException(ioe);
}
}