Author: chris.laprun(a)jboss.com
Date: 2007-10-31 19:53:29 -0400 (Wed, 31 Oct 2007)
New Revision: 8809
Modified:
modules/common/trunk/common/src/main/java/org/jboss/portal/common/net/URLTools.java
Log:
- Added getInputStreamFor and internalGetInputStreamFor methods and retro-fitted
performGET to use internalGetInputStreamFor (needed to get an input stream for WSRP WSDL
handling).
- Versioning for @since tags?
Modified:
modules/common/trunk/common/src/main/java/org/jboss/portal/common/net/URLTools.java
===================================================================
---
modules/common/trunk/common/src/main/java/org/jboss/portal/common/net/URLTools.java 2007-10-31
22:52:11 UTC (rev 8808)
+++
modules/common/trunk/common/src/main/java/org/jboss/portal/common/net/URLTools.java 2007-10-31
23:53:29 UTC (rev 8809)
@@ -73,10 +73,70 @@
* @param soTimeoutMillis the socket connection timeout in millis
* @param connTimeoutMillis the connection timeout in millis
* @return the retrieved byte array
- * @throws IllegalArgumentException if the URL is null or any time out value is
negative
+ * @throws IllegalArgumentException if the URL is null or any time out value is
negative
*/
public static byte[] performGET(URL url, int soTimeoutMillis, int connTimeoutMillis)
throws IllegalArgumentException
{
+ InputStream in = null;
+ try
+ {
+ in = internalGetInputStreamFor(url, soTimeoutMillis, connTimeoutMillis);
+ return IOTools.getBytes(in);
+ }
+ catch (IOException e)
+ {
+ return null;
+ }
+ finally
+ {
+ IOTools.safeClose(in);
+ }
+ }
+
+ /**
+ * Fetches content from URL as an InputStream. The timeout values must not be negative
integers, when it is equals to
+ * zero it means that it does not setup a timeout and use the default values.
+ *
+ * @param url the URL the URL of the resource
+ * @param soTimeoutMillis the socket connection timeout in millis
+ * @param connTimeoutMillis the connection timeout in millis
+ * @return the buffered content for the URL
+ * @throws IllegalArgumentException if the URL is null or any time out value is
negative
+ * @since 1.1
+ */
+ public static InputStream getInputStreamFor(URL url, int soTimeoutMillis, int
connTimeoutMillis)
+ {
+ //
+ InputStream in = null;
+ try
+ {
+ in = internalGetInputStreamFor(url, soTimeoutMillis, connTimeoutMillis);
+ return in;
+ }
+ catch (SocketTimeoutException e)
+ {
+ return null;
+ }
+ catch (IOException e)
+ {
+ return null;
+ }
+ finally
+ {
+ IOTools.safeClose(in);
+ }
+ }
+
+ /**
+ * @param url
+ * @param soTimeoutMillis
+ * @param connTimeoutMillis
+ * @return
+ * @throws IOException
+ * @since 1.1
+ */
+ private static InputStream internalGetInputStreamFor(URL url, int soTimeoutMillis, int
connTimeoutMillis) throws IOException
+ {
if (url == null)
{
throw new IllegalArgumentException();
@@ -105,26 +165,8 @@
conn.setConnectTimeout(soTimeoutMillis);
conn.setReadTimeout(connTimeoutMillis);
- //
- InputStream in = null;
- try
- {
- conn.connect();
- in = new BufferedInputStream(conn.getInputStream());
- return IOTools.getBytes(in);
- }
- catch (SocketTimeoutException e)
- {
- return null;
- }
- catch (IOException e)
- {
- return null;
- }
- finally
- {
- IOTools.safeClose(in);
- }
+ conn.connect();
+ return new BufferedInputStream(conn.getInputStream());
}
/**
@@ -257,14 +299,13 @@
}
/**
- * to remove : an API should not try to accomodate the client for that kind of
situation,
- * why not also something like forbidStringLengthToDivisibleBy3 ?
-
+ * to remove : an API should not try to accomodate the client for that kind of
situation, why not also something
+ * like forbidStringLengthToDivisibleBy3 ?
+ *
* @param stringURL
- * @param allowNull <code>true</code> if passing
<code>null</code> will be ignored and just return
- * <code>false</code>, <code>false</code>
to throw an {@link IllegalArgumentException} is the
- * given URL is <code>null</code>.
- *
+ * @param allowNull <code>true</code> if passing
<code>null</code> will be ignored and just return
+ * <code>false</code>, <code>false</code> to
throw an {@link IllegalArgumentException} is the given
+ * URL is <code>null</code>.
* @return
* @since 2.4.2
*/
Show replies by date