You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2009/03/09 14:19:27 UTC
svn commit: r751673 - in
/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file:
GenericFile.java GenericFileExchange.java
Author: davsclaus
Date: Mon Mar 9 13:19:26 2009
New Revision: 751673
URL: http://svn.apache.org/viewvc?rev=751673&view=rev
Log:
CAMEL-1428: Reduced unneeded code when computing renamed filename.
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFile.java
camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileExchange.java
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFile.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFile.java?rev=751673&r1=751672&r2=751673&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFile.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFile.java Mon Mar 9 13:19:26 2009
@@ -87,54 +87,37 @@
* @param newName the new name
*/
public void changeFileName(String newName) {
- // TODO: Should be TRACE
- if (LOG.isDebugEnabled()) {
- LOG.debug("Changing name to: " + newName);
+ if (LOG.isTraceEnabled()) {
+ LOG.trace("Changing name to: " + newName);
}
// use java.io.File to help us with computing name changes
File file = new File(newName);
- boolean nameChangeOnly = newName.indexOf(getFileSeparator()) == -1;
boolean absolute = file.isAbsolute();
// store the file name only
setFileNameOnly(file.getName());
setFileName(file.getName());
- // relative name is a bit more complex
- if (nameChangeOnly) {
- setRelativeFilePath(changeNameOnly(getRelativeFilePath(), file.getName()));
- setFileName(changeNameOnly(getFileName(), file.getName()));
+ // relative path
+ if (file.getParent() != null) {
+ setRelativeFilePath(file.getParent() + getFileSeparator() + file.getName());
} else {
- if (file.getParent() != null) {
- setRelativeFilePath(file.getParent() + getFileSeparator() + file.getName());
- } else {
- setRelativeFilePath(file.getName());
- }
+ setRelativeFilePath(file.getName());
}
- // absolute vs relative
+ // absolute path
if (absolute) {
setAbsolute(true);
setAbsoluteFilePath(file.getAbsolutePath());
} else {
setAbsolute(false);
- // construct a pseudo absolute filename that the file operations uses
+ // construct a pseudo absolute filename that the file operations uses even for relative only
setAbsoluteFilePath(endpointPath + getFileSeparator() + getRelativeFilePath());
}
- // TODO: Should be TRACE
- if (LOG.isDebugEnabled()) {
- LOG.debug("Name changed: " + this);
- }
- }
-
- private String changeNameOnly(String path, String name) {
- int pos = path.lastIndexOf(getFileSeparator());
- if (pos != -1) {
- return path.substring(0, pos + 1) + name;
- } else {
- return name;
+ if (LOG.isTraceEnabled()) {
+ LOG.trace("Name changed to: " + this);
}
}
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileExchange.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileExchange.java?rev=751673&r1=751672&r2=751673&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileExchange.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileExchange.java Mon Mar 9 13:19:26 2009
@@ -69,7 +69,7 @@
if (file.isAbsolute()) {
getIn().setHeader("CamelFilePath", file.getAbsoluteFilePath());
} else {
- // we must normal path according to protocol if we build our own paths
+ // we must normalize path according to protocol if we build our own paths
String path = file.normalizePathToProtocol(file.getEndpointPath() + File.separator + file.getRelativeFilePath());
getIn().setHeader("CamelFilePath", path);
}