void storeBuffer() throws IOException { final IOPool.Entry<?> buffer = this.buffer; final SequentialIOExceptionBuilder<IOException, SequentialIOException> builder = SequentialIOExceptionBuilder.create(IOException.class, SequentialIOException.class); try { final InputStream in = buffer.getInputSocket().newInputStream(); Streams.cat(in, zos); } catch (final InputException ex) { // NOT IOException! builder.warn(ex); builder.warn(ex); builder.warn(ex); } finally { try { in.close(); } catch (final IOException ex) { builder.warn(ex); buffer.release(); } catch (final IOException ex) { builder.warn(ex); builder.check();
@SuppressWarnings({ "unchecked", "element-type-mismatch" }) private void assertSequence(final Mapper mapper) throws X { final IOException warning = new IOException("warning"); final IOException failure = new IOException("failure"); builder.warn(warning); final SequentialIOException ex1 = builder.fail(failure); builder.check(); assertTrue(clazz.isInstance(ex1)); final SequentialIOException ex2 = mapper.map(ex1); assertTrue(clazz.isInstance(ex2)); final Set<IOException> causes = new HashSet<IOException>( Arrays.asList(warning, failure)); assertTrue(causes.remove(ex2.getCause())); assertTrue(causes.remove(ex2.getPredecessor().getCause())); assertTrue(causes.isEmpty()); assertNull(ex2.getPredecessor().getPredecessor()); }
@Test public void testChainingExceptionWithInitializedPredecessor() { builder.warn(newCause()); builder.warn(newCause()); try { builder.check(); fail(); } catch (final SequentialIOException expected) { assert expected.isInitPredecessor(); builder.warn(newCause()); builder.warn(expected); builder.warn(newCause()); } }