/** * Tags any IOExceptions thrown, wrapping and re-throwing. * * @param e The IOException thrown * @throws IOException if an I/O error occurs */ @Override protected void handleIOException(final IOException e) throws IOException { throw new TaggedIOException(e, tag); }
/** * Tags any IOExceptions thrown, wrapping and re-throwing. * * @param e The IOException thrown * @throws IOException if an I/O error occurs */ @Override protected void handleIOException(final IOException e) throws IOException { throw new TaggedIOException(e, tag); }
@Test public void testOtherException() throws Exception { final IOException exception = new IOException("test exception"); final InputStream closed = new ClosedInputStream(); final TaggedInputStream stream = new TaggedInputStream(closed); assertFalse(stream.isCauseOf(exception)); assertFalse(stream.isCauseOf( new TaggedIOException(exception, UUID.randomUUID()))); stream.throwIfCauseOf(exception); stream.throwIfCauseOf( new TaggedIOException(exception, UUID.randomUUID())); stream.close(); }
@Test public void testTaggedIOException() { final Serializable tag = UUID.randomUUID(); final IOException exception = new IOException("Test exception"); final TaggedIOException tagged = new TaggedIOException(exception, tag); assertTrue(TaggedIOException.isTaggedWith(tagged, tag)); assertFalse(TaggedIOException.isTaggedWith(tagged, UUID.randomUUID())); assertEquals(exception, tagged.getCause()); assertEquals(exception.getMessage(), tagged.getMessage()); }
@Test public void testOtherException() throws Exception { final IOException exception = new IOException("test exception"); final OutputStream closed = new ClosedOutputStream(); final TaggedOutputStream stream = new TaggedOutputStream(closed); assertFalse(stream.isCauseOf(exception)); assertFalse(stream.isCauseOf( new TaggedIOException(exception, UUID.randomUUID()))); try { stream.throwIfCauseOf(exception); } catch (final IOException e) { fail("Unexpected exception thrown"); } try { stream.throwIfCauseOf( new TaggedIOException(exception, UUID.randomUUID())); } catch (final IOException e) { fail("Unexpected exception thrown"); } stream.close(); }
/** * Tags any IOExceptions thrown, wrapping and re-throwing. * * @param e The IOException thrown * @throws IOException if an I/O error occurs */ @Override protected void handleIOException(IOException e) throws IOException { throw new TaggedIOException(e, tag); }
/** * Tags any IOExceptions thrown, wrapping and re-throwing. * * @param e The IOException thrown * @throws IOException if an I/O error occurs */ @Override protected void handleIOException(IOException e) throws IOException { throw new TaggedIOException(e, tag); }
/** * Tags any IOExceptions thrown, wrapping and re-throwing. * * @param e The IOException thrown * @throws IOException if an I/O error occurs */ @Override protected void handleIOException(final IOException e) throws IOException { throw new TaggedIOException(e, tag); }
/** * Tags any IOExceptions thrown, wrapping and re-throwing. * * @param e The IOException thrown * @throws IOException if an I/O error occurs */ @Override protected void handleIOException(IOException e) throws IOException { throw new TaggedIOException(e, tag); }
/** * Tags any IOExceptions thrown, wrapping and re-throwing. * * @param e The IOException thrown * @throws IOException if an I/O error occurs */ @Override protected void handleIOException(final IOException e) throws IOException { throw new TaggedIOException(e, tag); }
/** * Tags any IOExceptions thrown, wrapping and re-throwing. * * @param e The IOException thrown * @throws IOException if an I/O error occurs */ @Override protected void handleIOException(IOException e) throws IOException { throw new TaggedIOException(e, tag); }
/** * Tags any IOExceptions thrown, wrapping and re-throwing. * * @param e The IOException thrown * @throws IOException if an I/O error occurs */ @Override protected void handleIOException(final IOException e) throws IOException { throw new TaggedIOException(e, tag); }
/** * Tags any IOExceptions thrown, wrapping and re-throwing. * * @param e The IOException thrown * @throws IOException if an I/O error occurs */ @Override protected void handleIOException(final IOException e) throws IOException { throw new TaggedIOException(e, tag); }
private void put(final HttpPut put) throws IOException { logger.info(String.format("Writing to \"%s\".", put.getURI())); try (final CloseableHttpResponse response = client.execute(put)) { final int code = response.getStatusLine().getStatusCode(); if (code < 200 || code >= 300) { throw new TaggedIOException(new IOException(String.format("Unexpected response code: %d", code)), this); } } } }
@Override public void writeMetadata(final TikaDocument tikaDocument) throws IOException { final Metadata metadata = tikaDocument.getMetadata(); Path outputPath = getOutputPath(tikaDocument); outputPath = outputPath.getFileSystem().getPath(outputPath.toString() + ".json"); logger.info(String.format("Outputting metadata to file: \"%s\".", outputPath)); try (final JsonGenerator jsonGenerator = new JsonFactory().createGenerator(outputPath.toFile(), JsonEncoding.UTF8)) { jsonGenerator.useDefaultPrettyPrinter(); jsonGenerator.writeStartObject(); new MetadataTransformer(metadata, fields).transform(jsonGenerator::writeStringField, (name, values)-> { jsonGenerator.writeArrayFieldStart(name); jsonGenerator.writeStartArray(); for (String value: values) { jsonGenerator.writeString(value); } }); jsonGenerator.writeEndObject(); jsonGenerator.writeRaw('\n'); } catch (IOException e) { throw new TaggedIOException(new IOException("Unable to output JSON."), this); } }
throw new TaggedIOException(new IOException(String.format("Unable to make directories for file: \"%s\".", contentsOutputPath)), this); } catch (IOException e) { if (null != tagged && tagged.isCauseOf(e)) { throw new TaggedIOException(new IOException(String.format("Error writing output to file: \"%s\".", contentsOutputPath), e), this); } else {
throw new TaggedIOException(e, getClass());
@Override public void write(final TikaDocument tikaDocument, final Reader reader) throws IOException { if (outputMetadata) { writeMetadata(tikaDocument); } // A PrintStream should never throw an IOException: the exception would always come from the input stream. // There's no need to use a TaggedOutputStream or catch IOExceptions. copy(reader, stream); // Add an extra newline to signify the end of the text. stream.println(); if (stream.checkError()) { throw new TaggedIOException(new IOException("Error writing to print stream."), this); } // Write out child documents, if any. for (EmbeddedTikaDocument embed: tikaDocument.getEmbeds()) { try (final Reader embedReader = embed.getReader()) { write(embed, embedReader); } } }