Author: julien(a)jboss.com
Date: 2007-06-03 15:20:39 -0400 (Sun, 03 Jun 2007)
New Revision: 7374
Added:
trunk/common/src/main/org/jboss/portal/common/io/IOTools.java
trunk/common/src/main/org/jboss/portal/test/common/io/
trunk/common/src/main/org/jboss/portal/test/common/io/IOToolsTestCase.java
Modified:
trunk/cms/src/main/org/jboss/portal/cms/CMSMimeMappings.java
trunk/cms/src/main/org/jboss/portal/cms/hibernate/HibernateStore.java
trunk/cms/src/main/org/jboss/portal/cms/hibernate/state/HibernatePersistenceManager.java
trunk/cms/src/main/org/jboss/portal/cms/hibernate/state/JBossCachePersistenceManager.java
trunk/cms/src/main/org/jboss/portal/cms/impl/jcr/JCRCMS.java
trunk/cms/src/main/org/jboss/portal/test/cms/commands/TestFileArchiveUpload.java
trunk/common/build.xml
trunk/common/src/main/org/jboss/portal/common/i18n/ComplexResourceBundleFactory.java
trunk/common/src/main/org/jboss/portal/common/junit/ExtendedAssert.java
trunk/common/src/main/org/jboss/portal/common/logging/LoaderRepositorySelector.java
trunk/common/src/main/org/jboss/portal/common/util/LoaderResource.java
trunk/common/src/main/org/jboss/portal/common/util/Tools.java
trunk/common/src/main/org/jboss/portal/common/util/URLTools.java
trunk/common/src/main/org/jboss/portal/test/common/BufferedStreamTestCase.java
trunk/common/src/main/org/jboss/portal/test/common/JarTestCase.java
trunk/core-cms/src/main/org/jboss/portal/core/cms/servlet/CMSExportServlet.java
trunk/core/src/main/org/jboss/portal/core/controller/handler/HTTPResponse.java
trunk/core/src/main/org/jboss/portal/core/deployment/jboss/ObjectDeployment.java
trunk/core/src/main/org/jboss/portal/core/deployment/jboss/PortletAppDeployment.java
trunk/core/src/main/org/jboss/portal/test/core/Utils.java
trunk/format/src/main/org/jboss/portal/format/template/TemplateLoader.java
trunk/jems/src/main/org/jboss/portal/jems/hibernate/ByteArrayBlob.java
trunk/jems/src/main/org/jboss/portal/jems/hibernate/SessionFactoryBinder.java
trunk/portlet-server/src/main/org/jboss/portal/portlet/deployment/jboss/PortletAppDeployment.java
trunk/portlet-server/src/main/org/jboss/portal/portlet/deployment/jboss/PortletAppDeploymentFactory.java
trunk/portlet/src/main/org/jboss/portal/test/portlet/jsr168/ext/portletrequests/PortletRequestsSequenceBuilder.java
trunk/portlet/src/main/org/jboss/portal/test/portlet/session/TestClassLoader.java
trunk/server/src/main/org/jboss/portal/server/deployment/PortalWebApp.java
trunk/test/src/main/org/jboss/portal/test/framework/embedded/DSConfig.java
trunk/test/src/main/org/jboss/portal/test/framework/embedded/DataSourceSupport.java
trunk/test/src/main/org/jboss/portal/test/framework/embedded/HibernateSupport.java
trunk/theme/src/main/org/jboss/portal/theme/deployment/jboss/LayoutDeployment.java
trunk/theme/src/main/org/jboss/portal/theme/deployment/jboss/LayoutFeaturesDeployment.java
trunk/theme/src/main/org/jboss/portal/theme/deployment/jboss/ThemeDeployment.java
trunk/widget/src/main/org/jboss/portal/test/widget/google/PreferencesTestCase.java
trunk/workflow/src/main/org/jboss/portal/workflow/cms/ApprovePublishImpl.java
trunk/wsrp/src/main/org/jboss/portal/wsrp/services/AbstractJNDIServiceFactory.java
trunk/wsrp/src/main/org/jboss/portal/wsrp/services/RemoteSOAPInvokerServiceFactory.java
trunk/wsrp/src/main/org/jboss/portal/wsrp/servlet/RequestDumperFilter.java
Log:
- extracted related IO methods from Tools to io.IOTools
- added test cases for IOTools
Modified: trunk/cms/src/main/org/jboss/portal/cms/CMSMimeMappings.java
===================================================================
--- trunk/cms/src/main/org/jboss/portal/cms/CMSMimeMappings.java 2007-06-03 09:56:50 UTC
(rev 7373)
+++ trunk/cms/src/main/org/jboss/portal/cms/CMSMimeMappings.java 2007-06-03 19:20:39 UTC
(rev 7374)
@@ -22,8 +22,8 @@
******************************************************************************/
package org.jboss.portal.cms;
-import org.jboss.portal.common.util.Tools;
import org.jboss.portal.common.util.XML;
+import org.jboss.portal.common.io.IOTools;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
@@ -67,7 +67,7 @@
}
finally
{
- Tools.safeClose(is);
+ IOTools.safeClose(is);
}
}
Modified: trunk/cms/src/main/org/jboss/portal/cms/hibernate/HibernateStore.java
===================================================================
--- trunk/cms/src/main/org/jboss/portal/cms/hibernate/HibernateStore.java 2007-06-03
09:56:50 UTC (rev 7373)
+++ trunk/cms/src/main/org/jboss/portal/cms/hibernate/HibernateStore.java 2007-06-03
19:20:39 UTC (rev 7374)
@@ -33,7 +33,7 @@
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.jboss.portal.cms.util.HibernateUtil;
-import org.jboss.portal.common.util.Tools;
+import org.jboss.portal.common.io.IOTools;
import org.jboss.logging.Logger;
import java.io.ByteArrayInputStream;
@@ -957,7 +957,7 @@
try
{
long length = f.length();
- in = Tools.safeBufferedWrapper(new FileInputStream(f));
+ in = IOTools.safeBufferedWrapper(new FileInputStream(f));
if
(schemaObjectPrefix.equals(HibernateStoreConstants.versionClassName))
{
Query query = session.createQuery("from VersionEntry
where FSENTRY_PATH = ? and FSENTRY_NAME = ? and FSENTRY_DATA is not null");
@@ -1069,7 +1069,7 @@
}
finally
{
- Tools.safeClose(in);
+ IOTools.safeClose(in);
// temp file can now safely be removed
f.delete();
f = null;
@@ -1141,7 +1141,7 @@
}
finally
{
- Tools.safeClose(out);
+ IOTools.safeClose(out);
// in.close();
}
}
@@ -1166,7 +1166,7 @@
try
{
long length = f.length();
- in = Tools.safeBufferedWrapper(new FileInputStream(f));
+ in = IOTools.safeBufferedWrapper(new FileInputStream(f));
if
(schemaObjectPrefix.equals(HibernateStoreConstants.versionClassName))
{
Query query = session.createQuery("from VersionEntry
where FSENTRY_PATH = ? and FSENTRY_NAME = ? and FSENTRY_DATA is not null");
@@ -1240,7 +1240,7 @@
try
{
long length = f.length();
- in = Tools.safeBufferedWrapper(new FileInputStream(f));
+ in = IOTools.safeBufferedWrapper(new FileInputStream(f));
if
(schemaObjectPrefix.equals(HibernateStoreConstants.versionClassName))
{
VersionEntry versionEntry = new VersionEntry(parentDir, name,
createBlob(in), System.currentTimeMillis(), length);
@@ -1278,7 +1278,7 @@
}
finally
{
- Tools.safeClose(in);
+ IOTools.safeClose(in);
// temp file can now safely be removed
f.delete();
f = null;
@@ -1708,12 +1708,12 @@
{
in = blob.getBinaryStream();
ByteArrayOutputStream out = new ByteArrayOutputStream(in.available());
- Tools.copy(in, out);
+ IOTools.copy(in, out);
return out.toByteArray();
}
finally
{
- Tools.safeClose(in);
+ IOTools.safeClose(in);
}
}
Modified:
trunk/cms/src/main/org/jboss/portal/cms/hibernate/state/HibernatePersistenceManager.java
===================================================================
---
trunk/cms/src/main/org/jboss/portal/cms/hibernate/state/HibernatePersistenceManager.java 2007-06-03
09:56:50 UTC (rev 7373)
+++
trunk/cms/src/main/org/jboss/portal/cms/hibernate/state/HibernatePersistenceManager.java 2007-06-03
19:20:39 UTC (rev 7374)
@@ -49,7 +49,7 @@
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.jboss.portal.cms.hibernate.HibernateStoreConstants;
-import org.jboss.portal.common.util.Tools;
+import org.jboss.portal.common.io.IOTools;
import org.jboss.logging.Logger;
import javax.jcr.PropertyType;
@@ -402,7 +402,7 @@
NodeState state = createNew(id);
Serializer.deserialize(state, in);
- Tools.safeClose(in);
+ IOTools.safeClose(in);
tx.commit();
return state;
}
@@ -448,7 +448,7 @@
PropertyState state = createNew(id);
Serializer.deserialize(state, in, blobStore);
- Tools.safeClose(in);
+ IOTools.safeClose(in);
tx.commit();
return state;
}
@@ -497,7 +497,7 @@
NodeReferences refs = new NodeReferences(targetId);
Serializer.deserialize(refs, in);
- Tools.safeClose(in);
+ IOTools.safeClose(in);
tx.commit();
return refs;
}
Modified:
trunk/cms/src/main/org/jboss/portal/cms/hibernate/state/JBossCachePersistenceManager.java
===================================================================
---
trunk/cms/src/main/org/jboss/portal/cms/hibernate/state/JBossCachePersistenceManager.java 2007-06-03
09:56:50 UTC (rev 7373)
+++
trunk/cms/src/main/org/jboss/portal/cms/hibernate/state/JBossCachePersistenceManager.java 2007-06-03
19:20:39 UTC (rev 7374)
@@ -53,6 +53,7 @@
import org.jboss.mx.util.MBeanProxyExt;
import org.jboss.mx.util.MBeanServerLocator;
import org.jboss.portal.cms.hibernate.HibernateStoreConstants;
+import org.jboss.portal.common.io.IOTools;
import org.jboss.logging.Logger;
import javax.jcr.PropertyType;
@@ -552,7 +553,7 @@
// setup the propertyState
nodeState = createNew(node);
Serializer.deserialize(nodeState, in);
- org.jboss.portal.common.util.Tools.safeClose(in);
+ IOTools.safeClose(in);
tx.commit();
success = true;
@@ -846,7 +847,7 @@
// setup the propertyState
propertyState = createNew(property);
Serializer.deserialize(propertyState, in, blobStore);
- org.jboss.portal.common.util.Tools.safeClose(in);
+ IOTools.safeClose(in);
tx.commit();
success = true;
@@ -1178,7 +1179,7 @@
// setup the propertyState
refs = new NodeReferences(targetId);
Serializer.deserialize(refs, in);
- org.jboss.portal.common.util.Tools.safeClose(in);
+ IOTools.safeClose(in);
tx.commit();
success = true;
Modified: trunk/cms/src/main/org/jboss/portal/cms/impl/jcr/JCRCMS.java
===================================================================
--- trunk/cms/src/main/org/jboss/portal/cms/impl/jcr/JCRCMS.java 2007-06-03 09:56:50 UTC
(rev 7373)
+++ trunk/cms/src/main/org/jboss/portal/cms/impl/jcr/JCRCMS.java 2007-06-03 19:20:39 UTC
(rev 7374)
@@ -45,8 +45,8 @@
import org.jboss.portal.common.invocation.InvocationHandler;
import org.jboss.portal.common.net.URLNavigator;
import org.jboss.portal.common.net.URLVisitor;
-import org.jboss.portal.common.util.Tools;
import org.jboss.portal.common.util.XML;
+import org.jboss.portal.common.io.IOTools;
import org.jboss.portal.jems.as.JNDI;
import org.jboss.portal.identity.User;
import org.jboss.portal.identity.UserModule;
@@ -66,7 +66,6 @@
import javax.jcr.Session;
import javax.transaction.xa.XAResource;
import javax.transaction.xa.Xid;
-import javax.naming.InitialContext;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.net.URL;
@@ -494,11 +493,11 @@
try
{
urlin = url.openStream();
- Tools.copy(urlin, baos);
+ IOTools.copy(urlin, baos);
}
finally
{
- Tools.safeClose(urlin);
+ IOTools.safeClose(urlin);
}
//
@@ -534,7 +533,7 @@
}
finally
{
- Tools.safeClose(in);
+ IOTools.safeClose(in);
}
}
};
Modified:
trunk/cms/src/main/org/jboss/portal/test/cms/commands/TestFileArchiveUpload.java
===================================================================
---
trunk/cms/src/main/org/jboss/portal/test/cms/commands/TestFileArchiveUpload.java 2007-06-03
09:56:50 UTC (rev 7373)
+++
trunk/cms/src/main/org/jboss/portal/test/cms/commands/TestFileArchiveUpload.java 2007-06-03
19:20:39 UTC (rev 7374)
@@ -26,14 +26,13 @@
import org.jboss.portal.cms.CMSException;
import org.jboss.portal.cms.Command;
import org.jboss.portal.cms.model.Folder;
-import org.jboss.portal.common.util.Tools;
+import org.jboss.portal.common.io.IOTools;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import java.util.Locale;
-import java.util.Map;
/**
@@ -77,7 +76,7 @@
public void testArchiveUpload() throws CMSException, IOException
{
service.setDefaultLocale(Locale.ENGLISH.getLanguage());
- InputStream is = Tools.safeBufferedWrapper(new FileInputStream(sZipFile));
+ InputStream is = IOTools.safeBufferedWrapper(new FileInputStream(sZipFile));
Command storearchiveCMD =
service.getCommandFactory().createStoreArchiveCommand("", is, "en");
List contentsToVersion = (List)service.execute(storearchiveCMD);
Modified: trunk/common/build.xml
===================================================================
--- trunk/common/build.xml 2007-06-03 09:56:50 UTC (rev 7373)
+++ trunk/common/build.xml 2007-06-03 19:20:39 UTC (rev 7374)
@@ -210,6 +210,7 @@
</x-sysproperty>
<x-test>
+ <test todir="${test.reports}"
name="org.jboss.portal.test.common.io.IOToolsTestCase"/>
<test todir="${test.reports}"
name="org.jboss.portal.test.common.reflect.ReflectionTestCase"/>
<test todir="${test.reports}"
name="org.jboss.portal.test.common.reflect.ModifierTestCase"/>
<test todir="${test.reports}"
name="org.jboss.portal.test.common.test.junit.POJOJunitTestTestCase"/>
Modified:
trunk/common/src/main/org/jboss/portal/common/i18n/ComplexResourceBundleFactory.java
===================================================================
---
trunk/common/src/main/org/jboss/portal/common/i18n/ComplexResourceBundleFactory.java 2007-06-03
09:56:50 UTC (rev 7373)
+++
trunk/common/src/main/org/jboss/portal/common/i18n/ComplexResourceBundleFactory.java 2007-06-03
19:20:39 UTC (rev 7374)
@@ -22,7 +22,7 @@
******************************************************************************/
package org.jboss.portal.common.i18n;
-import org.jboss.portal.common.util.Tools;
+import org.jboss.portal.common.io.IOTools;
import java.io.IOException;
import java.io.InputStream;
@@ -105,7 +105,7 @@
{
try
{
- in = Tools.safeBufferedWrapper(in);
+ in = IOTools.safeBufferedWrapper(in);
return new PropertyResourceBundle(in);
}
catch (IOException e)
@@ -113,7 +113,7 @@
}
finally
{
- Tools.safeClose(in);
+ IOTools.safeClose(in);
}
}
Added: trunk/common/src/main/org/jboss/portal/common/io/IOTools.java
===================================================================
--- trunk/common/src/main/org/jboss/portal/common/io/IOTools.java
(rev 0)
+++ trunk/common/src/main/org/jboss/portal/common/io/IOTools.java 2007-06-03 19:20:39 UTC
(rev 7374)
@@ -0,0 +1,438 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, 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.portal.common.io;
+
+import org.jboss.portal.common.util.Tools;
+import org.apache.log4j.Logger;
+
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.lang.reflect.InvocationTargetException;
+import java.io.OutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Reader;
+import java.io.ByteArrayOutputStream;
+import java.io.Writer;
+import java.io.Serializable;
+import java.io.ObjectOutputStream;
+import java.io.ByteArrayInputStream;
+import java.io.ObjectInputStream;
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
+
+/**
+ * IO tools.
+ *
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class IOTools
+{
+
+ /** The logger. */
+ public static final Logger log = Logger.getLogger(IOTools.class);
+
+ /** . */
+ private static final Object[] EMPTY_ARGS = new Object[0];
+
+ /** . */
+ private static final Class[] EMPTY_PARAMETER_TYPES = new Class[0];
+
+ /**
+ * <p>Attempt to close an object. Null argument value is authorized and no
operation will be performed in that
+ * use case.</p>
+ *
+ * <p>It will try to obtain a <code>close()</code> method by
reflection and it
+ * will be invoked only if the method is public and not static. If the method is
called, any <code>Error</code>
+ * or <code>RuntimeException</code> will be rethrown, any other kind of
throwable will not be rethrown in any form.</p>
+ *
+ * @param closable the object to close
+ */
+ public static void safeClose(Object closable)
+ {
+ if (closable != null)
+ {
+ try
+ {
+ Method m = closable.getClass().getMethod("close",
EMPTY_PARAMETER_TYPES);
+ if (Modifier.isStatic(m.getModifiers()))
+ {
+ log.warn("close() method on closable object is static");
+ return;
+ }
+ m.invoke(closable, EMPTY_ARGS);
+ }
+ catch (NoSuchMethodException e)
+ {
+ log.warn("The closable object does not have a close() method", e);
+ }
+ catch (IllegalAccessException e)
+ {
+ log.warn("Cannot access close() method on closable object", e);
+ }
+ catch (InvocationTargetException e)
+ {
+ Throwable t = e.getCause();
+
+ //
+ if (t instanceof RuntimeException)
+ {
+ log.error("The close() method threw a runtime exception", t);
+ throw (RuntimeException)t;
+ }
+ else if (t instanceof Error)
+ {
+ log.error("The close() method threw an error", t);
+ throw (Error)t;
+ }
+ else if (t instanceof Exception)
+ {
+ log.error("The close() method threw an exception", t);
+ }
+ else
+ {
+ log.error("The close() method threw an unexpected throwable",
t);
+ }
+ }
+ }
+ }
+
+ /**
+ * <p>Attempt to close an <code>OutputStream</code>. Null argument
value is authorized and no operation will be performed in that
+ * use case.</p>
+ *
+ * @param out the stream to close
+ */
+ public static void safeClose(OutputStream out)
+ {
+ if (out != null)
+ {
+ try
+ {
+ out.close();
+ }
+ catch (IOException e)
+ {
+ log.error("Error while closing outstream", e);
+ }
+ }
+ }
+
+ /**
+ * <p>Attempt to close an <code>InputStream</code>. Null argument
value is authorized and no operation will be performed in that
+ * use case.</p>
+ *
+ * @param in the stream to close
+ */
+ public static void safeClose(InputStream in)
+ {
+ if (in != null)
+ {
+ try
+ {
+ in.close();
+ }
+ catch (IOException e)
+ {
+ log.error("Error while closing inputstream", e);
+ }
+ }
+ }
+
+ /**
+ * <p>Attempt to close an <code>Reader</code>. Null argument value
is authorized and no operation will be performed in that
+ * use case.</p>
+ *
+ * @param reader the stream to close
+ */
+ public static void safeClose(Reader reader)
+ {
+ if (reader != null)
+ {
+ try
+ {
+ reader.close();
+ }
+ catch (IOException e)
+ {
+ log.error("Error while closing reader", e);
+ }
+ }
+ }
+
+ /**
+ * <p>Attempt to close an <code>Writer</code>. Null argument value
is authorized and no operation will be performed in that
+ * use case.</p>
+ *
+ * @param writer the stream to close
+ */
+ public static void safeClose(Writer writer)
+ {
+ if (writer != null)
+ {
+ try
+ {
+ writer.close();
+ }
+ catch (IOException e)
+ {
+ log.error("Error while closing writer", e);
+ }
+ }
+ }
+
+ /**
+ * @see #getBytes(java.io.InputStream, int)
+ * @param in the input stream
+ * @return the bytes read from the stream
+ * @throws java.io.IOException
+ * @throws IllegalArgumentException if the input stream is null
+ */
+ public static byte[] getBytes(InputStream in) throws IOException,
IllegalArgumentException
+ {
+ return getBytes(in, Tools.DEFAULT_BUFFER_SIZE);
+ }
+
+ /**
+ * Get the bytes from the provided input stream. No attempt will be made to close the
stream.
+ *
+ * @param in the input stream
+ * @param bufferSize the buffer size used to copy the bytes
+ * @return the bytes read from the stream
+ * @throws java.io.IOException
+ * @throws IllegalArgumentException if the input stream is null or the buffer size
< 1
+ */
+ public static byte[] getBytes(InputStream in, int bufferSize) throws IOException,
IllegalArgumentException
+ {
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ copy(in, out, bufferSize);
+ return out.toByteArray();
+ }
+
+ /**
+ * @see #copy(java.io.InputStream, java.io.OutputStream, int)
+ * @param in the incoming stream
+ * @param out the outcoming stream
+ * @throws IllegalArgumentException if an argument is null
+ */
+ public static void copy(InputStream in, OutputStream out) throws IOException
+ {
+ copy(in, out, Tools.DEFAULT_BUFFER_SIZE);
+ }
+
+ /**
+ * Pipe an incoming stream in an outcoming stream until no bytes is available from the
input stream.
+ * No attempts will be made to close the streams.
+ *
+ * @param in the incoming stream
+ * @param out the outcoming stream
+ * @param bufferSize the buffer size
+ * @throws IllegalArgumentException if bufferSize < 1 or an argument is null
+ */
+ public static void copy(InputStream in, OutputStream out, int bufferSize) throws
IOException
+ {
+ // arguments check
+ if (in == null)
+ {
+ throw new IllegalArgumentException("null in");
+ }
+ if (out == null)
+ {
+ throw new IllegalArgumentException("null out");
+ }
+ if (bufferSize < 1)
+ {
+ throw new IllegalArgumentException("Buffer size is too small");
+ }
+
+ // do the job
+ byte[] buffer = new byte[bufferSize];
+ while (true)
+ {
+ int i = in.read(buffer);
+ if (i == 0)
+ {
+ continue;
+ }
+ if (i == -1)
+ {
+ break;
+ }
+ out.write(buffer, 0, i);
+ }
+ }
+
+ /**
+ * Pipe an input stream in an output stream.
+ *
+ * @param reader the incoming reader
+ * @param writer the outcoming writer
+ * @throws IllegalArgumentException if an argument is null
+ */
+ public static void copy(Reader reader, Writer writer) throws IOException
+ {
+ copy(reader, writer, Tools.DEFAULT_BUFFER_SIZE);
+ }
+
+ /**
+ * Pipe an incoming stream in an outcoming stream.
+ *
+ * @param reader the incoming reader
+ * @param writer the outcoming writer
+ * @param bufferSize the buffer size
+ * @throws IllegalArgumentException if bufferSize < 1 or an argument is null
+ */
+ public static void copy(Reader reader, Writer writer, int bufferSize) throws
IOException
+ {
+ // arguments check
+ if (reader == null)
+ {
+ throw new IllegalArgumentException("null in");
+ }
+ if (writer == null)
+ {
+ throw new IllegalArgumentException("null out");
+ }
+ if (bufferSize < 1)
+ {
+ throw new IllegalArgumentException("Buffer size is too small");
+ }
+
+ // do the job
+ char[] buffer = new char[bufferSize];
+ while (true)
+ {
+ int i = reader.read(buffer);
+ if (i == 0)
+ {
+ continue;
+ }
+ if (i == -1)
+ {
+ break;
+ }
+ writer.write(buffer, 0, i);
+ }
+ }
+
+ /**
+ * Clone an object implementing the <code>Serializable</code> interface.
+ *
+ * @param serializable
+ * @return
+ * @throws IllegalArgumentException if the serializable object is null
+ * @throws IOException
+ */
+ public static Object clone(Serializable serializable) throws IllegalArgumentException,
IOException
+ {
+ try
+ {
+ return unserialize(serialize(serializable));
+ }
+ catch (ClassNotFoundException e)
+ {
+ throw new Error("Got a class not found exception for a class that was
used", e);
+ }
+ }
+
+ public static byte[] serialize(Serializable serializable) throws
IllegalArgumentException, IOException
+ {
+ if (serializable == null)
+ {
+ throw new IllegalArgumentException("No null serializable accepted");
+ }
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ ObjectOutputStream oos = new ObjectOutputStream(baos);
+ oos.writeObject(serializable);
+ oos.close();
+ return baos.toByteArray();
+ }
+
+ public static Serializable unserialize(byte[] bytes) throws IllegalArgumentException,
IOException, ClassNotFoundException
+ {
+ if (bytes == null)
+ {
+ throw new IllegalArgumentException("No null serializable accepted");
+ }
+ ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
+ ObjectInputStream ois = new ObjectInputStream(bais);
+ return (Serializable)ois.readObject();
+ }
+
+ /**
+ * Check that the provided input stream is buffered. If the argument is already an
instance of <code>BufferedInputStream</code>
+ * no operation will be performed, otherwise a instance of
<code>BufferedInputStream</code> will be created and returned.
+ *
+ * If the provided argument is null, the null value is returned.
+ *
+ * @param in the stream
+ * @return a buffered wrapper
+ */
+ public static BufferedInputStream safeBufferedWrapper(InputStream in)
+ {
+ if (in != null)
+ {
+ if (in instanceof BufferedInputStream)
+ {
+ return (BufferedInputStream)in;
+ }
+ else
+ {
+ return new BufferedInputStream(in);
+ }
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ /**
+ * Check that the provided output stream is buffered. If the argument is already an
instance of <code>BufferedOutputStream</code>
+ * no operation will be performed, otherwise a instance of
<code>BufferedOutputStream</code> will be created and returned.
+ *
+ * If the provided argument is null, the null value is returned.
+ *
+ * @param out the stream
+ * @return a buffered wrapper
+ */
+ public static BufferedOutputStream safeBufferedWrapper(OutputStream out)
+ {
+ if (out != null)
+ {
+ if (out instanceof BufferedOutputStream)
+ {
+ return (BufferedOutputStream)out;
+ }
+ else
+ {
+ return new BufferedOutputStream(out);
+ }
+ }
+ else
+ {
+ return null;
+ }
+ }
+}
Modified: trunk/common/src/main/org/jboss/portal/common/junit/ExtendedAssert.java
===================================================================
--- trunk/common/src/main/org/jboss/portal/common/junit/ExtendedAssert.java 2007-06-03
09:56:50 UTC (rev 7373)
+++ trunk/common/src/main/org/jboss/portal/common/junit/ExtendedAssert.java 2007-06-03
19:20:39 UTC (rev 7374)
@@ -52,13 +52,29 @@
fail(format(message, expected, actual));
}
+ /** @see #assertEquals(char[],char[]) */
+ public static void assertEquals(char[] expected, char[] actual)
+ {
+ assertEquals(null, expected, actual);
+ }
+
+ /** Test equality as defined by java.util.Array#equals(char[], char[]). */
+ public static void assertEquals(String message, char[] expected, char[] actual)
+ {
+ if (Arrays.equals(expected, actual))
+ {
+ return;
+ }
+ fail(format(message, expected, actual));
+ }
+
/** @see #assertEquals(byte[],byte[]) */
public static void assertEquals(byte[] expected, byte[] actual)
{
assertEquals(null, expected, actual);
}
- /** Test equality as defined by java.util.Array#equals(Object[], Object[]). */
+ /** Test equality as defined by java.util.Array#equals(char[], char[]). */
public static void assertEquals(String message, byte[] expected, byte[] actual)
{
if (Arrays.equals(expected, actual))
Modified:
trunk/common/src/main/org/jboss/portal/common/logging/LoaderRepositorySelector.java
===================================================================
---
trunk/common/src/main/org/jboss/portal/common/logging/LoaderRepositorySelector.java 2007-06-03
09:56:50 UTC (rev 7373)
+++
trunk/common/src/main/org/jboss/portal/common/logging/LoaderRepositorySelector.java 2007-06-03
19:20:39 UTC (rev 7374)
@@ -32,6 +32,7 @@
import org.apache.log4j.xml.DOMConfigurator;
import org.jboss.portal.common.util.ResourceLoader;
import org.jboss.portal.common.util.Tools;
+import org.jboss.portal.common.io.IOTools;
import org.w3c.dom.Document;
import javax.xml.parsers.DocumentBuilder;
@@ -106,7 +107,7 @@
}
finally
{
- Tools.safeClose(log4JConfig);
+ IOTools.safeClose(log4JConfig);
}
}
Modified: trunk/common/src/main/org/jboss/portal/common/util/LoaderResource.java
===================================================================
--- trunk/common/src/main/org/jboss/portal/common/util/LoaderResource.java 2007-06-03
09:56:50 UTC (rev 7373)
+++ trunk/common/src/main/org/jboss/portal/common/util/LoaderResource.java 2007-06-03
19:20:39 UTC (rev 7374)
@@ -25,6 +25,7 @@
import org.w3c.dom.Document;
import org.xml.sax.SAXException;
import org.apache.log4j.Logger;
+import org.jboss.portal.common.io.IOTools;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.ParserConfigurationException;
@@ -73,7 +74,7 @@
InputStream in = null;
try
{
- in = Tools.safeBufferedWrapper(asInputStream());
+ in = IOTools.safeBufferedWrapper(asInputStream());
return builder.parse(in);
}
catch (SAXException e)
@@ -90,7 +91,7 @@
}
finally
{
- Tools.safeClose(in);
+ IOTools.safeClose(in);
}
}
@@ -111,7 +112,7 @@
try
{
- in = Tools.safeBufferedWrapper(asInputStream());
+ in = IOTools.safeBufferedWrapper(asInputStream());
Properties props;
if (xml)
{
@@ -141,7 +142,7 @@
}
finally
{
- Tools.safeClose(in);
+ IOTools.safeClose(in);
}
}
@@ -162,9 +163,9 @@
try
{
- in = Tools.safeBufferedWrapper(asInputStream());
+ in = IOTools.safeBufferedWrapper(asInputStream());
ByteArrayOutputStream out = new ByteArrayOutputStream(in.available());
- Tools.copy(in, out);
+ IOTools.copy(in, out);
String result;
if (enc == null)
{
@@ -186,7 +187,7 @@
}
finally
{
- Tools.safeClose(in);
+ IOTools.safeClose(in);
}
}
}
Modified: trunk/common/src/main/org/jboss/portal/common/util/Tools.java
===================================================================
--- trunk/common/src/main/org/jboss/portal/common/util/Tools.java 2007-06-03 09:56:50 UTC
(rev 7373)
+++ trunk/common/src/main/org/jboss/portal/common/util/Tools.java 2007-06-03 19:20:39 UTC
(rev 7374)
@@ -26,24 +26,10 @@
import org.apache.log4j.Logger;
import org.jboss.portal.common.logging.Log4JWriter;
-import java.io.BufferedInputStream;
-import java.io.BufferedOutputStream;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.io.OutputStream;
import java.io.PrintWriter;
-import java.io.Reader;
-import java.io.Serializable;
import java.io.StringWriter;
import java.io.Writer;
import java.lang.reflect.Array;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.lang.reflect.Modifier;
import java.math.BigInteger;
import java.net.URL;
import java.net.URLClassLoader;
@@ -74,243 +60,6 @@
public static final Logger log = Logger.getLogger(Tools.class);
- private static final Object[] EMPTY_ARGS = new Object[0];
-
- private static final Class[] EMPTY_PARAMETER_TYPES = new Class[0];
-
- /**
- * Close an object that implements a close() method.
- *
- * @param closable the object to close
- */
- public static void safeClose(Object closable)
- {
- if (closable != null)
- {
- try
- {
- Method m = closable.getClass().getMethod("close",
Tools.EMPTY_PARAMETER_TYPES);
- if (!Modifier.isPublic(m.getModifiers()))
- {
- log.warn("close() method on closable object is not public");
- return;
- }
- if (Modifier.isStatic(m.getModifiers()))
- {
- log.warn("close() method on closable object is static");
- return;
- }
- m.invoke(closable, EMPTY_ARGS);
- }
- catch (NoSuchMethodException e)
- {
- log.warn("The closable object does not have a close() method", e);
- }
- catch (IllegalAccessException e)
- {
- log.warn("Cannot access close() method on closable object", e);
- }
- catch (InvocationTargetException e)
- {
- log.error("The close() method threw an exception",
e.getTargetException());
- }
- }
- }
-
- /**
- * Close an output stream safely.
- *
- * @param out the stream to close
- */
- public static void safeClose(OutputStream out)
- {
- if (out != null)
- {
- try
- {
- out.close();
- }
- catch (IOException e)
- {
- log.error("Error while closing putstream", e);
- }
- }
- }
-
- /**
- * Close an input stream safely.
- *
- * @param in the stream to close
- */
- public static void safeClose(InputStream in)
- {
- if (in != null)
- {
- try
- {
- in.close();
- }
- catch (IOException e)
- {
- log.error("Error while closing inputstream", e);
- }
- }
- }
-
- /**
- * Close a reader safely.
- *
- * @param reader the stream to close
- */
- public static void safeClose(Reader reader)
- {
- if (reader != null)
- {
- try
- {
- reader.close();
- }
- catch (IOException e)
- {
- log.error("Error while closing inputstream", e);
- }
- }
- }
-
- /**
- * @see #getBytes(java.io.InputStream, int)
- * @param in the input stream
- * @return the bytes read from the stream
- * @throws IOException
- * @throws IllegalArgumentException if the input stream is null
- */
- public static byte[] getBytes(InputStream in) throws IOException,
IllegalArgumentException
- {
- return getBytes(in, DEFAULT_BUFFER_SIZE);
- }
-
- /**
- * Get the bytes from the provided input stream. No attempt will be made to close the
stream.
- *
- * @param in the input stream
- * @param bufferSize the buffer size used to copy the bytes
- * @return the bytes read from the stream
- * @throws IOException
- * @throws IllegalArgumentException if the input stream is null or the buffer size
< 1
- */
- public static byte[] getBytes(InputStream in, int bufferSize) throws IOException,
IllegalArgumentException
- {
- ByteArrayOutputStream out = new ByteArrayOutputStream();
- copy(in, out, bufferSize);
- return out.toByteArray();
- }
-
- /**
- * @see #copy(java.io.InputStream, java.io.OutputStream, int)
- * @param in the incoming stream
- * @param out the outcoming stream
- * @throws IllegalArgumentException if an argument is null
- */
- public static void copy(InputStream in, OutputStream out) throws IOException
- {
- copy(in, out, DEFAULT_BUFFER_SIZE);
- }
-
- /**
- * Pipe an incoming stream in an outcoming stream until no bytes is available from the
input stream.
- * No attempts will be made to close the streams.
- *
- * @param in the incoming stream
- * @param out the outcoming stream
- * @param bufferSize the buffer size
- * @throws IllegalArgumentException if bufferSize < 1 or an argument is null
- */
- public static void copy(InputStream in, OutputStream out, int bufferSize) throws
IOException
- {
- // arguments check
- if (in == null)
- {
- throw new IllegalArgumentException("null in");
- }
- if (out == null)
- {
- throw new IllegalArgumentException("null out");
- }
- if (bufferSize < 1)
- {
- throw new IllegalArgumentException("Buffer size is too small");
- }
-
- // do the job
- byte[] buffer = new byte[bufferSize];
- while (true)
- {
- int i = in.read(buffer);
- if (i == 0)
- {
- continue;
- }
- if (i == -1)
- {
- break;
- }
- out.write(buffer, 0, i);
- }
- }
-
- /**
- * Pipe an input stream in an output stream.
- *
- * @param reader the incoming reader
- * @param writer the outcoming writer
- * @throws IllegalArgumentException if an argument is null
- */
- public static void copy(Reader reader, Writer writer) throws IOException
- {
- copy(reader, writer, DEFAULT_BUFFER_SIZE);
- }
-
- /**
- * Pipe an incoming stream in an outcoming stream.
- *
- * @param reader the incoming reader
- * @param writer the outcoming writer
- * @param bufferSize the buffer size
- * @throws IllegalArgumentException if bufferSize < 1 or an argument is null
- */
- public static void copy(Reader reader, Writer writer, int bufferSize) throws
IOException
- {
- // arguments check
- if (reader == null)
- {
- throw new IllegalArgumentException("null in");
- }
- if (writer == null)
- {
- throw new IllegalArgumentException("null out");
- }
- if (bufferSize < 1)
- {
- throw new IllegalArgumentException("Buffer size is too small");
- }
-
- // do the job
- char[] buffer = new char[bufferSize];
- while (true)
- {
- int i = reader.read(buffer);
- if (i == 0)
- {
- continue;
- }
- if (i == -1)
- {
- break;
- }
- writer.write(buffer, 0, i);
- }
- }
-
/** 16 chars long VMID. */
public static final String VMID = VMID();
@@ -958,73 +707,6 @@
return buffer.toString();
}
- public static Object clone(Serializable serializable) throws IOException,
ClassNotFoundException
- {
- return unserialize(serialize(serializable));
- }
-
- public static byte[] serialize(Serializable serializable) throws
IllegalArgumentException, IOException
- {
- if (serializable == null)
- {
- throw new IllegalArgumentException("No null serializable accepted");
- }
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- ObjectOutputStream oos = new ObjectOutputStream(baos);
- oos.writeObject(serializable);
- oos.close();
- return baos.toByteArray();
- }
-
- public static Serializable unserialize(byte[] bytes) throws IllegalArgumentException,
IOException, ClassNotFoundException
- {
- if (bytes == null)
- {
- throw new IllegalArgumentException("No null serializable accepted");
- }
- ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
- ObjectInputStream ois = new ObjectInputStream(bais);
- return (Serializable)ois.readObject();
- }
-
- public static BufferedInputStream safeBufferedWrapper(InputStream in)
- {
- if (in != null)
- {
- if (in instanceof BufferedInputStream)
- {
- return (BufferedInputStream)in;
- }
- else
- {
- return new BufferedInputStream(in);
- }
- }
- else
- {
- return null;
- }
- }
-
- public static BufferedOutputStream safeBufferedWrapper(OutputStream out)
- {
- if (out != null)
- {
- if (out instanceof BufferedOutputStream)
- {
- return (BufferedOutputStream)out;
- }
- else
- {
- return new BufferedOutputStream(out);
- }
- }
- else
- {
- return null;
- }
- }
-
public static Object[] appendTo(Object[] array, Object o)
{
if (array == null)
Modified: trunk/common/src/main/org/jboss/portal/common/util/URLTools.java
===================================================================
--- trunk/common/src/main/org/jboss/portal/common/util/URLTools.java 2007-06-03 09:56:50
UTC (rev 7373)
+++ trunk/common/src/main/org/jboss/portal/common/util/URLTools.java 2007-06-03 19:20:39
UTC (rev 7374)
@@ -25,6 +25,7 @@
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpMethod;
import org.apache.commons.httpclient.methods.GetMethod;
+import org.jboss.portal.common.io.IOTools;
import java.io.UnsupportedEncodingException;
import java.io.IOException;
@@ -231,7 +232,7 @@
}
finally
{
- Tools.safeClose(thread.getInputStream());
+ IOTools.safeClose(thread.getInputStream());
}
}
Modified: trunk/common/src/main/org/jboss/portal/test/common/BufferedStreamTestCase.java
===================================================================
---
trunk/common/src/main/org/jboss/portal/test/common/BufferedStreamTestCase.java 2007-06-03
09:56:50 UTC (rev 7373)
+++
trunk/common/src/main/org/jboss/portal/test/common/BufferedStreamTestCase.java 2007-06-03
19:20:39 UTC (rev 7374)
@@ -23,7 +23,7 @@
package org.jboss.portal.test.common;
import junit.framework.TestCase;
-import org.jboss.portal.common.util.Tools;
+import org.jboss.portal.common.io.IOTools;
import java.io.InputStream;
import java.io.ByteArrayInputStream;
@@ -47,9 +47,9 @@
public void testInputStream() throws Exception
{
- assertNull(Tools.safeBufferedWrapper((InputStream)null));
- BufferedInputStream in = Tools.safeBufferedWrapper(new
ByteArrayInputStream("abc".getBytes("UTF8")));
- assertEquals(System.identityHashCode(in),
System.identityHashCode(Tools.safeBufferedWrapper(in)));
+ assertNull(IOTools.safeBufferedWrapper((InputStream)null));
+ BufferedInputStream in = IOTools.safeBufferedWrapper(new
ByteArrayInputStream("abc".getBytes("UTF8")));
+ assertEquals(System.identityHashCode(in),
System.identityHashCode(IOTools.safeBufferedWrapper(in)));
assertNotNull(in);
byte[] bytes = "abc".getBytes("UTF8");
Arrays.fill(bytes, (byte)0);
@@ -60,11 +60,11 @@
public void testOutputputStream() throws Exception
{
- assertNull(Tools.safeBufferedWrapper((OutputStream)null));
+ assertNull(IOTools.safeBufferedWrapper((OutputStream)null));
ByteArrayOutputStream out = new ByteArrayOutputStream();
- BufferedOutputStream buffered = Tools.safeBufferedWrapper(out);
+ BufferedOutputStream buffered = IOTools.safeBufferedWrapper(out);
assertNotNull(buffered);
- assertEquals(System.identityHashCode(buffered),
System.identityHashCode(Tools.safeBufferedWrapper(buffered)));
+ assertEquals(System.identityHashCode(buffered),
System.identityHashCode(IOTools.safeBufferedWrapper(buffered)));
buffered.write("abc".getBytes("UTF8"));
buffered.close();
assertEquals("abc", out.toString("UTF8"));
Modified: trunk/common/src/main/org/jboss/portal/test/common/JarTestCase.java
===================================================================
--- trunk/common/src/main/org/jboss/portal/test/common/JarTestCase.java 2007-06-03
09:56:50 UTC (rev 7373)
+++ trunk/common/src/main/org/jboss/portal/test/common/JarTestCase.java 2007-06-03
19:20:39 UTC (rev 7374)
@@ -35,9 +35,9 @@
import java.io.FileInputStream;
import java.io.OutputStream;
-import org.jboss.portal.common.util.Tools;
import org.jboss.portal.common.jar.JarEntryInfo;
import org.jboss.portal.common.jar.JarInfo;
+import org.jboss.portal.common.io.IOTools;
/**
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
@@ -85,7 +85,7 @@
{
File jarFile = File.createTempFile("test", ".jar");
- OutputStream out = Tools.safeBufferedWrapper(new FileOutputStream(jarFile));
+ OutputStream out = IOTools.safeBufferedWrapper(new FileOutputStream(jarFile));
JarOutputStream jarOut = new JarOutputStream(out);
jarOut.putNextEntry(new JarEntry("a/c"));
jarOut.closeEntry();
@@ -101,7 +101,7 @@
jarFile.deleteOnExit();
- JarInputStream jarIn = new JarInputStream(Tools.safeBufferedWrapper(new
FileInputStream(jarFile)));
+ JarInputStream jarIn = new JarInputStream(IOTools.safeBufferedWrapper(new
FileInputStream(jarFile)));
Iterator i = new JarInfo(jarIn).entries();
while (i.hasNext())
{
Added: trunk/common/src/main/org/jboss/portal/test/common/io/IOToolsTestCase.java
===================================================================
--- trunk/common/src/main/org/jboss/portal/test/common/io/IOToolsTestCase.java
(rev 0)
+++ trunk/common/src/main/org/jboss/portal/test/common/io/IOToolsTestCase.java 2007-06-03
19:20:39 UTC (rev 7374)
@@ -0,0 +1,667 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, 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.portal.test.common.io;
+
+import org.jboss.portal.common.io.IOTools;
+import org.jboss.portal.common.junit.ExtendedAssert;
+import junit.framework.TestCase;
+
+import java.io.OutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Reader;
+import java.io.Writer;
+import java.io.ByteArrayOutputStream;
+import java.io.ByteArrayInputStream;
+import java.io.CharArrayWriter;
+import java.io.CharArrayReader;
+import java.util.Random;
+
+import EDU.oswego.cs.dl.util.concurrent.SynchronizedBoolean;
+
+/**
+ * todo:
+ * <ul>
+ * <li>test safeBufferedWrapper</li>
+ * <li>test serialize</li>
+ * <li>test unserialize</li>
+ * <li>test clone</li>
+ * </ul>
+ *
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class IOToolsTestCase extends TestCase
+{
+
+ public void testGenericSafeClose()
+ {
+ IOTools.safeClose((Object)null);
+ IOTools.safeClose(new Object());
+
+ //
+ assertTrue(new GenericPublicSafeClose().apply().called);
+ assertFalse(new GenericProtectedSafeClose().apply().called);
+ assertFalse(new GenericPackageProtectedSafeClose().apply().called);
+ assertFalse(new GenericPrivateSafeClose().apply().called);
+
+ //
+ IOTools.safeClose(new GenericPublicStaticSafeClose());
+ assertFalse(GenericPublicStaticSafeClose.called);
+ IOTools.safeClose(new GenericProtectedStaticSafeClose());
+ assertFalse(GenericProtectedStaticSafeClose.called);
+ IOTools.safeClose(new GenericPackageProtectedStaticSafeClose());
+ assertFalse(GenericPackageProtectedStaticSafeClose.called);
+ IOTools.safeClose(new GenericPrivateStaticSafeClose());
+ assertFalse(GenericPrivateStaticSafeClose.called);
+ }
+
+ public static class GenericSafeClose
+ {
+ boolean called = false;
+ public GenericSafeClose apply()
+ {
+ IOTools.safeClose(this);
+ return this;
+ }
+ }
+
+ public static class GenericPublicSafeClose extends GenericSafeClose
+ {
+ public void close()
+ {
+ called = true;
+ }
+ }
+
+ public static class GenericProtectedSafeClose extends GenericSafeClose
+ {
+ protected void close()
+ {
+ called = true;
+ }
+ }
+
+ public static class GenericPackageProtectedSafeClose extends GenericSafeClose
+ {
+ protected void close()
+ {
+ called = true;
+ }
+ }
+
+ public static class GenericPrivateSafeClose extends GenericSafeClose
+ {
+ private void close()
+ {
+ called = true;
+ }
+ }
+
+ public static class GenericPublicStaticSafeClose
+ {
+ static boolean called = false;
+ public static void close()
+ {
+ called = true;
+ }
+ }
+
+ public static class GenericProtectedStaticSafeClose
+ {
+ static boolean called = false;
+ protected static void close()
+ {
+ called = true;
+ }
+ }
+
+ public static class GenericPackageProtectedStaticSafeClose
+ {
+ static boolean called = false;
+ static void close()
+ {
+ called = true;
+ }
+ }
+
+ public static class GenericPrivateStaticSafeClose
+ {
+ static boolean called = false;
+ private static void close()
+ {
+ called = true;
+ }
+ }
+
+
+ public void testGenericSafeCloseWithThrowable()
+ {
+ new FailingGenericSafeClose()
+ {
+ protected void internalClose() throws Throwable
+ {
+ throw new Exception();
+ }
+ }.apply(null);
+ new FailingGenericSafeClose()
+ {
+ protected void internalClose() throws Throwable
+ {
+ throw new Throwable();
+ }
+ }.apply(null);
+ final RuntimeException runtimeException = new RuntimeException();
+ new FailingGenericSafeClose()
+ {
+ protected void internalClose() throws Throwable
+ {
+ throw runtimeException;
+ }
+ }.apply(runtimeException);
+ final Error error = new Error();
+ new FailingGenericSafeClose()
+ {
+ protected void internalClose() throws Throwable
+ {
+ throw error;
+ }
+ }.apply(error);
+ }
+
+ public abstract static class FailingGenericSafeClose
+ {
+ public void apply(Throwable expectedThrowable)
+ {
+ try
+ {
+ IOTools.safeClose(this);
+ assertNull(expectedThrowable);
+ }
+ catch (Throwable t)
+ {
+ assertEquals(expectedThrowable, t);
+ }
+ }
+
+ public void close() throws Throwable
+ {
+ internalClose();
+ }
+
+ protected abstract void internalClose() throws Throwable;
+ }
+
+ public void testOutputStreamSafeClose()
+ {
+ IOTools.safeClose((OutputStream)null);
+ final SynchronizedBoolean called = new SynchronizedBoolean(false);
+ IOTools.safeClose(new AbstractOutputStream()
+ {
+ public void close() throws IOException
+ {
+ called.set(true);
+ }
+ });
+ assertTrue(called.get());
+ IOTools.safeClose(new AbstractOutputStream()
+ {
+ public void close() throws IOException
+ {
+ throw new IOException();
+ }
+ });
+ final Error error = new Error();
+ try
+ {
+ IOTools.safeClose(new AbstractOutputStream()
+ {
+ public void close() throws IOException
+ {
+ throw error;
+ }
+ });
+ fail("Was expecting an error exception");
+ }
+ catch (Error expected)
+ {
+ assertEquals(error, expected);
+ }
+ final RuntimeException runtimeException = new RuntimeException();
+ try
+ {
+ IOTools.safeClose(new AbstractOutputStream()
+ {
+ public void close() throws IOException
+ {
+ throw runtimeException;
+ }
+ });
+ fail("Was expecting a runtime exception");
+ }
+ catch (RuntimeException expected)
+ {
+ assertEquals(runtimeException, expected);
+ }
+ }
+
+ public abstract static class AbstractOutputStream extends OutputStream
+ {
+ public void write(int b) throws IOException
+ {
+ }
+ }
+
+ public void testInputStreamSafeClose()
+ {
+ IOTools.safeClose((InputStream)null);
+ final SynchronizedBoolean called = new SynchronizedBoolean(false);
+ IOTools.safeClose(new AbstractInputStream()
+ {
+ public void close() throws IOException
+ {
+ called.set(true);
+ }
+ });
+ assertTrue(called.get());
+ IOTools.safeClose(new AbstractInputStream()
+ {
+ public void close() throws IOException
+ {
+ throw new IOException();
+ }
+ });
+ final Error error = new Error();
+ try
+ {
+ IOTools.safeClose(new AbstractInputStream()
+ {
+ public void close() throws IOException
+ {
+ throw error;
+ }
+ });
+ fail("Was expecting an error exception");
+ }
+ catch (Error expected)
+ {
+ assertEquals(error, expected);
+ }
+ final RuntimeException runtimeException = new RuntimeException();
+ try
+ {
+ IOTools.safeClose(new AbstractInputStream()
+ {
+ public void close() throws IOException
+ {
+ throw runtimeException;
+ }
+ });
+ fail("Was expecting a runtime exception");
+ }
+ catch (RuntimeException expected)
+ {
+ assertEquals(runtimeException, expected);
+ }
+ }
+
+ public abstract static class AbstractInputStream extends InputStream
+ {
+ public int read() throws IOException
+ {
+ return 0;
+ }
+ }
+
+ public void testReaderSafeClose()
+ {
+ IOTools.safeClose((Reader)null);
+ final SynchronizedBoolean called = new SynchronizedBoolean(false);
+ IOTools.safeClose(new AbstractReader()
+ {
+ public void close() throws IOException
+ {
+ called.set(true);
+ }
+ });
+ assertTrue(called.get());
+ IOTools.safeClose(new AbstractReader()
+ {
+ public void close() throws IOException
+ {
+ throw new IOException();
+ }
+ });
+ final Error error = new Error();
+ try
+ {
+ IOTools.safeClose(new AbstractReader()
+ {
+ public void close() throws IOException
+ {
+ throw error;
+ }
+ });
+ fail("Was expecting an error exception");
+ }
+ catch (Error expected)
+ {
+ assertEquals(error, expected);
+ }
+ final RuntimeException runtimeException = new RuntimeException();
+ try
+ {
+ IOTools.safeClose(new AbstractReader()
+ {
+ public void close() throws IOException
+ {
+ throw runtimeException;
+ }
+ });
+ fail("Was expecting a runtime exception");
+ }
+ catch (RuntimeException expected)
+ {
+ assertEquals(runtimeException, expected);
+ }
+ }
+
+ public abstract static class AbstractReader extends Reader
+ {
+ public int read(char cbuf[], int off, int len) throws IOException
+ {
+ return 0;
+ }
+ }
+
+ public void testWriterSafeClose()
+ {
+ IOTools.safeClose((Writer)null);
+ final SynchronizedBoolean called = new SynchronizedBoolean(false);
+ IOTools.safeClose(new AbstractWriter()
+ {
+ public void close() throws IOException
+ {
+ called.set(true);
+ }
+ });
+ assertTrue(called.get());
+ IOTools.safeClose(new AbstractWriter()
+ {
+ public void close() throws IOException
+ {
+ throw new IOException();
+ }
+ });
+ final Error error = new Error();
+ try
+ {
+ IOTools.safeClose(new AbstractWriter()
+ {
+ public void close() throws IOException
+ {
+ throw error;
+ }
+ });
+ fail("Was expecting an error exception");
+ }
+ catch (Error expected)
+ {
+ assertEquals(error, expected);
+ }
+ final RuntimeException runtimeException = new RuntimeException();
+ try
+ {
+ IOTools.safeClose(new AbstractWriter()
+ {
+ public void close() throws IOException
+ {
+ throw runtimeException;
+ }
+ });
+ fail("Was expecting a runtime exception");
+ }
+ catch (RuntimeException expected)
+ {
+ assertEquals(runtimeException, expected);
+ }
+ }
+
+ public abstract static class AbstractWriter extends Writer
+ {
+ public void write(char cbuf[], int off, int len) throws IOException
+ {
+ }
+ public void flush() throws IOException
+ {
+ }
+ }
+
+ public void testCopyInputStreamToOutputStream() throws IOException
+ {
+ try
+ {
+ IOTools.copy(null, new ByteArrayOutputStream());
+ fail("Was expecting an IAE");
+ }
+ catch (IllegalArgumentException expected)
+ {
+ }
+
+ //
+ try
+ {
+ IOTools.copy(new ByteArrayInputStream(new byte[0]), null);
+ fail("Was expecting an IOException");
+ }
+ catch (IllegalArgumentException expected)
+ {
+ }
+
+ //
+ final SynchronizedBoolean closeCalled1 = new SynchronizedBoolean(false);
+ final IOException ioException1 = new IOException();
+ try
+ {
+ IOTools.copy(new AbstractInputStream()
+ {
+ public int read() throws IOException
+ {
+ throw ioException1;
+ }
+ public void close() throws IOException
+ {
+ closeCalled1.set(true);
+ }
+ }, new ByteArrayOutputStream());
+ fail("Was expecting an IOException");
+ }
+ catch (IOException expected)
+ {
+ assertEquals(ioException1, expected);
+ assertFalse(closeCalled1.get());
+ }
+
+ //
+ final SynchronizedBoolean closeCalled2 = new SynchronizedBoolean(false);
+ IOTools.copy(new AbstractInputStream()
+ {
+ public int read() throws IOException
+ {
+ return -1;
+ }
+ public void close() throws IOException
+ {
+ closeCalled2.set(true);
+ }
+ }, new ByteArrayOutputStream());
+ assertFalse(closeCalled2.get());
+
+ //
+ final IOException ioException2 = new IOException();
+ final SynchronizedBoolean closeCalled3 = new SynchronizedBoolean(false);
+ try
+ {
+ IOTools.copy(new ByteArrayInputStream(new byte[1]), new AbstractOutputStream()
+ {
+ public void write(int b) throws IOException
+ {
+ throw ioException2;
+ }
+ public void close() throws IOException
+ {
+ closeCalled3.set(true);
+ }
+ });
+ fail("Was expecting an IOException");
+ }
+ catch (IOException expected)
+ {
+ assertEquals(ioException2, expected);
+ }
+
+ //
+ final SynchronizedBoolean closeCalled4 = new SynchronizedBoolean(false);
+ IOTools.copy(new ByteArrayInputStream(new byte[1]), new AbstractOutputStream()
+ {
+ public void close() throws IOException
+ {
+ closeCalled4.set(true);
+ }
+ });
+
+ //
+ Random random = new Random();
+ byte[] bytes = new byte[2000];
+ random.nextBytes(bytes);
+ ByteArrayOutputStream baos = new ByteArrayOutputStream(bytes.length);
+ IOTools.copy(new ByteArrayInputStream((byte[])bytes.clone()), baos);
+ ExtendedAssert.assertEquals(bytes, baos.toByteArray());
+ }
+
+ public void testCopyReaderToWriter() throws IOException
+ {
+ try
+ {
+ IOTools.copy(null, new CharArrayWriter());
+ fail("Was expecting an IAE");
+ }
+ catch (IllegalArgumentException expected)
+ {
+ }
+
+ //
+ try
+ {
+ IOTools.copy(new CharArrayReader(new char[0]), null);
+ fail("Was expecting an IOException");
+ }
+ catch (IllegalArgumentException expected)
+ {
+ }
+
+ //
+ final SynchronizedBoolean closeCalled1 = new SynchronizedBoolean(false);
+ final IOException ioException1 = new IOException();
+ try
+ {
+ IOTools.copy(new AbstractReader()
+ {
+ public int read(char cbuf[], int off, int len) throws IOException
+ {
+ throw ioException1;
+ }
+ public void close() throws IOException
+ {
+ closeCalled1.set(true);
+ }
+ }, new CharArrayWriter());
+ fail("Was expecting an IOException");
+ }
+ catch (IOException expected)
+ {
+ assertEquals(ioException1, expected);
+ assertFalse(closeCalled1.get());
+ }
+
+ //
+ final SynchronizedBoolean closeCalled2 = new SynchronizedBoolean(false);
+ IOTools.copy(new AbstractReader()
+ {
+ public int read(char cbuf[], int off, int len) throws IOException
+ {
+ return -1;
+ }
+ public void close() throws IOException
+ {
+ closeCalled2.set(true);
+ }
+ }, new CharArrayWriter());
+ assertFalse(closeCalled2.get());
+
+ //
+ final IOException ioException2 = new IOException();
+ final SynchronizedBoolean closeCalled3 = new SynchronizedBoolean(false);
+ try
+ {
+ IOTools.copy(new CharArrayReader(new char[1]), new AbstractWriter()
+ {
+ public void write(char cbuf[], int off, int len) throws IOException
+ {
+ throw ioException2;
+ }
+ public void close() throws IOException
+ {
+ closeCalled3.set(true);
+ }
+ });
+ fail("Was expecting an IOException");
+ }
+ catch (IOException expected)
+ {
+ assertEquals(ioException2, expected);
+ }
+
+ //
+ final SynchronizedBoolean closeCalled4 = new SynchronizedBoolean(false);
+ IOTools.copy(new CharArrayReader(new char[1]), new AbstractWriter()
+ {
+ public void close() throws IOException
+ {
+ closeCalled4.set(true);
+ }
+ });
+
+ //
+ Random random = new Random();
+ char[] chars = new char[2000];
+ for (int i = 0; i < chars.length; i++)
+ {
+ chars[i] = (char)random.nextInt();
+
+ }
+ CharArrayWriter caw = new CharArrayWriter(chars.length);
+ IOTools.copy(new CharArrayReader((char[])chars.clone()), caw);
+ ExtendedAssert.assertEquals(chars, caw.toCharArray());
+ }
+}
Modified: trunk/core/src/main/org/jboss/portal/core/controller/handler/HTTPResponse.java
===================================================================
---
trunk/core/src/main/org/jboss/portal/core/controller/handler/HTTPResponse.java 2007-06-03
09:56:50 UTC (rev 7373)
+++
trunk/core/src/main/org/jboss/portal/core/controller/handler/HTTPResponse.java 2007-06-03
19:20:39 UTC (rev 7374)
@@ -23,7 +23,7 @@
package org.jboss.portal.core.controller.handler;
import org.jboss.portal.server.ServerInvocationContext;
-import org.jboss.portal.common.util.Tools;
+import org.jboss.portal.common.io.IOTools;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.ServletOutputStream;
@@ -111,8 +111,8 @@
}
finally
{
- Tools.safeClose(in);
- Tools.safeClose(sout);
+ IOTools.safeClose(in);
+ IOTools.safeClose(sout);
}
}
}
Modified:
trunk/core/src/main/org/jboss/portal/core/deployment/jboss/ObjectDeployment.java
===================================================================
---
trunk/core/src/main/org/jboss/portal/core/deployment/jboss/ObjectDeployment.java 2007-06-03
09:56:50 UTC (rev 7373)
+++
trunk/core/src/main/org/jboss/portal/core/deployment/jboss/ObjectDeployment.java 2007-06-03
19:20:39 UTC (rev 7374)
@@ -24,9 +24,9 @@
import org.jboss.deployment.DeploymentException;
import org.jboss.logging.Logger;
-import org.jboss.portal.common.util.Tools;
import org.jboss.portal.common.util.XML;
import org.jboss.portal.common.xml.NullEntityResolver;
+import org.jboss.portal.common.io.IOTools;
import org.jboss.portal.core.model.portal.metadata.PortalObjectMetaData;
import org.jboss.portal.core.model.portal.metadata.BuildContext;
import org.jboss.portal.core.model.portal.PortalObject;
@@ -109,7 +109,7 @@
{
// Load xml document
log.debug("Loading portal metadata from " + url);
- in = Tools.safeBufferedWrapper(url.openStream());
+ in = IOTools.safeBufferedWrapper(url.openStream());
DocumentBuilder builder = XML.getDocumentBuilderFactory().newDocumentBuilder();
EntityResolver entityResolver = factory.getPortalObjectEntityResolver();
if (entityResolver == null)
@@ -261,7 +261,7 @@
}
finally
{
- Tools.safeClose(in);
+ IOTools.safeClose(in);
}
}
Modified:
trunk/core/src/main/org/jboss/portal/core/deployment/jboss/PortletAppDeployment.java
===================================================================
---
trunk/core/src/main/org/jboss/portal/core/deployment/jboss/PortletAppDeployment.java 2007-06-03
09:56:50 UTC (rev 7373)
+++
trunk/core/src/main/org/jboss/portal/core/deployment/jboss/PortletAppDeployment.java 2007-06-03
19:20:39 UTC (rev 7374)
@@ -26,11 +26,11 @@
import org.jboss.mx.util.MBeanProxyExt;
import org.jboss.portal.common.net.URLNavigator;
import org.jboss.portal.common.net.URLVisitor;
-import org.jboss.portal.common.util.Tools;
import org.jboss.portal.common.util.XML;
import org.jboss.portal.common.value.StringValue;
import org.jboss.portal.common.value.Value;
import org.jboss.portal.common.xml.NullEntityResolver;
+import org.jboss.portal.common.io.IOTools;
import org.jboss.portal.core.model.instance.metadata.InstanceMetaData;
import org.jboss.portal.core.model.instance.metadata.PreferencesMetaData;
import org.jboss.portal.core.metadata.ServiceMetaData;
@@ -173,7 +173,7 @@
InputStream in = null;
try
{
- in = Tools.safeBufferedWrapper(url.openStream());
+ in = IOTools.safeBufferedWrapper(url.openStream());
DocumentBuilder builder =
XML.getDocumentBuilderFactory().newDocumentBuilder();
EntityResolver entityResolver =
factory.getPortalObjectEntityResolver();
if (entityResolver == null)
@@ -222,7 +222,7 @@
}
finally
{
- Tools.safeClose(in);
+ IOTools.safeClose(in);
}
}
}
@@ -259,7 +259,7 @@
InputStream in = null;
try
{
- in =
Tools.safeBufferedWrapper(pwa.getServletContext().getResourceAsStream("/WEB-INF/portlet-instances.xml"));
+ in =
IOTools.safeBufferedWrapper(pwa.getServletContext().getResourceAsStream("/WEB-INF/portlet-instances.xml"));
if (in != null)
{
DocumentBuilder builder =
XML.getDocumentBuilderFactory().newDocumentBuilder();
@@ -313,7 +313,7 @@
}
finally
{
- Tools.safeClose(in);
+ IOTools.safeClose(in);
}
// Create instances when we have
Modified: trunk/core/src/main/org/jboss/portal/test/core/Utils.java
===================================================================
--- trunk/core/src/main/org/jboss/portal/test/core/Utils.java 2007-06-03 09:56:50 UTC (rev
7373)
+++ trunk/core/src/main/org/jboss/portal/test/core/Utils.java 2007-06-03 19:20:39 UTC (rev
7374)
@@ -26,7 +26,7 @@
import org.dbunit.database.IDatabaseConnection;
import org.dbunit.dataset.IDataSet;
import org.dbunit.dataset.xml.FlatXmlDataSet;
-import org.jboss.portal.common.util.Tools;
+import org.jboss.portal.common.io.IOTools;
import java.io.FileInputStream;
import java.sql.Connection;
@@ -44,7 +44,7 @@
public static IDataSet getDataSet(String file) throws Exception
{
- return new FlatXmlDataSet(Tools.safeBufferedWrapper(new FileInputStream(file)));
+ return new FlatXmlDataSet(IOTools.safeBufferedWrapper(new FileInputStream(file)));
}
public static IDatabaseConnection getConnection() throws Exception
Modified: trunk/core-cms/src/main/org/jboss/portal/core/cms/servlet/CMSExportServlet.java
===================================================================
---
trunk/core-cms/src/main/org/jboss/portal/core/cms/servlet/CMSExportServlet.java 2007-06-03
09:56:50 UTC (rev 7373)
+++
trunk/core-cms/src/main/org/jboss/portal/core/cms/servlet/CMSExportServlet.java 2007-06-03
19:20:39 UTC (rev 7374)
@@ -22,7 +22,7 @@
******************************************************************************/
package org.jboss.portal.core.cms.servlet;
-import org.jboss.portal.common.util.Tools;
+import org.jboss.portal.common.io.IOTools;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
@@ -55,7 +55,7 @@
response.setContentLength((int)file.length());
response.setHeader("Content-Disposition", "attachment;
filename=" + file.getName());
- InputStream in = Tools.safeBufferedWrapper(new FileInputStream(file));
+ InputStream in = IOTools.safeBufferedWrapper(new FileInputStream(file));
ServletOutputStream sout = response.getOutputStream();
byte[] buf = new byte[2048];
int len;
Modified: trunk/format/src/main/org/jboss/portal/format/template/TemplateLoader.java
===================================================================
--- trunk/format/src/main/org/jboss/portal/format/template/TemplateLoader.java 2007-06-03
09:56:50 UTC (rev 7373)
+++ trunk/format/src/main/org/jboss/portal/format/template/TemplateLoader.java 2007-06-03
19:20:39 UTC (rev 7374)
@@ -23,7 +23,7 @@
package org.jboss.portal.format.template;
import org.dom4j.Document;
-import org.jboss.portal.common.util.Tools;
+import org.jboss.portal.common.io.IOTools;
import org.jboss.portal.format.util.CLLoader;
import org.jboss.portal.format.util.Loader;
@@ -162,7 +162,7 @@
}
finally
{
- Tools.safeClose(tin);
+ IOTools.safeClose(tin);
}
}
Modified: trunk/jems/src/main/org/jboss/portal/jems/hibernate/ByteArrayBlob.java
===================================================================
--- trunk/jems/src/main/org/jboss/portal/jems/hibernate/ByteArrayBlob.java 2007-06-03
09:56:50 UTC (rev 7373)
+++ trunk/jems/src/main/org/jboss/portal/jems/hibernate/ByteArrayBlob.java 2007-06-03
19:20:39 UTC (rev 7374)
@@ -22,7 +22,7 @@
******************************************************************************/
package org.jboss.portal.jems.hibernate;
-import org.jboss.portal.common.util.Tools;
+import org.jboss.portal.common.io.IOTools;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@@ -45,7 +45,7 @@
public ByteArrayBlob(InputStream in) throws IOException
{
ByteArrayOutputStream out = new ByteArrayOutputStream();
- Tools.copy(in, out);
+ IOTools.copy(in, out);
_bytes = out.toByteArray();
}
Modified: trunk/jems/src/main/org/jboss/portal/jems/hibernate/SessionFactoryBinder.java
===================================================================
---
trunk/jems/src/main/org/jboss/portal/jems/hibernate/SessionFactoryBinder.java 2007-06-03
09:56:50 UTC (rev 7373)
+++
trunk/jems/src/main/org/jboss/portal/jems/hibernate/SessionFactoryBinder.java 2007-06-03
19:20:39 UTC (rev 7374)
@@ -35,8 +35,8 @@
import org.hibernate.tool.hbm2ddl.SchemaUpdate;
import org.jboss.portal.common.util.CLResourceLoader;
import org.jboss.portal.common.util.LoaderResource;
-import org.jboss.portal.common.util.Tools;
import org.jboss.portal.common.util.URLTools;
+import org.jboss.portal.common.io.IOTools;
import org.jboss.portal.jems.as.system.AbstractJBossService;
import javax.naming.InitialContext;
@@ -236,7 +236,7 @@
}
finally
{
- Tools.safeClose(conn);
+ IOTools.safeClose(conn);
}
}
log.debug("Using dialect " + dialectName);
@@ -304,7 +304,7 @@
}
finally
{
- Tools.safeClose(session);
+ IOTools.safeClose(session);
}
// There was no sql grammar exception - schema is ok!
if (bad == 0)
Modified:
trunk/portlet/src/main/org/jboss/portal/test/portlet/jsr168/ext/portletrequests/PortletRequestsSequenceBuilder.java
===================================================================
---
trunk/portlet/src/main/org/jboss/portal/test/portlet/jsr168/ext/portletrequests/PortletRequestsSequenceBuilder.java 2007-06-03
09:56:50 UTC (rev 7373)
+++
trunk/portlet/src/main/org/jboss/portal/test/portlet/jsr168/ext/portletrequests/PortletRequestsSequenceBuilder.java 2007-06-03
19:20:39 UTC (rev 7374)
@@ -27,6 +27,7 @@
import org.jboss.portal.test.framework.driver.http.response.InvokeGetResponse;
import org.jboss.portal.common.test.driver.DriverResponse;
import org.jboss.portal.common.http.HttpRequest;
+import org.jboss.portal.common.io.IOTools;
import org.jboss.portal.test.framework.driver.http.response.InvokePostResponse;
import org.jboss.portal.test.framework.portlet.PortletTest;
import org.jboss.portal.test.framework.portlet.PortletTestDriver;
@@ -174,7 +175,7 @@
{
in = request.getPortletInputStream();
ByteArrayOutputStream out = new ByteArrayOutputStream();
- Tools.copy(in, out);
+ IOTools.copy(in, out);
out.close();
byte[] bytes = out.toByteArray();
assertEquals(-1, in.read());
@@ -190,7 +191,7 @@
}
finally
{
- Tools.safeClose(in);
+ IOTools.safeClose(in);
}
try
{
@@ -250,7 +251,7 @@
{
in = request.getReader();
StringWriter out = new StringWriter();
- Tools.copy(in, out);
+ IOTools.copy(in, out);
out.close();
byte[] bytes = out.toString().getBytes("UTF-8");
assertEquals(-1, in.read());
@@ -266,7 +267,7 @@
}
finally
{
- Tools.safeClose(in);
+ IOTools.safeClose(in);
}
try
{
Modified:
trunk/portlet/src/main/org/jboss/portal/test/portlet/session/TestClassLoader.java
===================================================================
---
trunk/portlet/src/main/org/jboss/portal/test/portlet/session/TestClassLoader.java 2007-06-03
09:56:50 UTC (rev 7373)
+++
trunk/portlet/src/main/org/jboss/portal/test/portlet/session/TestClassLoader.java 2007-06-03
19:20:39 UTC (rev 7374)
@@ -22,7 +22,7 @@
******************************************************************************/
package org.jboss.portal.test.portlet.session;
-import org.jboss.portal.common.util.Tools;
+import org.jboss.portal.common.io.IOTools;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
@@ -51,7 +51,7 @@
{
in =
ReplicatedValue.class.getClassLoader().getResourceAsStream(ReplicatedValue.class.getName().replace('.',
'/') + ".class");
ByteArrayOutputStream baos = new ByteArrayOutputStream();
- Tools.copy(in, baos);
+ IOTools.copy(in, baos);
byte[] bytes = baos.toByteArray();
replicatedValueClass = defineClass(ReplicatedValue.class.getName(),
bytes, 0, bytes.length);
}
@@ -61,7 +61,7 @@
}
finally
{
- Tools.safeClose(in);
+ IOTools.safeClose(in);
}
}
return replicatedValueClass;
Modified:
trunk/portlet-server/src/main/org/jboss/portal/portlet/deployment/jboss/PortletAppDeployment.java
===================================================================
---
trunk/portlet-server/src/main/org/jboss/portal/portlet/deployment/jboss/PortletAppDeployment.java 2007-06-03
09:56:50 UTC (rev 7373)
+++
trunk/portlet-server/src/main/org/jboss/portal/portlet/deployment/jboss/PortletAppDeployment.java 2007-06-03
19:20:39 UTC (rev 7374)
@@ -23,8 +23,8 @@
package org.jboss.portal.portlet.deployment.jboss;
import org.jboss.deployment.DeploymentException;
-import org.jboss.portal.common.util.Tools;
import org.jboss.portal.common.xml.NullEntityResolver;
+import org.jboss.portal.common.io.IOTools;
import org.jboss.portal.portlet.deployment.JBossApplicationMetaDataFactory;
import org.jboss.portal.portlet.deployment.PortletApplicationMetaDataFactory;
import org.jboss.portal.portlet.deployment.ValueTrimmingFilter;
@@ -245,7 +245,7 @@
InputStream sourceTLD = null;
try
{
- sourceTLD =
Tools.safeBufferedWrapper(Thread.currentThread().getContextClassLoader().getResourceAsStream("org/jboss/portal/portlet/portlet.tld"));
+ sourceTLD =
IOTools.safeBufferedWrapper(Thread.currentThread().getContextClassLoader().getResourceAsStream("org/jboss/portal/portlet/portlet.tld"));
pwa.importFile("/WEB-INF", "portlet.tld", sourceTLD,
false);
}
catch (IOException e)
@@ -254,7 +254,7 @@
}
finally
{
- Tools.safeClose(sourceTLD);
+ IOTools.safeClose(sourceTLD);
}
}
@@ -263,7 +263,7 @@
InputStream in = null;
try
{
- in = Tools.safeBufferedWrapper(url.openStream());
+ in = IOTools.safeBufferedWrapper(url.openStream());
PortletApplicationMetaDataFactory factory = new
PortletApplicationMetaDataFactory();
Unmarshaller unmarshaller =
UnmarshallerFactory.newInstance().newUnmarshaller();
PortletApplicationMetaData portletAppMD =
(PortletApplicationMetaData)unmarshaller.unmarshal(in, new ValueTrimmingFilter(factory),
null);
@@ -272,7 +272,7 @@
}
finally
{
- Tools.safeClose(in);
+ IOTools.safeClose(in);
}
}
@@ -284,7 +284,7 @@
InputStream in = null;
try
{
- in =
Tools.safeBufferedWrapper(servletContext.getResourceAsStream("/WEB-INF/jboss-portlet.xml"));
+ in =
IOTools.safeBufferedWrapper(servletContext.getResourceAsStream("/WEB-INF/jboss-portlet.xml"));
if (in != null)
{
log.info("Parsing " + contextPath +
"jboss-portlet.xml");
@@ -312,7 +312,7 @@
}
finally
{
- Tools.safeClose(in);
+ IOTools.safeClose(in);
}
return jbossAppMD;
}
Modified:
trunk/portlet-server/src/main/org/jboss/portal/portlet/deployment/jboss/PortletAppDeploymentFactory.java
===================================================================
---
trunk/portlet-server/src/main/org/jboss/portal/portlet/deployment/jboss/PortletAppDeploymentFactory.java 2007-06-03
09:56:50 UTC (rev 7373)
+++
trunk/portlet-server/src/main/org/jboss/portal/portlet/deployment/jboss/PortletAppDeploymentFactory.java 2007-06-03
19:20:39 UTC (rev 7374)
@@ -23,7 +23,7 @@
package org.jboss.portal.portlet.deployment.jboss;
import org.jboss.deployment.DeploymentException;
-import org.jboss.portal.common.util.Tools;
+import org.jboss.portal.common.io.IOTools;
import org.jboss.portal.portlet.container.PortletApplicationRegistry;
import org.jboss.portal.portlet.deployment.JBossApplicationMetaDataFactory;
import org.jboss.portal.portlet.deployment.ValueTrimmingFilter;
@@ -226,7 +226,7 @@
InputStream in = null;
try
{
- in =
Tools.safeBufferedWrapper(Thread.currentThread().getContextClassLoader().getResourceAsStream(standardJBossApplicationMetaDataLocation));
+ in =
IOTools.safeBufferedWrapper(Thread.currentThread().getContextClassLoader().getResourceAsStream(standardJBossApplicationMetaDataLocation));
if (in != null)
{
JBossApplicationMetaDataFactory factory =
createJBossApplicationMetaDataFactory();
@@ -240,7 +240,7 @@
}
finally
{
- Tools.safeClose(in);
+ IOTools.safeClose(in);
}
}
}
Modified: trunk/server/src/main/org/jboss/portal/server/deployment/PortalWebApp.java
===================================================================
--- trunk/server/src/main/org/jboss/portal/server/deployment/PortalWebApp.java 2007-06-03
09:56:50 UTC (rev 7373)
+++ trunk/server/src/main/org/jboss/portal/server/deployment/PortalWebApp.java 2007-06-03
19:20:39 UTC (rev 7374)
@@ -23,9 +23,9 @@
package org.jboss.portal.server.deployment;
import org.apache.log4j.Logger;
-import org.jboss.portal.common.util.Tools;
import org.jboss.portal.common.util.XML;
import org.jboss.portal.common.xml.NullEntityResolver;
+import org.jboss.portal.common.io.IOTools;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.xml.sax.SAXException;
@@ -160,14 +160,14 @@
OutputStream target = null;
try
{
- target = Tools.safeBufferedWrapper(new FileOutputStream(new File(parentDir,
name)));
- Tools.copy(source, target);
+ target = IOTools.safeBufferedWrapper(new FileOutputStream(new File(parentDir,
name)));
+ IOTools.copy(source, target);
done = true;
log.debug("Copied file" + name + " to location " +
parentDirRelativePath);
}
finally
{
- Tools.safeClose(target);
+ IOTools.safeClose(target);
}
}
return done;
@@ -213,7 +213,7 @@
InputStream in = null;
try
{
- in =
Tools.safeBufferedWrapper(getServletContext().getResourceAsStream("/WEB-INF/jboss-app.xml"));
+ in =
IOTools.safeBufferedWrapper(getServletContext().getResourceAsStream("/WEB-INF/jboss-app.xml"));
if (in != null)
{
DocumentBuilder builder =
XML.getDocumentBuilderFactory().newDocumentBuilder();
@@ -244,7 +244,7 @@
}
finally
{
- Tools.safeClose(in);
+ IOTools.safeClose(in);
}
}
Modified: trunk/test/src/main/org/jboss/portal/test/framework/embedded/DSConfig.java
===================================================================
--- trunk/test/src/main/org/jboss/portal/test/framework/embedded/DSConfig.java 2007-06-03
09:56:50 UTC (rev 7373)
+++ trunk/test/src/main/org/jboss/portal/test/framework/embedded/DSConfig.java 2007-06-03
19:20:39 UTC (rev 7374)
@@ -23,9 +23,9 @@
package org.jboss.portal.test.framework.embedded;
-import org.jboss.portal.common.util.Tools;
import org.jboss.portal.common.util.XML;
import org.jboss.portal.common.test.MultiValuedTestParameterValue;
+import org.jboss.portal.common.io.IOTools;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
@@ -125,7 +125,7 @@
InputStream in = null;
try
{
- in = Tools.safeBufferedWrapper(url.openStream());
+ in = IOTools.safeBufferedWrapper(url.openStream());
Document doc = XML.getDocumentBuilderFactory().newDocumentBuilder().parse(in);
for (Iterator i = XML.getChildrenIterator(doc.getDocumentElement(),
"directory"); i.hasNext();)
{
@@ -177,7 +177,7 @@
}
finally
{
- Tools.safeClose(in);
+ IOTools.safeClose(in);
}
}
Modified:
trunk/test/src/main/org/jboss/portal/test/framework/embedded/DataSourceSupport.java
===================================================================
---
trunk/test/src/main/org/jboss/portal/test/framework/embedded/DataSourceSupport.java 2007-06-03
09:56:50 UTC (rev 7373)
+++
trunk/test/src/main/org/jboss/portal/test/framework/embedded/DataSourceSupport.java 2007-06-03
19:20:39 UTC (rev 7374)
@@ -23,9 +23,9 @@
package org.jboss.portal.test.framework.embedded;
-import org.jboss.portal.common.util.Tools;
import org.jboss.portal.common.util.XML;
import org.jboss.portal.common.test.MultiValuedTestParameterValue;
+import org.jboss.portal.common.io.IOTools;
import org.jboss.resource.adapter.jdbc.local.LocalTxDataSource;
import org.jboss.resource.connectionmanager.CachedConnectionManagerReference;
import org.w3c.dom.Document;
@@ -118,8 +118,8 @@
}
finally
{
- Tools.safeClose(st);
- Tools.safeClose(conn);
+ IOTools.safeClose(st);
+ IOTools.safeClose(conn);
}
}
catch (Exception e)
@@ -267,7 +267,7 @@
InputStream in = null;
try
{
- in = Tools.safeBufferedWrapper(url.openStream());
+ in = IOTools.safeBufferedWrapper(url.openStream());
Document doc =
XML.getDocumentBuilderFactory().newDocumentBuilder().parse(in);
for (Iterator i = XML.getChildrenIterator(doc.getDocumentElement(),
"datasource"); i.hasNext();)
{
@@ -303,7 +303,7 @@
}
finally
{
- Tools.safeClose(in);
+ IOTools.safeClose(in);
}
}
}
Modified:
trunk/test/src/main/org/jboss/portal/test/framework/embedded/HibernateSupport.java
===================================================================
---
trunk/test/src/main/org/jboss/portal/test/framework/embedded/HibernateSupport.java 2007-06-03
09:56:50 UTC (rev 7373)
+++
trunk/test/src/main/org/jboss/portal/test/framework/embedded/HibernateSupport.java 2007-06-03
19:20:39 UTC (rev 7374)
@@ -32,7 +32,7 @@
import org.hibernate.cfg.Settings;
import org.hibernate.tool.hbm2ddl.SchemaExport;
import org.jboss.portal.common.util.XML;
-import org.jboss.portal.common.util.Tools;
+import org.jboss.portal.common.io.IOTools;
import org.w3c.dom.Element;
import org.w3c.dom.Document;
@@ -350,7 +350,7 @@
InputStream in = null;
try
{
- in = Tools.safeBufferedWrapper(url.openStream());
+ in = IOTools.safeBufferedWrapper(url.openStream());
Document doc = XML.getDocumentBuilderFactory().newDocumentBuilder().parse(in);
for (Iterator i = XML.getChildrenIterator(doc.getDocumentElement(),
"configuration"); i.hasNext();)
{
@@ -384,7 +384,7 @@
}
finally
{
- Tools.safeClose(in);
+ IOTools.safeClose(in);
}
}
Modified:
trunk/theme/src/main/org/jboss/portal/theme/deployment/jboss/LayoutDeployment.java
===================================================================
---
trunk/theme/src/main/org/jboss/portal/theme/deployment/jboss/LayoutDeployment.java 2007-06-03
09:56:50 UTC (rev 7373)
+++
trunk/theme/src/main/org/jboss/portal/theme/deployment/jboss/LayoutDeployment.java 2007-06-03
19:20:39 UTC (rev 7374)
@@ -24,7 +24,7 @@
import org.jboss.logging.Logger;
import org.jboss.deployment.DeploymentException;
-import org.jboss.portal.common.util.Tools;
+import org.jboss.portal.common.io.IOTools;
import org.jboss.portal.server.deployment.PortalWebApp;
import org.jboss.portal.server.deployment.jboss.Deployment;
import org.jboss.portal.theme.LayoutException;
@@ -76,7 +76,7 @@
InputStream in = null;
try
{
- in = Tools.safeBufferedWrapper(url.openStream());
+ in = IOTools.safeBufferedWrapper(url.openStream());
LayoutService layoutService = factory.getLayoutService();
RuntimeContext ctx = new RuntimeContext(pwa.getId(), pwa.getServletContext(),
pwa.getContextPath(), pwa.getClassLoader());
Unmarshaller unmarshaller =
UnmarshallerFactory.newInstance().newUnmarshaller();
@@ -94,7 +94,7 @@
}
finally
{
- Tools.safeClose(in);
+ IOTools.safeClose(in);
}
// Make sure that the portal-layout.tld is available in the local context
@@ -104,7 +104,7 @@
InputStream source = null;
try
{
- source =
Tools.safeBufferedWrapper(Thread.currentThread().getContextClassLoader().getResourceAsStream("conf/theme/portal-layout.tld"));
+ source =
IOTools.safeBufferedWrapper(Thread.currentThread().getContextClassLoader().getResourceAsStream("conf/theme/portal-layout.tld"));
pwa.importFile("/WEB-INF/theme", "portal-layout.tld",
source, false);
}
catch (IOException e)
@@ -113,7 +113,7 @@
}
finally
{
- Tools.safeClose(source);
+ IOTools.safeClose(source);
}
}
else
Modified:
trunk/theme/src/main/org/jboss/portal/theme/deployment/jboss/LayoutFeaturesDeployment.java
===================================================================
---
trunk/theme/src/main/org/jboss/portal/theme/deployment/jboss/LayoutFeaturesDeployment.java 2007-06-03
09:56:50 UTC (rev 7373)
+++
trunk/theme/src/main/org/jboss/portal/theme/deployment/jboss/LayoutFeaturesDeployment.java 2007-06-03
19:20:39 UTC (rev 7374)
@@ -24,7 +24,7 @@
import org.jboss.deployment.DeploymentException;
import org.jboss.logging.Logger;
-import org.jboss.portal.common.util.Tools;
+import org.jboss.portal.common.io.IOTools;
import org.jboss.portal.server.deployment.PortalWebApp;
import org.jboss.portal.server.deployment.jboss.Deployment;
import org.jboss.portal.theme.LayoutException;
@@ -96,7 +96,7 @@
InputStream stream = null;
try
{
- stream = Tools.safeBufferedWrapper(url.openStream());
+ stream = IOTools.safeBufferedWrapper(url.openStream());
if (isRenderSet)
{
List renderSets =
(List)UnmarshallerFactory.newInstance().newUnmarshaller().unmarshal(stream, new
RenderSetMetaDataFactory(), null);
@@ -109,7 +109,7 @@
}
finally
{
- Tools.safeClose(stream);
+ IOTools.safeClose(stream);
}
}
else
Modified:
trunk/theme/src/main/org/jboss/portal/theme/deployment/jboss/ThemeDeployment.java
===================================================================
---
trunk/theme/src/main/org/jboss/portal/theme/deployment/jboss/ThemeDeployment.java 2007-06-03
09:56:50 UTC (rev 7373)
+++
trunk/theme/src/main/org/jboss/portal/theme/deployment/jboss/ThemeDeployment.java 2007-06-03
19:20:39 UTC (rev 7374)
@@ -24,7 +24,7 @@
import org.jboss.logging.Logger;
import org.jboss.deployment.DeploymentException;
-import org.jboss.portal.common.util.Tools;
+import org.jboss.portal.common.io.IOTools;
import org.jboss.portal.server.deployment.PortalWebApp;
import org.jboss.portal.server.deployment.jboss.Deployment;
import org.jboss.portal.theme.RuntimeContext;
@@ -72,7 +72,7 @@
InputStream themeStream = null;
try
{
- themeStream = Tools.safeBufferedWrapper(url.openStream());
+ themeStream = IOTools.safeBufferedWrapper(url.openStream());
RuntimeContext ctx = new RuntimeContext(pwa.getId(), pwa.getServletContext(),
pwa.getContextPath(), pwa.getClassLoader());
List portalThemes =
(List)UnmarshallerFactory.newInstance().newUnmarshaller().unmarshal(themeStream, new
PortalThemeMetaDataFactory(), null);
@@ -88,7 +88,7 @@
}
finally
{
- Tools.safeClose(themeStream);
+ IOTools.safeClose(themeStream);
}
}
Modified:
trunk/widget/src/main/org/jboss/portal/test/widget/google/PreferencesTestCase.java
===================================================================
---
trunk/widget/src/main/org/jboss/portal/test/widget/google/PreferencesTestCase.java 2007-06-03
09:56:50 UTC (rev 7373)
+++
trunk/widget/src/main/org/jboss/portal/test/widget/google/PreferencesTestCase.java 2007-06-03
19:20:39 UTC (rev 7374)
@@ -29,7 +29,7 @@
import org.jboss.portal.widget.google.GGPreferenceInfo;
import org.jboss.portal.widget.google.type.DataType;
import org.jboss.portal.widget.google.type.EnumType;
-import org.jboss.portal.common.util.Tools;
+import org.jboss.portal.common.io.IOTools;
import java.net.URL;
import java.io.File;
@@ -146,7 +146,7 @@
{
File file = new File(url.getPath());
InputStream io = new FileInputStream(file);
- byte[] bytes = Tools.getBytes(io);
+ byte[] bytes = IOTools.getBytes(io);
io.close();
return bytes;
}
Modified: trunk/workflow/src/main/org/jboss/portal/workflow/cms/ApprovePublishImpl.java
===================================================================
---
trunk/workflow/src/main/org/jboss/portal/workflow/cms/ApprovePublishImpl.java 2007-06-03
09:56:50 UTC (rev 7373)
+++
trunk/workflow/src/main/org/jboss/portal/workflow/cms/ApprovePublishImpl.java 2007-06-03
19:20:39 UTC (rev 7374)
@@ -37,6 +37,7 @@
import org.jboss.portal.jems.as.JNDI;
import org.jboss.portal.common.util.Tools;
+import org.jboss.portal.common.io.IOTools;
import org.jbpm.JbpmContext;
import org.jbpm.db.GraphSession;
@@ -155,7 +156,7 @@
}
finally
{
- Tools.safeClose(is);
+ IOTools.safeClose(is);
Tools.safeClose(jbpmContext);
}
Modified:
trunk/wsrp/src/main/org/jboss/portal/wsrp/services/AbstractJNDIServiceFactory.java
===================================================================
---
trunk/wsrp/src/main/org/jboss/portal/wsrp/services/AbstractJNDIServiceFactory.java 2007-06-03
09:56:50 UTC (rev 7373)
+++
trunk/wsrp/src/main/org/jboss/portal/wsrp/services/AbstractJNDIServiceFactory.java 2007-06-03
19:20:39 UTC (rev 7374)
@@ -23,7 +23,7 @@
package org.jboss.portal.wsrp.services;
import org.jboss.logging.Logger;
-import org.jboss.portal.common.util.Tools;
+import org.jboss.portal.common.io.IOTools;
import org.jboss.portal.jems.as.system.AbstractJBossService;
import javax.naming.InitialContext;
@@ -150,7 +150,7 @@
}
finally
{
- Tools.safeClose(ctx);
+ IOTools.safeClose(ctx);
}
}
Modified:
trunk/wsrp/src/main/org/jboss/portal/wsrp/services/RemoteSOAPInvokerServiceFactory.java
===================================================================
---
trunk/wsrp/src/main/org/jboss/portal/wsrp/services/RemoteSOAPInvokerServiceFactory.java 2007-06-03
09:56:50 UTC (rev 7373)
+++
trunk/wsrp/src/main/org/jboss/portal/wsrp/services/RemoteSOAPInvokerServiceFactory.java 2007-06-03
19:20:39 UTC (rev 7374)
@@ -25,8 +25,8 @@
import org.jboss.logging.Logger;
import org.jboss.portal.common.util.ParameterValidation;
-import org.jboss.portal.common.util.Tools;
import org.jboss.portal.common.util.URLStreamOpeningThread;
+import org.jboss.portal.common.io.IOTools;
import org.xml.sax.InputSource;
import javax.wsdl.Definition;
@@ -224,7 +224,7 @@
{
// Timeout occurred; thread has not finished
// todo: do we need more clean up here?
- Tools.safeClose(thread.getInputStream());
+ IOTools.safeClose(thread.getInputStream());
throw new RuntimeException("Couldn't connect to " + wsdlURL
+ " within " + delayMillis / 1000
+ " seconds. Check your connection parameters or the URL.");
}
@@ -233,7 +233,7 @@
// Finished
if (thread.isConnected() && !thread.isError())
{
- InputStream is = Tools.safeBufferedWrapper(thread.getInputStream());
+ InputStream is = IOTools.safeBufferedWrapper(thread.getInputStream());
return new InputSource(is);
}
else
@@ -310,7 +310,7 @@
try
{
log.info("Resolved to: " + wsdlImport);
- InputStream is = Tools.safeBufferedWrapper(new
URL(wsdlImport).openStream());
+ InputStream is = IOTools.safeBufferedWrapper(new
URL(wsdlImport).openStream());
if (is == null)
{
throw new IllegalArgumentException("Cannot import wsdl from [" +
wsdlImport + "]");
Modified: trunk/wsrp/src/main/org/jboss/portal/wsrp/servlet/RequestDumperFilter.java
===================================================================
--- trunk/wsrp/src/main/org/jboss/portal/wsrp/servlet/RequestDumperFilter.java 2007-06-03
09:56:50 UTC (rev 7373)
+++ trunk/wsrp/src/main/org/jboss/portal/wsrp/servlet/RequestDumperFilter.java 2007-06-03
19:20:39 UTC (rev 7374)
@@ -23,7 +23,7 @@
package org.jboss.portal.wsrp.servlet;
import org.jboss.logging.Logger;
-import org.jboss.portal.common.util.Tools;
+import org.jboss.portal.common.io.IOTools;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
@@ -94,7 +94,7 @@
if (reader != null)
{
StringWriter buffer = new StringWriter();
- Tools.copy(reader, buffer);
+ IOTools.copy(reader, buffer);
tmp.append("body=").append(buffer.toString());
}