@Override public void write(final int b) throws IOException { try { out.write(b); } catch (final IOException ioe) { throw new FlowFileAccessException("Could not write to " + flowFile, ioe); } }
} catch (final FlowFileAccessException e) { context.yield(); logger.error("Unable to retrieve file {} due to {}", new Object[]{file.getFullPathFileName(), e.getCause()}, e);
} catch (final FlowFileAccessException e) { context.yield(); logger.error("Unable to transfer {} to remote host {} due to {}", new Object[]{flowFile, hostname, e.getCause()}); flowFile = session.penalize(flowFile); session.transfer(flowFile, REL_FAILURE);
@Override public void write(final byte[] b, final int off, final int len) throws IOException { try { out.write(b, off, len); } catch (final IOException ioe) { throw new FlowFileAccessException("Could not write to " + flowFile, ioe); } }
} catch (final FlowFileAccessException e) { context.yield(); logger.error("Unable to retrieve file {} due to {}", new Object[]{file.getFullPathFileName(), e.getCause()}, e);
@Override public void flush() throws IOException { try { out.flush(); } catch (final IOException ioe) { throw new FlowFileAccessException("Could not flush OutputStream for " + flowFile, ioe); } } }
} catch (final FlowFileAccessException e) { context.yield(); logger.error("Unable to transfer {} to remote host {} due to {}", new Object[]{flowFile, hostname, e.getCause()}); flowFile = session.penalize(flowFile); session.transfer(flowFile, REL_FAILURE);
@Override public void write(final byte[] b) throws IOException { try { out.write(b); } catch (final IOException ioe) { throw new FlowFileAccessException("Could not write to " + flowFile, ioe); } }
@Override public int available() throws IOException { try { return super.available(); } catch (final IOException ioe) { throw new FlowFileAccessException("Could not determine amount of data available from " + flowFile, ioe); } }
@Override public long skip(final long n) throws IOException { try { final long count = super.skip(n); bytesConsumed += count; return count; } catch (final IOException ioe) { throw new FlowFileAccessException("Could not skip data in " + flowFile, ioe); } }
@Override public void reset() throws IOException { try { super.reset(); } catch (final IOException ioe) { throw new FlowFileAccessException("Could not reset stream from " + flowFile, ioe); } }
@Override public int read() throws IOException { try { final int byteRead = super.read(); if (byteRead < 0) { ensureAllContentRead(); } else { bytesConsumed++; } return byteRead; } catch (final ContentNotFoundException cnfe) { throw cnfe; } catch (final IOException ioe) { throw new FlowFileAccessException("Could not read from " + flowFile, ioe); } }
private void closeStreams(final Map<FlowFile, ? extends Closeable> streamMap, final boolean enforceClosed) { final Map<FlowFile, ? extends Closeable> openStreamCopy = new HashMap<>(streamMap); // avoid ConcurrentModificationException by creating a copy of the List for (final Map.Entry<FlowFile, ? extends Closeable> entry : openStreamCopy.entrySet()) { final FlowFile flowFile = entry.getKey(); final Closeable openStream = entry.getValue(); try { openStream.close(); } catch (IOException e) { throw new FlowFileAccessException("Failed to close stream for " + flowFile, e); } if (enforceClosed) { throw new FlowFileHandlingException("Cannot commit session because the following streams were created via " + "calls to ProcessSession.read(FlowFile) or ProcessSession.write(FlowFile) and never closed: " + streamMap); } } }
@Override public int read(final byte[] b, final int off, final int len) throws IOException { try { final int count = super.read(b, off, len); if (count < 0) { ensureAllContentRead(); } else { bytesConsumed += count; } return count; } catch (final ContentNotFoundException cnfe) { throw cnfe; } catch (final IOException ioe) { throw new FlowFileAccessException("Could not read from " + flowFile, ioe); } }
@Override public int read(final byte[] b) throws IOException { try { final int count = super.read(b); if (count < 0) { ensureAllContentRead(); } else { bytesConsumed += count; } return count; } catch (final ContentNotFoundException cnfe) { throw cnfe; } catch (final IOException ioe) { throw new FlowFileAccessException("Could not read from " + flowFile, ioe); } }
@Override public void exportTo(FlowFile flowFile, final Path path, final boolean append) { flowFile = validateState(flowFile); if (flowFile == null || path == null) { throw new IllegalArgumentException("argument cannot be null"); } if (!(flowFile instanceof MockFlowFile)) { throw new IllegalArgumentException("Cannot export a flow file that I did not create"); } final MockFlowFile mock = (MockFlowFile) flowFile; final OpenOption mode = append ? StandardOpenOption.APPEND : StandardOpenOption.CREATE; try (final OutputStream out = Files.newOutputStream(path, mode)) { out.write(mock.getData()); } catch (final IOException e) { throw new FlowFileAccessException(e.toString(), e); } }
@Override public void exportTo(FlowFile flowFile, final OutputStream out) { flowFile = validateState(flowFile); if (flowFile == null || out == null) { throw new IllegalArgumentException("arguments cannot be null"); } if (!(flowFile instanceof MockFlowFile)) { throw new IllegalArgumentException("Cannot export a flow file that I did not create"); } final MockFlowFile mock = (MockFlowFile) flowFile; try { out.write(mock.getData()); } catch (final IOException e) { throw new FlowFileAccessException(e.toString(), e); } }
private void resetWriteClaims(final boolean suppressExceptions) { for (final ByteCountingOutputStream out : appendableStreams.values()) { try { try { out.flush(); } finally { out.close(); } } catch (final IOException e) { if (!suppressExceptions) { throw new FlowFileAccessException("Unable to flush the output of FlowFile to the Content Repository"); } } } appendableStreams.clear(); }
@Override public byte[] getData() { final int attempts = getMessageAttempts.incrementAndGet(); if (attempts == 1) { throw new FlowFileAccessException("Unit test failure"); } else { return VALID_MESSAGE.getBytes(); } } });
@Override public void write(final byte[] b) throws IOException { try { countingOut.write(b); } catch (final IOException ioe) { LOG.error("Failed to write content to " + sourceFlowFile + "; rolling back session", ioe); rollback(true); close(); throw new FlowFileAccessException("Failed to write to Content Repository for " + sourceFlowFile, ioe); } }