You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by eginez <gi...@git.apache.org> on 2015/05/15 10:02:16 UTC

[GitHub] incubator-groovy pull request: GROOVY-7425: Adding 'getBytes(Map p...

GitHub user eginez opened a pull request:

    https://github.com/apache/incubator-groovy/pull/16

    GROOVY-7425: Adding 'getBytes(Map parameters)' method to the URL class

    Hi all, new contributor to groovy.lang
    from https://issues.apache.org/jira/browse/GROOVY-7425
    
    Let me know if there is anything that needs to be changed


You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/eginez/incubator-groovy master

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/incubator-groovy/pull/16.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #16
    
----
commit 2d93a1f7547ff3caf43b18325345493e85ce71a6
Author: Esteban <eg...@gmail.com>
Date:   2015-05-15T07:34:46Z

    GROOVY-7425: Adding 'getBytes(Map parameters)' method to the URL class

----


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-groovy pull request: GROOVY-7425: Adding 'getBytes(Map p...

Posted by eginez <gi...@git.apache.org>.
Github user eginez commented on a diff in the pull request:

    https://github.com/apache/incubator-groovy/pull/16#discussion_r30418806
  
    --- Diff: src/main/org/codehaus/groovy/runtime/ResourceGroovyMethods.java ---
    @@ -694,6 +694,29 @@ public static String getText(URL url, Map parameters, String charset) throws IOE
         }
     
         /**
    +     * Read the content of this URL and returns it as a byte[].
    +     * The default connection parameters can be modified by adding keys to the
    +     * <i>parameters map</i>:
    +     * <ul>
    +     * <li>connectTimeout : the connection timeout</li>
    +     * <li>readTimeout : the read timeout</li>
    +     * <li>useCaches : set the use cache property for the URL connection</li>
    +     * <li>allowUserInteraction : set the user interaction flag for the URL connection</li>
    +     * <li>requestProperties : a map of properties to be passed to the URL connection</li>
    +     * </ul>
    +     *
    +     * @param url        URL to read content from
    +     * @param parameters connection parameters
    +     * @return the byte[] from that URL
    +     * @throws IOException if an IOException occurs.
    +     * @since 2.4.1
    --- End diff --
    
    Ah sure I'll fix that


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-groovy pull request: GROOVY-7425: Adding 'getBytes(Map p...

Posted by paulk-asert <gi...@git.apache.org>.
Github user paulk-asert commented on a diff in the pull request:

    https://github.com/apache/incubator-groovy/pull/16#discussion_r30414741
  
    --- Diff: src/main/org/codehaus/groovy/runtime/ResourceGroovyMethods.java ---
    @@ -694,6 +694,29 @@ public static String getText(URL url, Map parameters, String charset) throws IOE
         }
     
         /**
    +     * Read the content of this URL and returns it as a byte[].
    +     * The default connection parameters can be modified by adding keys to the
    +     * <i>parameters map</i>:
    +     * <ul>
    +     * <li>connectTimeout : the connection timeout</li>
    +     * <li>readTimeout : the read timeout</li>
    +     * <li>useCaches : set the use cache property for the URL connection</li>
    +     * <li>allowUserInteraction : set the user interaction flag for the URL connection</li>
    +     * <li>requestProperties : a map of properties to be passed to the URL connection</li>
    +     * </ul>
    +     *
    +     * @param url        URL to read content from
    +     * @param parameters connection parameters
    +     * @return the byte[] from that URL
    +     * @throws IOException if an IOException occurs.
    +     * @since 2.4.1
    --- End diff --
    
    2.4.4 is our next planned release for the 2_4_X stream, so that would be the since version.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-groovy pull request: GROOVY-7425: Adding 'getBytes(Map p...

Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:

    https://github.com/apache/incubator-groovy/pull/16


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-groovy pull request: GROOVY-7425: Adding 'getBytes(Map p...

Posted by paulk-asert <gi...@git.apache.org>.
Github user paulk-asert commented on a diff in the pull request:

    https://github.com/apache/incubator-groovy/pull/16#discussion_r30414852
  
    --- Diff: src/test/org/codehaus/groovy/runtime/URLGetBytesTest.groovy ---
    @@ -0,0 +1,114 @@
    +/*
    + * Copyright 2003-2015 the original author or authors.
    + *
    + * Licensed under the Apache License, Version 2.0 (the "License");
    + * you may not use this file except in compliance with the License.
    + * You may obtain a copy of the License at
    + *
    + *      http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +package org.codehaus.groovy.runtime
    +
    +/**
    + * Tests for {@link DefaultGroovyMethods} URL.getBytes() methods.
    + *
    + */
    +class URLGetBytesTest extends GroovyTestCase {
    +    void testGetBytesFromURLWithParameters() {
    +        def url = new URL('http','groovy.codehaus.org',80, '/', new URLStreamHandler() {
    --- End diff --
    
    I know it's a dummy URLConnection but I'd probably change groovy.codehaus.org to groovy-lang.org.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-groovy pull request: GROOVY-7425: Adding 'getBytes(Map p...

Posted by eginez <gi...@git.apache.org>.
Github user eginez commented on a diff in the pull request:

    https://github.com/apache/incubator-groovy/pull/16#discussion_r30418833
  
    --- Diff: src/test/org/codehaus/groovy/runtime/URLGetBytesTest.groovy ---
    @@ -0,0 +1,114 @@
    +/*
    + * Copyright 2003-2015 the original author or authors.
    + *
    + * Licensed under the Apache License, Version 2.0 (the "License");
    + * you may not use this file except in compliance with the License.
    + * You may obtain a copy of the License at
    + *
    + *      http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +package org.codehaus.groovy.runtime
    +
    +/**
    + * Tests for {@link DefaultGroovyMethods} URL.getBytes() methods.
    + *
    + */
    +class URLGetBytesTest extends GroovyTestCase {
    +    void testGetBytesFromURLWithParameters() {
    +        def url = new URL('http','groovy.codehaus.org',80, '/', new URLStreamHandler() {
    +            @Override
    +            protected URLConnection openConnection(URL u) {
    +                new DummyURLConnection(new URL('http://groovy.codehaus.org'))
    +            }
    +
    +        })
    +
    +        assert url.bytes == 'Groovy'.bytes
    +
    +        shouldFail(SocketTimeoutException) {
    +            url.getBytes(readTimeout:5)
    +        }
    +
    +        shouldFail(SocketTimeoutException) {
    +            url.getText(connectTimeout:5)
    +        }
    +
    +        shouldFail(RuntimeException) {
    +            url.getBytes(allowUserInteraction:true)
    +        }
    +
    +        assert url.getBytes(useCaches:true) == 'Groovy cached'.bytes
    +
    +        assert url.getBytes(requestProperties:[a:'b']) == 'Groovy a:b'.bytes
    +
    +        assert url.getBytes(useCaches:true, requestProperties:[a:'b']) == 'Groovy cached a:b'.bytes
    +
    +        assert url.getBytes() == url.getBytes()
    --- End diff --
    
    oops line shouldn't be there, fixed


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-groovy pull request: GROOVY-7425: Adding 'getBytes(Map p...

Posted by eginez <gi...@git.apache.org>.
Github user eginez commented on a diff in the pull request:

    https://github.com/apache/incubator-groovy/pull/16#discussion_r30418860
  
    --- Diff: src/test/org/codehaus/groovy/runtime/URLGetBytesTest.groovy ---
    @@ -0,0 +1,114 @@
    +/*
    + * Copyright 2003-2015 the original author or authors.
    + *
    + * Licensed under the Apache License, Version 2.0 (the "License");
    + * you may not use this file except in compliance with the License.
    + * You may obtain a copy of the License at
    + *
    + *      http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +package org.codehaus.groovy.runtime
    +
    +/**
    + * Tests for {@link DefaultGroovyMethods} URL.getBytes() methods.
    + *
    + */
    +class URLGetBytesTest extends GroovyTestCase {
    +    void testGetBytesFromURLWithParameters() {
    +        def url = new URL('http','groovy.codehaus.org',80, '/', new URLStreamHandler() {
    --- End diff --
    
    good idea, changed!


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-groovy pull request: GROOVY-7425: Adding 'getBytes(Map p...

Posted by paulk-asert <gi...@git.apache.org>.
Github user paulk-asert commented on a diff in the pull request:

    https://github.com/apache/incubator-groovy/pull/16#discussion_r30414765
  
    --- Diff: src/test/org/codehaus/groovy/runtime/URLGetBytesTest.groovy ---
    @@ -0,0 +1,114 @@
    +/*
    + * Copyright 2003-2015 the original author or authors.
    + *
    + * Licensed under the Apache License, Version 2.0 (the "License");
    + * you may not use this file except in compliance with the License.
    + * You may obtain a copy of the License at
    + *
    + *      http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +package org.codehaus.groovy.runtime
    +
    +/**
    + * Tests for {@link DefaultGroovyMethods} URL.getBytes() methods.
    + *
    + */
    +class URLGetBytesTest extends GroovyTestCase {
    +    void testGetBytesFromURLWithParameters() {
    +        def url = new URL('http','groovy.codehaus.org',80, '/', new URLStreamHandler() {
    +            @Override
    +            protected URLConnection openConnection(URL u) {
    +                new DummyURLConnection(new URL('http://groovy.codehaus.org'))
    +            }
    +
    +        })
    +
    +        assert url.bytes == 'Groovy'.bytes
    +
    +        shouldFail(SocketTimeoutException) {
    +            url.getBytes(readTimeout:5)
    +        }
    +
    +        shouldFail(SocketTimeoutException) {
    +            url.getText(connectTimeout:5)
    +        }
    +
    +        shouldFail(RuntimeException) {
    +            url.getBytes(allowUserInteraction:true)
    +        }
    +
    +        assert url.getBytes(useCaches:true) == 'Groovy cached'.bytes
    +
    +        assert url.getBytes(requestProperties:[a:'b']) == 'Groovy a:b'.bytes
    +
    +        assert url.getBytes(useCaches:true, requestProperties:[a:'b']) == 'Groovy cached a:b'.bytes
    +
    +        assert url.getBytes() == url.getBytes()
    --- End diff --
    
    What are you trying to test with this line?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---