On Wed, Jun 25, 2014 at 12:06 PM, Remko Popma <remko.po...@gmail.com> wrote:

> Don't mind the rename, but why would you need varargs?
> I don't think that would be much cleaner than simply calling
> Closer.closeSilently(a);
> Closer.closeSilently(b);
> ...
>

Because of org.apache.logging.log4j.core.net.FreePortFinder:

    public static int[] findFreePorts(final int count) throws IOException {
        final int[] ports = new int[count];
        final ServerSocket[] sockets = new ServerSocket[count];
        try {
            for (int i = 0; i < count; ++i) {
                sockets[i] = new ServerSocket(0);
                ports[i] = sockets[i].getLocalPort();
            }
        } finally {
            for (int i = 0; i < count; ++i) {
                Closer.closeSilently(sockets[i]);
            }
        }
        return ports;
    }

which is a method that was duplicated in each Flume test class and is now
in one spot.

There is a separate thread about this class.

Gary

>
> (And Closeable is only for io stuff (streams, files, ...). For database
> stuff like Statement, ResultSet, Connection you need separate methods
> anyway.)
>
>
> On Thu, Jun 26, 2014 at 12:02 AM, Matt Sicker <boa...@gmail.com> wrote:
>
>> I like calling it closeSilently(). And for varargs, I propose just adding
>> an additional method that takes things like close(Closeable c, Closeable...
>> more) or something like that.
>>
>>
>> On 24 June 2014 23:18, Gary Gregory <garydgreg...@gmail.com> wrote:
>>
>>> I just found a bunch of handy
>>> org.apache.logging.log4j.core.util.Closer.closeSilent() methods, very nice,
>>> I just reused one in a test. BUT these should be called IMO closeSilently().
>>>
>>> They also should be varargs methinks.
>>>
>>> Gary
>>>
>>> --
>>> E-Mail: garydgreg...@gmail.com | ggreg...@apache.org
>>> Java Persistence with Hibernate, Second Edition
>>> <http://www.manning.com/bauer3/>
>>> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
>>> Spring Batch in Action <http://www.manning.com/templier/>
>>> Blog: http://garygregory.wordpress.com
>>> Home: http://garygregory.com/
>>> Tweet! http://twitter.com/GaryGregory
>>>
>>
>>
>>
>> --
>> Matt Sicker <boa...@gmail.com>
>>
>
>


-- 
E-Mail: garydgreg...@gmail.com | ggreg...@apache.org
Java Persistence with Hibernate, Second Edition
<http://www.manning.com/bauer3/>
JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
Spring Batch in Action <http://www.manning.com/templier/>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory

Reply via email to