ContentItemUploadTask implements Comparable, ProgressListener { public void execute() throws Exception { File tmpFile = null; InputStream tmpStream = null; try { log.info("executing file upload: {}", contentItem); startDate = new Date(); tmpFile = IOUtil.writeStreamToFile(this.stream); tmpStream = IOUtil.getFileStream(tmpFile); contentStore.addContent(contentItem.getSpaceId(), contentItem.getContentId(), tmpStream, tmpFile.length(), contentItem.getContentMimetype(), null, null); log.info("file upload completed successfully: {}", contentItem); } catch (Exception ex) { log.error("failed to upload content item: {}, bytesRead={}, totalBytes={}, message: {}", new Object[] {contentItem, this.bytesRead, this.totalBytes, ex.getMessage()}); ex.printStackTrace(); throw ex; } finally { FileUtils.deleteQuietly(tmpFile); IOUtils.closeQuietly(tmpStream); } } ContentItemUploadTask(ContentItem contentItem,
                                 ContentStore contentStore,
                                 InputStream stream,
                                 String username); void execute(); void update(long pBytesRead, long pContentLength, int pItems); String getId(); Map<String, String> getProperties(); Date getStartDate(); @Override int compareTo(Object o); String getUsername(); String toString();  }
@Test public void testExecute() throws Exception { task = new ContentItemUploadTask(contentItem, contentStore, stream, username); task.execute(); }