[jboss-svn-commits] JBL Code SVN: r11640 - in labs/jbossesb/trunk/product/core: rosetta/src/org/jboss/internal/soa/esb/couriers and 3 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Thu May 3 08:17:36 EDT 2007
Author: kevin.conner at jboss.com
Date: 2007-05-03 08:17:36 -0400 (Thu, 03 May 2007)
New Revision: 11640
Added:
labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/util/FileUtil.java
Modified:
labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/FileGatewayListener.java
labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/RemoteGatewayListener.java
labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/couriers/FileCourier.java
labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/couriers/helpers/LocalFileHandler.java
labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/util/EdtFtpImpl.java
labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/util/SecureFtpImpl.java
labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/util/FtpClientUtil.java
Log:
Tidied up file copying and ftp mismatch: JBESB-542
Modified: labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/FileGatewayListener.java
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/FileGatewayListener.java 2007-05-03 11:28:34 UTC (rev 11639)
+++ labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/FileGatewayListener.java 2007-05-03 12:17:36 UTC (rev 11640)
@@ -35,6 +35,7 @@
import org.jboss.soa.esb.message.Message;
import org.jboss.soa.esb.message.format.MessageFactory;
import org.jboss.soa.esb.services.registry.RegistryException;
+import org.jboss.soa.esb.util.FileUtil;
import org.jboss.soa.esb.util.Util;
public class FileGatewayListener extends AbstractFileGateway
@@ -159,12 +160,7 @@
+ to.getAbsolutePath());
}
- if (!from.renameTo(to))
- {
- copyFile(from, to);
- from.delete();
- }
- return true;
+ return FileUtil.renameTo(from, to) ;
}
@Override
@@ -178,74 +174,6 @@
+ " - Using default composer class : " + _composerName);
}
- protected void copyFile(final File from, final File to)
- throws GatewayException
- {
- final FileInputStream fis;
- try
- {
- fis = new FileInputStream(from);
- }
- catch (final IOException ioe)
- {
- throw new GatewayException("Could not open input file for reading",
- ioe);
- }
- try
- {
- final FileOutputStream fos;
- try
- {
- fos = new FileOutputStream(to);
- }
- catch (final IOException ioe)
- {
- throw new GatewayException(
- "Could not open output file for writing", ioe);
- }
-
- try
- {
- final long filesize = from.length();
- final byte[] buffer = (filesize > 256 ? new byte[256]
- : new byte[(int) filesize]);
- while (true)
- {
- final int count = fis.read(buffer);
- if (count <= 0)
- {
- break;
- }
- fos.write(buffer, 0, count);
- }
- }
- catch (final IOException ioe)
- {
- throw new GatewayException("Error copying file", ioe);
- }
- finally
- {
- try
- {
- fos.close();
- }
- catch (final IOException ioe)
- {
- } // ignore
- }
- }
- finally
- {
- try
- {
- fis.close();
- }
- catch (final IOException ioe)
- {
- } // ignore
- }
- }
-
// ______________________________________________________________________________
/**
* Default gateway action for files <p/>It will just drop the file contents
Modified: labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/RemoteGatewayListener.java
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/RemoteGatewayListener.java 2007-05-03 11:28:34 UTC (rev 11639)
+++ labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/RemoteGatewayListener.java 2007-05-03 12:17:36 UTC (rev 11640)
@@ -129,7 +129,7 @@
FTPEpr ftpEpr = (FTPEpr) epr;
rfs = RemoteFileSystemFactory.getRemoteFileSystem(ftpEpr, true);
rfs.setRemoteDir(FtpClientUtil.fileToFtpString(_inputDirectory));
- rfs.downloadFile(file.toString(), temp.getName());
+ rfs.downloadFile(file.toString(), temp.getAbsolutePath());
final byte[] contents = super.getFileContents(temp);
temp.delete() ;
return contents ;
Modified: labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/couriers/FileCourier.java
===================================================================
--- labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/couriers/FileCourier.java 2007-05-03 11:28:34 UTC (rev 11639)
+++ labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/couriers/FileCourier.java 2007-05-03 12:17:36 UTC (rev 11640)
@@ -45,6 +45,7 @@
import org.jboss.soa.esb.couriers.CourierException;
import org.jboss.soa.esb.couriers.CourierUtil;
import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.util.FileUtil;
import org.jboss.soa.esb.util.Util;
/**
@@ -241,7 +242,7 @@
tmpFile = CourierUtil.messageToLocalFile(dir, message);
File messageFile = new File(dir, name);
- tmpFile.renameTo(messageFile);
+ FileUtil.renameTo(tmpFile, messageFile);
tmpFile = messageFile;
upload.invoke(handler, new Object[]
Modified: labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/couriers/helpers/LocalFileHandler.java
===================================================================
--- labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/couriers/helpers/LocalFileHandler.java 2007-05-03 11:28:34 UTC (rev 11639)
+++ labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/couriers/helpers/LocalFileHandler.java 2007-05-03 12:17:36 UTC (rev 11640)
@@ -33,6 +33,7 @@
import org.apache.log4j.Logger;
import org.jboss.soa.esb.addressing.eprs.FileEpr;
import org.jboss.soa.esb.couriers.CourierException;
+import org.jboss.soa.esb.util.FileUtil;
import org.jboss.soa.esb.util.Util;
public class LocalFileHandler implements FileHandler
@@ -113,7 +114,7 @@
{
if (to.exists())
to.delete();
- if (!from.renameTo(to))
+ if (!FileUtil.renameTo(from, to))
throw new CourierException("Unable to rename from " + from
+ " to " + to);
Modified: labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/util/EdtFtpImpl.java
===================================================================
--- labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/util/EdtFtpImpl.java 2007-05-03 11:28:34 UTC (rev 11639)
+++ labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/util/EdtFtpImpl.java 2007-05-03 12:17:36 UTC (rev 11640)
@@ -37,6 +37,7 @@
import org.jboss.soa.esb.common.ModulePropertyManager;
import org.jboss.soa.esb.helpers.ConfigTree;
import org.jboss.soa.esb.helpers.KeyValuePair;
+import org.jboss.soa.esb.util.FileUtil;
import org.jboss.soa.esb.util.FtpClientUtil;
import org.jboss.soa.esb.util.RemoteFileSystem;
import org.jboss.soa.esb.util.RemoteFileSystemException;
@@ -315,12 +316,13 @@
throw new RemoteFileSystemException(ex);
}
- File oNew = new File(oLocalDir, p_sFinalName);
+ final File to = new File(p_sFinalName) ;
+ final File oNew = (to.isAbsolute() ? to : new File(oLocalDir, p_sFinalName)) ;
if (oNew.exists())
oNew.delete();
- oLclFile.renameTo(oNew);
+ FileUtil.renameTo(oLclFile, oNew);
}
/*
Modified: labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/util/SecureFtpImpl.java
===================================================================
--- labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/util/SecureFtpImpl.java 2007-05-03 11:28:34 UTC (rev 11639)
+++ labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/util/SecureFtpImpl.java 2007-05-03 12:17:36 UTC (rev 11640)
@@ -41,6 +41,7 @@
import org.jboss.soa.esb.common.ModulePropertyManager;
import org.jboss.soa.esb.helpers.ConfigTree;
import org.jboss.soa.esb.helpers.KeyValuePair;
+import org.jboss.soa.esb.util.FileUtil;
import org.jboss.soa.esb.util.RemoteFileSystem;
import org.jboss.soa.esb.util.RemoteFileSystemException;
@@ -526,7 +527,7 @@
File oNew = new File(oLocalDir, p_sFinalName);
if (oNew.exists())
oNew.delete();
- oLclFile.renameTo(oNew);
+ FileUtil.renameTo(oLclFile, oNew);
}
catch (Exception ex)
{
Added: labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/util/FileUtil.java
===================================================================
--- labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/util/FileUtil.java (rev 0)
+++ labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/util/FileUtil.java 2007-05-03 12:17:36 UTC (rev 11640)
@@ -0,0 +1,152 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.soa.esb.util;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+
+import org.apache.log4j.Logger;
+
+/**
+ * Common file utility functions.
+ * @author kevin
+ */
+public class FileUtil
+{
+ /**
+ * The logger for this class.
+ */
+ private final static Logger LOGGER = Logger.getLogger(FileUtil.class) ;
+
+ /**
+ * Attempt to rename a file
+ * @param from The original file
+ * @param to The destination file.
+ * @return true if the rename succeeded, false otherwise
+ */
+ public static boolean renameTo(final File from, final File to)
+ {
+ if (!from.renameTo(to))
+ {
+ final File tmpFile ;
+ try
+ {
+ tmpFile = File.createTempFile("copy", ".tmp", to.getParentFile()) ;
+ }
+ catch (final IOException ioe)
+ {
+ LOGGER.debug("Could not create temporary file for writing", ioe) ;
+ return false ;
+ }
+
+ try
+ {
+ copyFile(from, tmpFile) ;
+ if (!tmpFile.renameTo(to))
+ {
+ LOGGER.debug("Could not rename temporary file " + tmpFile.getAbsolutePath()) ;
+ return false ;
+ }
+ from.delete();
+ }
+ finally
+ {
+ tmpFile.delete() ;
+ }
+ }
+ return true;
+ }
+
+ /**
+ * Attempt to copy the file.
+ * @param from The original file
+ * @param to The destination file.
+ */
+ private static boolean copyFile(final File from, final File to)
+ {
+ final FileInputStream fis;
+ try
+ {
+ fis = new FileInputStream(from);
+ }
+ catch (final IOException ioe)
+ {
+ LOGGER.debug("Could not open input file for reading", ioe) ;
+ return false ;
+ }
+ try
+ {
+ final FileOutputStream fos;
+ try
+ {
+ fos = new FileOutputStream(to);
+ }
+ catch (final IOException ioe)
+ {
+ LOGGER.debug("Could not open output file for writing", ioe);
+ return false ;
+ }
+
+ try
+ {
+ final long filesize = from.length();
+ final byte[] buffer = (filesize > 256 ? new byte[256]
+ : new byte[(int) filesize]);
+ while (true)
+ {
+ final int count = fis.read(buffer);
+ if (count <= 0)
+ {
+ break;
+ }
+ fos.write(buffer, 0, count);
+ }
+ }
+ catch (final IOException ioe)
+ {
+ LOGGER.debug("Error copying file", ioe);
+ to.delete() ;
+ return false ;
+ }
+ finally
+ {
+ try
+ {
+ fos.close();
+ }
+ catch (final IOException ioe) {} // ignore
+ }
+ }
+ finally
+ {
+ try
+ {
+ fis.close();
+ }
+ catch (final IOException ioe) {} // ignore
+ }
+ return true ;
+ }
+}
Property changes on: labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/util/FileUtil.java
___________________________________________________________________
Name: svn:keywords
+ Rev Date
Name: svn:eol-style
+ native
Modified: labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/util/FtpClientUtil.java
===================================================================
--- labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/util/FtpClientUtil.java 2007-05-03 11:28:34 UTC (rev 11639)
+++ labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/util/FtpClientUtil.java 2007-05-03 12:17:36 UTC (rev 11640)
@@ -402,7 +402,7 @@
if (oNew.exists())
oNew.delete();
- oLclFile.renameTo(oNew);
+ FileUtil.renameTo(oLclFile, oNew);
}
catch (FTPException ex)
{
More information about the jboss-svn-commits
mailing list