+1 this looks like an oversight Ted Yu <[email protected]> schrieb:
>This is an interesting idea. > >HTable already implements Closeable. > >Do you mind filing a JIRA (and optionally a patch) ? > >Thanks > >On Tue, Jan 10, 2012 at 2:57 AM, Ioan Eugen Stan <[email protected]>wrote: > >> Hello, >> >> In my code I get to write a lot of boilerplate code to close a HTable >> instance (see below snippet). Making HTableInterface extent >> java.io.Closeable would allow developers to use IOUtils.closeQuietly() >> from appache-commons or a similar method to cose a HTable instance >> without the extra code. What do you think? >> >> HTable table = null; >> try { >> table = new HTable(conf , "some table"); >> ResultScanner scanner = table.getScanner(scan); >> Result result; >> while ((result = scanner.next()) != null) { >> // do something >> } >> scanner.close(); // close the scanner >> } catch (IOException e) { >> LOG.error("Exception scanning in table"); >> } finally { >> // close the table >> if (table != null) { >> try { >> table.close(); >> } catch (IOException e) { >> >> } >> } >> } >> >> >> Cheers, >> >> -- >> Ioan Eugen Stan >> http://ieugen.blogspot.com/ >>
