private void closeAllHandles() throws Throwable { Throwable lastThrowable = null; for ( DocumentWriteOperation doc : writeSet.getWriteSet() ) { try { if ( doc.getContent() instanceof Closeable ) { ((Closeable) doc.getContent()).close(); } if ( doc.getMetadata() instanceof Closeable ) { ((Closeable) doc.getMetadata()).close(); } } catch (Throwable t) { logger.error("error calling close()", t); lastThrowable = t; } } if ( lastThrowable != null ) throw lastThrowable; } }
@Override public void write(List<? extends DocumentWriteOperation> items) { for (DocumentWriteOperation op : items) { writeBatcher.add(op.getUri(), op.getMetadata(), op.getContent()); } }
@Override public Content adapt(DocumentWriteOperation operation) { String uri = operation.getUri(); ContentCreateOptions options = adaptMetadata(operation.getMetadata()); AbstractWriteHandle handle = operation.getContent(); if (handle instanceof StringHandle) { return ContentFactory.newContent(uri, ((StringHandle) handle).get(), options); } else if (handle instanceof FileHandle) { return ContentFactory.newContent(uri, ((FileHandle) handle).get(), options); } else if (handle instanceof BytesHandle) { return ContentFactory.newContent(uri, ((BytesHandle) handle).get(), options); } else if (handle instanceof InputStreamHandle) { try { return ContentFactory.newContent(uri, ((InputStreamHandle) handle).get(), options); } catch (IOException e) { throw new RuntimeException("Unable to read content input stream: " + e.getMessage(), e); } } else if (handle instanceof DOMHandle) { return ContentFactory.newContent(uri, ((DOMHandle) handle).get(), options); } else throw new IllegalArgumentException("No support yet for content class: " + handle.getClass().getName()); }
for ( DocumentWriteOperation write : writeSet ) { String temporalDocumentURI = write.getTemporalDocumentURI(); HandleImplementation metadata = HandleAccessor.checkHandle(write.getMetadata(), "write"); HandleImplementation content = HandleAccessor.checkHandle(write.getContent(), "write"); String contentDispositionTemporal = ""; headers.add(HEADER_CONTENT_DISPOSITION, DISPOSITION_TYPE_INLINE + "; category=metadata" + contentDispositionTemporal); headerList.add(headers); writeHandles.add(write.getMetadata()); } else if ( metadata != null ) { RequestParameters headers = new RequestParameters(); writeHandles.add(write.getMetadata());
public WriteBatch getBatchOfWriteEvents() { WriteBatchImpl batch = new WriteBatchImpl() .withBatcher(batcher) .withClient(client) .withJobBatchNumber(batchNumber) .withJobWritesSoFar(itemsSoFar) .withJobTicket(batcher.getJobTicket()); WriteEvent[] writeEvents = getWriteSet().stream() .map(writeOperation -> new WriteEventImpl() .withTargetUri(writeOperation.getUri()) .withContent(writeOperation.getContent()) .withMetadata(writeOperation.getMetadata()) ) .toArray(WriteEventImpl[]::new); batch.withItems(writeEvents); return batch; } }