Search in sources :

Example 36 with Closeable

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();
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) Closeable(java.io.Closeable)

Example 37 with Closeable

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);
        }
    }
}
Also used : Closeable(java.io.Closeable)

Example 38 with 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();
    }
}
Also used : ServletOutputStream(javax.servlet.ServletOutputStream) Closeable(java.io.Closeable)

Example 39 with Closeable

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);
    }
}
Also used : JVMStabilityInspector(org.apache.cassandra.utils.JVMStabilityInspector) KillerForTests(org.apache.cassandra.utils.KillerForTests) DiskFailurePolicy(org.apache.cassandra.config.Config.DiskFailurePolicy) Closeable(java.io.Closeable) Test(org.junit.Test)

Example 40 with Closeable

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);
    }
}
Also used : DiskFailurePolicy(org.apache.cassandra.config.Config.DiskFailurePolicy) Closeable(java.io.Closeable) Test(org.junit.Test)

Aggregations

Closeable (java.io.Closeable)216 IOException (java.io.IOException)88 Test (org.junit.Test)56 ArrayList (java.util.ArrayList)29 File (java.io.File)26 HashMap (java.util.HashMap)12 VirtualFile (org.jboss.vfs.VirtualFile)12 URL (java.net.URL)9 Path (java.nio.file.Path)9 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)8 Map (java.util.Map)7 ISE (io.druid.java.util.common.ISE)6 InputStream (java.io.InputStream)6 MountHandle (org.jboss.as.server.deployment.module.MountHandle)6 ResourceRoot (org.jboss.as.server.deployment.module.ResourceRoot)6 ProgramController (co.cask.cdap.app.runtime.ProgramController)5 ProgramType (co.cask.cdap.proto.ProgramType)4 ProgramId (co.cask.cdap.proto.id.ProgramId)4 Pair (io.druid.java.util.common.Pair)4 FileOutputStream (java.io.FileOutputStream)4