use of java.io.Closeable in project spring-boot by spring-projects.
the class SampleNarayanaApplication method main.
public static void main(String[] args) throws Exception {
ApplicationContext context = SpringApplication.run(SampleNarayanaApplication.class, args);
AccountService service = context.getBean(AccountService.class);
AccountRepository repository = context.getBean(AccountRepository.class);
service.createAccountAndNotify("josh");
System.out.println("Count is " + repository.count());
try {
// Using username "error" will cause service to throw SampleRuntimeException
service.createAccountAndNotify("error");
} catch (SampleRuntimeException ex) {
// Log message to let test case know that exception was thrown
System.out.println(ex.getMessage());
}
System.out.println("Count is " + repository.count());
((Closeable) context).close();
}
use of java.io.Closeable in project exhibitor by soabase.
the class ExhibitorServletContextListener method contextDestroyed.
@Override
public void contextDestroyed(ServletContextEvent event) {
if (exhibitor != null) {
CloseableUtils.closeQuietly(exhibitor);
exhibitor = null;
}
if (exhibitorCreator != null) {
for (Closeable closeable : exhibitorCreator.getCloseables()) {
CloseableUtils.closeQuietly(closeable);
}
}
}
use of java.io.Closeable in project spring-framework by spring-projects.
the class AbstractXlsView method renderWorkbook.
/**
* The actual render step: taking the POI {@link Workbook} and rendering
* it to the given response.
* @param workbook the POI Workbook to render
* @param response current HTTP response
* @throws IOException when thrown by I/O methods that we're delegating to
*/
protected void renderWorkbook(Workbook workbook, HttpServletResponse response) throws IOException {
ServletOutputStream out = response.getOutputStream();
workbook.write(out);
// Closeable only implemented as of POI 3.10
if (workbook instanceof Closeable) {
((Closeable) workbook).close();
}
}
use of java.io.Closeable in project cassandra by apache.
the class OutOfSpaceTest method testFlushUnwriteableDie.
@Test
public void testFlushUnwriteableDie() throws Throwable {
makeTable();
KillerForTests killerForTests = new KillerForTests();
JVMStabilityInspector.Killer originalKiller = JVMStabilityInspector.replaceKiller(killerForTests);
DiskFailurePolicy oldPolicy = DatabaseDescriptor.getDiskFailurePolicy();
try (Closeable c = Util.markDirectoriesUnwriteable(getCurrentColumnFamilyStore())) {
DatabaseDescriptor.setDiskFailurePolicy(DiskFailurePolicy.die);
flushAndExpectError();
Assert.assertTrue(killerForTests.wasKilled());
//only killed quietly on startup failure
Assert.assertFalse(killerForTests.wasKilledQuietly());
} finally {
DatabaseDescriptor.setDiskFailurePolicy(oldPolicy);
JVMStabilityInspector.replaceKiller(originalKiller);
}
}
use of java.io.Closeable in project cassandra by apache.
the class OutOfSpaceTest method testFlushUnwriteableStop.
@Test
public void testFlushUnwriteableStop() throws Throwable {
makeTable();
DiskFailurePolicy oldPolicy = DatabaseDescriptor.getDiskFailurePolicy();
try (Closeable c = Util.markDirectoriesUnwriteable(getCurrentColumnFamilyStore())) {
DatabaseDescriptor.setDiskFailurePolicy(DiskFailurePolicy.stop);
flushAndExpectError();
Assert.assertFalse(Gossiper.instance.isEnabled());
} finally {
DatabaseDescriptor.setDiskFailurePolicy(oldPolicy);
}
}
Aggregations