Thanks for the clarification. No objection to add another method to Closer that takes an additional vararg like Matt suggested. Also fine with consolidating the port finders.
Sent from my iPhone > On 2014/06/26, at 1:54, Gary Gregory <garydgreg...@gmail.com> wrote: > >> 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 >>>> JUnit in Action, Second Edition >>>> Spring Batch in Action >>>> 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 > JUnit in Action, Second Edition > Spring Batch in Action > Blog: http://garygregory.wordpress.com > Home: http://garygregory.com/ > Tweet! http://twitter.com/GaryGregory