/** * Since the build process is multi-step and parses the content multiple times, it's necessary to be given * the byte[] and provide on-demand ByteArrayInputStreams as needed. * * @return InputStream */ protected InputStream getContentStream() throws FileNotFoundException { return artifactContent.getInputStream(); } }
@Override public void write(ArtificerDocumentArtifact artifact, ArtifactContent content, EntityManager entityManager) throws Exception { artifact.setContent(IOUtils.toByteArray(content.getInputStream())); } }
@Override public void write(ArtificerDocumentArtifact artifact, ArtifactContent content, EntityManager entityManager) throws Exception { InputStream inputStream = null; try { File out = new File(path + artifact.getUuid()); out.createNewFile(); inputStream = content.getInputStream(); Files.copy(content.getInputStream(), out.toPath(), StandardCopyOption.REPLACE_EXISTING); artifact.setContentPath(path + artifact.getUuid()); } finally { if (inputStream != null) { IOUtils.closeQuietly(inputStream); } } } }
private void processDocument(ArtificerDocumentArtifact artificerArtifact, ArtifactContent content) throws Exception { InputStream inputStream = null; try { if (content != null) { artificerArtifact.setContentSize(content.getSize()); inputStream = content.getInputStream(); String sha1Hash = DigestUtils.shaHex(inputStream); artificerArtifact.setContentHash(sha1Hash); } else { artificerArtifact.setContentSize(0); artificerArtifact.setContentHash(""); } } finally { if (inputStream != null) { IOUtils.closeQuietly(inputStream); } } } }