Thanks for your patch. Looking over it, it looks like the output stream would still not be
closed in the case where there were not any errors.
I committed a modified patch to SVN as well as went through and added javadocs to
the relevant interfaces making it more obvious that these streams need to be closed by the
calling code. Could you take a look at the changes and post back if you see any problems.
As for the build, we are using Maven now rather than Ant. The Maven build is working
fine on my system. What version of Maven are you using? and what is the failure you are
seeing?
To build the whole tree, cd into the Excalibur root and run:
maven multiproject:install
Cheers, Leif
Vadim Gritsenko wrote:
Hi all,
Currently SourceUtil.copy(Source, Source) does not:
* Close InputStream when its done with it * Cancel OutputStream when failed to copy
Attached patch fixes these issues. Can somebody apply it?
PS I found no ant script, and maven fails - is it normal?
Thanks, Vadim
------------------------------------------------------------------------
Index: components/sourceresolve/src/java/org/apache/excalibur/source/SourceUtil.java
===================================================================
--- components/sourceresolve/src/java/org/apache/excalibur/source/SourceUtil.java (revision 47353)
+++ components/sourceresolve/src/java/org/apache/excalibur/source/SourceUtil.java (working copy)
@@ -1,29 +1,34 @@
-/* +/*
* Copyright 2002-2004 The Apache Software Foundation
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at - * + * You may obtain a copy of the License at
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- * + *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied.
- * + *
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.excalibur.source;
-import java.io.*; +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.io.OutputStreamWriter; +import java.io.UnsupportedEncodingException; import java.util.BitSet; import java.util.Iterator;
import org.apache.avalon.framework.parameters.Parameters;
/** - * * Utility class for source resolving. * * @author <a href="mailto:[email protected]">Avalon Development Team</a> @@ -493,16 +498,36 @@ "' is not writeable"); }
+ InputStream in = null; + OutputStream out = null; try { - OutputStream out = ((ModifiableSource) destination).getOutputStream(); - InputStream in = source.getInputStream(); + out = ((ModifiableSource) destination).getOutputStream(); + in = source.getInputStream();
copy(in, out); } catch (IOException ioe) { + if (out != null && ((ModifiableSource) destination).canCancel(out)) { + try { + ((ModifiableSource) destination).cancel(out); + } catch (IOException e) { + throw new SourceException("Could not copy source '" + + source.getURI() + "' to '" + + destination.getURI() + "' (" + + ioe.getMessage() + + ") and can't cancel output: " + + e.getMessage(), ioe); + } + } + throw new SourceException("Could not copy source '"+ source.getURI()+"' to '"+ destination.getURI()+"' :"+ ioe.getMessage(), ioe); + } finally { + try { + if (in != null) + in.close(); + } catch (IOException ignored) { } } } }
------------------------------------------------------------------------
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] Apache Excalibur Project -- URL: http://excalibur.apache.org/
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] Apache Excalibur Project -- URL: http://excalibur.apache.org/
