You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by pa...@apache.org on 2021/04/23 08:20:47 UTC
[groovy] 01/03: GROOVY-10050: Add additional NamedParam annotations
in ResourceGroovyMethods
This is an automated email from the ASF dual-hosted git repository.
paulk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git
commit e8bf15095e91e31685ef72e3850a945049836bf1
Author: Paul King <pa...@asert.com.au>
AuthorDate: Thu Apr 22 13:10:54 2021 +1000
GROOVY-10050: Add additional NamedParam annotations in ResourceGroovyMethods
---
.../groovy/runtime/ResourceGroovyMethods.java | 90 +++++++++++++++++-----
1 file changed, 69 insertions(+), 21 deletions(-)
diff --git a/src/main/java/org/codehaus/groovy/runtime/ResourceGroovyMethods.java b/src/main/java/org/codehaus/groovy/runtime/ResourceGroovyMethods.java
index 5f7bcaa..038f92f 100644
--- a/src/main/java/org/codehaus/groovy/runtime/ResourceGroovyMethods.java
+++ b/src/main/java/org/codehaus/groovy/runtime/ResourceGroovyMethods.java
@@ -621,7 +621,15 @@ public class ResourceGroovyMethods extends DefaultGroovyMethodsSupport {
* @throws IOException if an IOException occurs.
* @since 1.8.1
*/
- public static String getText(URL url, Map parameters) throws IOException {
+ public static String getText(
+ URL url,
+ @NamedParam(value = "connectTimeout", type = Integer.class)
+ @NamedParam(value = "readTimeout", type = Integer.class)
+ @NamedParam(value = "useCaches", type = Boolean.class)
+ @NamedParam(value = "allowUserInteraction", type = Boolean.class)
+ @NamedParam(value = "requestProperties", type = Map.class)
+ Map<String, ?> parameters
+ ) throws IOException {
return getText(url, parameters, CharsetToolkit.getDefaultSystemCharset().name());
}
@@ -653,7 +661,16 @@ public class ResourceGroovyMethods extends DefaultGroovyMethodsSupport {
* @see java.net.URLConnection#getInputStream()
* @since 1.8.1
*/
- public static String getText(URL url, Map parameters, String charset) throws IOException {
+ public static String getText(
+ URL url,
+ @NamedParam(value = "connectTimeout", type = Integer.class)
+ @NamedParam(value = "readTimeout", type = Integer.class)
+ @NamedParam(value = "useCaches", type = Boolean.class)
+ @NamedParam(value = "allowUserInteraction", type = Boolean.class)
+ @NamedParam(value = "requestProperties", type = Map.class)
+ Map<String, ?> parameters,
+ String charset
+ ) throws IOException {
BufferedReader reader = newReader(url, parameters, charset);
return IOGroovyMethods.getText(reader);
}
@@ -700,7 +717,15 @@ public class ResourceGroovyMethods extends DefaultGroovyMethodsSupport {
* @throws IOException if an IOException occurs.
* @since 2.4.4
*/
- public static byte[] getBytes(URL url, Map parameters) throws IOException {
+ public static byte[] getBytes(
+ URL url,
+ @NamedParam(value = "connectTimeout", type = Integer.class)
+ @NamedParam(value = "readTimeout", type = Integer.class)
+ @NamedParam(value = "useCaches", type = Boolean.class)
+ @NamedParam(value = "allowUserInteraction", type = Boolean.class)
+ @NamedParam(value = "requestProperties", type = Map.class)
+ Map<String, ?> parameters
+ ) throws IOException {
return IOGroovyMethods.getBytes(configuredInputStream(parameters, url));
}
@@ -1317,10 +1342,10 @@ public class ResourceGroovyMethods extends DefaultGroovyMethodsSupport {
@NamedParam(value = "postRoot", type = Boolean.class)
@NamedParam(value = "visitRoot", type = Boolean.class)
@NamedParam(value = "maxDepth", type = Integer.class)
- @NamedParam(value = "filter", type = Object.class)
- @NamedParam(value = "nameFilter", type = Object.class)
- @NamedParam(value = "excludeFilter", type = Object.class)
- @NamedParam(value = "excludeNameFilter", type = Object.class)
+ @NamedParam(value = "filter")
+ @NamedParam(value = "nameFilter")
+ @NamedParam(value = "excludeFilter")
+ @NamedParam(value = "excludeNameFilter")
@NamedParam(value = "sort", type = Closure.class)
final Map<String, ?> options,
@ClosureParams(value = SimpleType.class, options = "java.io.File")
@@ -1415,7 +1440,7 @@ public class ResourceGroovyMethods extends DefaultGroovyMethodsSupport {
*/
public static void traverse(final File self, @ClosureParams(value = SimpleType.class, options = "java.io.File") final Closure closure)
throws FileNotFoundException, IllegalArgumentException {
- traverse(self, new HashMap<String, Object>(), closure);
+ traverse(self, new HashMap<>(), closure);
}
/**
@@ -1439,10 +1464,10 @@ public class ResourceGroovyMethods extends DefaultGroovyMethodsSupport {
@NamedParam(value = "postRoot", type = Boolean.class)
@NamedParam(value = "visitRoot", type = Boolean.class)
@NamedParam(value = "maxDepth", type = Integer.class)
- @NamedParam(value = "filter", type = Object.class)
- @NamedParam(value = "nameFilter", type = Object.class)
- @NamedParam(value = "excludeFilter", type = Object.class)
- @NamedParam(value = "excludeNameFilter", type = Object.class)
+ @NamedParam(value = "filter")
+ @NamedParam(value = "nameFilter")
+ @NamedParam(value = "excludeFilter")
+ @NamedParam(value = "excludeNameFilter")
@NamedParam(value = "sort", type = Closure.class)
final Map<String, ?> options)
throws FileNotFoundException, IllegalArgumentException {
@@ -2195,7 +2220,7 @@ public class ResourceGroovyMethods extends DefaultGroovyMethodsSupport {
* @throws IOException if an I/O error occurs while creating the input stream
* @since 1.8.1
*/
- private static InputStream configuredInputStream(Map parameters, URL url) throws IOException {
+ private static InputStream configuredInputStream(Map<String, ?> parameters, URL url) throws IOException {
final URLConnection connection = url.openConnection();
if (parameters != null) {
if (parameters.containsKey("connectTimeout")) {
@@ -2227,11 +2252,10 @@ public class ResourceGroovyMethods extends DefaultGroovyMethodsSupport {
*
* @param url a URL
* @return a BufferedInputStream for the URL
- * @throws MalformedURLException is thrown if the URL is not well formed
* @throws IOException if an I/O error occurs while creating the input stream
* @since 1.5.2
*/
- public static BufferedInputStream newInputStream(URL url) throws MalformedURLException, IOException {
+ public static BufferedInputStream newInputStream(URL url) throws IOException {
return new BufferedInputStream(configuredInputStream(null, url));
}
@@ -2250,11 +2274,18 @@ public class ResourceGroovyMethods extends DefaultGroovyMethodsSupport {
* @param url a URL
* @param parameters connection parameters
* @return a BufferedInputStream for the URL
- * @throws MalformedURLException is thrown if the URL is not well formed
* @throws IOException if an I/O error occurs while creating the input stream
* @since 1.8.1
*/
- public static BufferedInputStream newInputStream(URL url, Map parameters) throws MalformedURLException, IOException {
+ public static BufferedInputStream newInputStream(
+ URL url,
+ @NamedParam(value = "connectTimeout", type = Integer.class)
+ @NamedParam(value = "readTimeout", type = Integer.class)
+ @NamedParam(value = "useCaches", type = Boolean.class)
+ @NamedParam(value = "allowUserInteraction", type = Boolean.class)
+ @NamedParam(value = "requestProperties", type = Map.class)
+ Map<String, ?> parameters
+ ) throws IOException {
return new BufferedInputStream(configuredInputStream(parameters, url));
}
@@ -2267,7 +2298,7 @@ public class ResourceGroovyMethods extends DefaultGroovyMethodsSupport {
* @throws IOException if an I/O error occurs while creating the input stream
* @since 1.5.5
*/
- public static BufferedReader newReader(URL url) throws MalformedURLException, IOException {
+ public static BufferedReader newReader(URL url) throws IOException {
return IOGroovyMethods.newReader(configuredInputStream(null, url));
}
@@ -2290,7 +2321,15 @@ public class ResourceGroovyMethods extends DefaultGroovyMethodsSupport {
* @throws IOException if an I/O error occurs while creating the input stream
* @since 1.8.1
*/
- public static BufferedReader newReader(URL url, Map parameters) throws MalformedURLException, IOException {
+ public static BufferedReader newReader(
+ URL url,
+ @NamedParam(value = "connectTimeout", type = Integer.class)
+ @NamedParam(value = "readTimeout", type = Integer.class)
+ @NamedParam(value = "useCaches", type = Boolean.class)
+ @NamedParam(value = "allowUserInteraction", type = Boolean.class)
+ @NamedParam(value = "requestProperties", type = Map.class)
+ Map<String, ?> parameters
+ ) throws IOException {
return IOGroovyMethods.newReader(configuredInputStream(parameters, url));
}
@@ -2304,7 +2343,7 @@ public class ResourceGroovyMethods extends DefaultGroovyMethodsSupport {
* @throws IOException if an I/O error occurs while creating the input stream
* @since 1.5.5
*/
- public static BufferedReader newReader(URL url, String charset) throws MalformedURLException, IOException {
+ public static BufferedReader newReader(URL url, String charset) throws IOException {
return new BufferedReader(new InputStreamReader(configuredInputStream(null, url), charset));
}
@@ -2319,7 +2358,16 @@ public class ResourceGroovyMethods extends DefaultGroovyMethodsSupport {
* @throws IOException if an I/O error occurs while creating the input stream
* @since 1.8.1
*/
- public static BufferedReader newReader(URL url, Map parameters, String charset) throws MalformedURLException, IOException {
+ public static BufferedReader newReader(
+ URL url,
+ @NamedParam(value = "connectTimeout", type = Integer.class)
+ @NamedParam(value = "readTimeout", type = Integer.class)
+ @NamedParam(value = "useCaches", type = Boolean.class)
+ @NamedParam(value = "allowUserInteraction", type = Boolean.class)
+ @NamedParam(value = "requestProperties", type = Map.class)
+ Map<String, ?> parameters,
+ String charset
+ ) throws IOException {
return new BufferedReader(new InputStreamReader(configuredInputStream(parameters, url), charset));
}