public static void writeToFile(File file, ImageUtils.StaticContentPathInfo pathInfo, byte[] content) throws ContentProviderException, IOException { if (pathInfo.isImage() && pathInfo.isResized()) { content = ImageUtils.resizeImage(content, pathInfo); } Files.write(content, file); }
ImageUtils.writeToFile(file, pathInfo, binaryData.getBytes()); } catch (IOException e) { throw new StaticContentNotLoadedException("Cannot write new loaded content to a file " + file, e);
@Override protected DefaultContentProvider.StaticContentFile getStaticContentFile(File file, ImageUtils.StaticContentPathInfo pathInfo, int publicationId) throws ContentProviderException, IOException { BinaryMeta binaryMeta; WebComponentMetaFactory factory = new WebComponentMetaFactoryImpl(publicationId); ComponentMeta componentMeta; int itemId; synchronized (LOCK) { binaryMeta = dynamicMetaRetriever.getBinaryMetaByURL(prependFullUrlIfNeeded(pathInfo.getFileName())); if (binaryMeta == null) { throw new StaticContentNotFoundException("No binary meta found for: [" + publicationId + "] " + pathInfo.getFileName()); } itemId = (int) binaryMeta.getURI().getItemId(); componentMeta = factory.getMeta(itemId); if (componentMeta == null) { throw new StaticContentNotFoundException("No meta meta found for: [" + publicationId + "] " + pathInfo.getFileName()); } } long componentTime = componentMeta.getLastPublicationDate().getTime(); if (isToBeRefreshed(file, componentTime)) { BinaryData binaryData = binaryContentRetriever.getBinary(publicationId, itemId, binaryMeta.getVariantId()); LOG.debug("Writing binary content to file: {}", file); writeToFile(file, pathInfo, binaryData.getBytes()); } else { LOG.debug("File does not need to be refreshed: {}", file); } return new StaticContentFile(file, binaryMeta.getType()); }