Author: thorsten
Date: Thu Sep 25 03:36:37 2008
New Revision: 698919
URL: http://svn.apache.org/viewvc?rev=698919&view=rev
Log:
Extracting another helper method closeStream
Modified:
forrest/trunk/whiteboard/dispatcher/java/org/apache/forrest/dispatcher/impl/XMLStructurer.java
forrest/trunk/whiteboard/dispatcher/java/org/apache/forrest/dispatcher/impl/helper/StreamHelper.java
Modified:
forrest/trunk/whiteboard/dispatcher/java/org/apache/forrest/dispatcher/impl/XMLStructurer.java
URL:
http://svn.apache.org/viewvc/forrest/trunk/whiteboard/dispatcher/java/org/apache/forrest/dispatcher/impl/XMLStructurer.java?rev=698919&r1=698918&r2=698919&view=diff
==============================================================================
---
forrest/trunk/whiteboard/dispatcher/java/org/apache/forrest/dispatcher/impl/XMLStructurer.java
(original)
+++
forrest/trunk/whiteboard/dispatcher/java/org/apache/forrest/dispatcher/impl/XMLStructurer.java
Thu Sep 25 03:36:37 2008
@@ -27,6 +27,7 @@
import org.apache.forrest.dispatcher.factories.ContractFactory;
import org.apache.forrest.dispatcher.impl.helper.Captions;
import org.apache.forrest.dispatcher.impl.helper.StAX;
+import org.apache.forrest.dispatcher.impl.helper.StreamHelper;
import org.apache.forrest.dispatcher.utils.CommonString;
import org.xml.sax.InputSource;
@@ -103,13 +104,10 @@
} catch (IOException e) {
throw new DispatcherException(e);
} finally {
- if (null != structurerStream) {
try {
- structurerStream.close();
+ StreamHelper.closeStream(structurerStream);
} catch (IOException e) {
throw new DispatcherException(e);
- }
- ;
}
}
return stream;
@@ -153,8 +151,7 @@
}
}
log.debug(out.toString());
- return (out != null) ? new BufferedInputStream(new ByteArrayInputStream(out
- .toByteArray())) : null;
+ return (out != null) ? StreamHelper.switchStream(out) : null;
}
/**
@@ -232,13 +229,9 @@
elementName = reader.getLocalName();
if (elementName.equals(Captions.CONTRACT_ELEMENT)) {
InputStream resultStream = contract.execute(dataStream, param);
- if (null != dataStream) {
- dataStream.close();
- }
+ StreamHelper.closeStream(dataStream);
processContractResult(resultStream);
- if (null != resultStream) {
- resultStream.close();
- }
+ StreamHelper.closeStream(resultStream);
process = false;
}
break;
@@ -401,8 +394,7 @@
break;
}
}
- InputSource value = new InputSource(new ByteArrayInputStream(out
- .toByteArray()));
+ InputSource value = new InputSource(StreamHelper.switchStream(out));
return value;
}
Modified:
forrest/trunk/whiteboard/dispatcher/java/org/apache/forrest/dispatcher/impl/helper/StreamHelper.java
URL:
http://svn.apache.org/viewvc/forrest/trunk/whiteboard/dispatcher/java/org/apache/forrest/dispatcher/impl/helper/StreamHelper.java?rev=698919&r1=698918&r2=698919&view=diff
==============================================================================
---
forrest/trunk/whiteboard/dispatcher/java/org/apache/forrest/dispatcher/impl/helper/StreamHelper.java
(original)
+++
forrest/trunk/whiteboard/dispatcher/java/org/apache/forrest/dispatcher/impl/helper/StreamHelper.java
Thu Sep 25 03:36:37 2008
@@ -19,6 +19,8 @@
import java.io.BufferedInputStream;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
public class StreamHelper {
/**
@@ -28,4 +30,13 @@
public static BufferedInputStream switchStream(ByteArrayOutputStream out) {
return new BufferedInputStream(new
ByteArrayInputStream(out.toByteArray()));
}
+ /**
+ * @param dataStream
+ * @throws IOException
+ */
+ public static void closeStream(InputStream dataStream) throws IOException {
+ if (null != dataStream) {
+ dataStream.close();
+ }
+ }
}