Java Code Examples for org.alfresco.repo.content.filestore.FileContentWriter#putContent()

The following examples show how to use org.alfresco.repo.content.filestore.FileContentWriter#putContent() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ContentCacheImplTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Test
public void getWriter()
{
    final String url = "store://some/url.bin";
    
    FileContentWriter writer = (FileContentWriter) contentCache.getWriter(url);
    writer.putContent("Some test content for " + getClass().getName());
    
    assertEquals(url, writer.getContentUrl());
    // Check cached item is recorded properly in cache
    Mockito.verify(lookupTable).put(Key.forUrl(url), writer.getFile().getAbsolutePath());
    Mockito.verify(lookupTable).put(Key.forCacheFile(writer.getFile().getAbsolutePath()), url);
}
 
Example 2
Source File: AbstractImageMagickContentTransformerWorker.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Checks for the JMagick and ImageMagick dependencies, using the common
 * {@link #transformInternal(File, String , File, java.lang.String, TransformationOptions) transformation method} to check
 * that the sample image can be converted.
 * <p>
 * If initialization is successful, then autoregistration takes place.
 */
public void afterPropertiesSet()
{
    if (getMimetypeService() == null)
    {
        throw new AlfrescoRuntimeException("MimetypeMap not present");
    }
    if (!remoteTransformerClientConfigured())
    {
        try
        {
            // load, into memory the sample gif
            String resourcePath = "org/alfresco/repo/content/transform/magick/alfresco.gif";
            InputStream imageStream = getClass().getClassLoader().getResourceAsStream(resourcePath);
            if (imageStream == null)
            {
                throw new AlfrescoRuntimeException("Sample image not found: " + resourcePath);
            }
            // dump to a temp file
            File inputFile = TempFileProvider.createTempFile(
                    getClass().getSimpleName() + "_init_source_",
                    ".gif");
            FileContentWriter writer = new FileContentWriter(inputFile);
            writer.putContent(imageStream);

            // create the output file
            File outputFile = TempFileProvider.createTempFile(
                    getClass().getSimpleName() + "_init_target_",
                    ".png");

            // execute it
            transformInternal(
                    inputFile, MimetypeMap.MIMETYPE_IMAGE_GIF,
                    outputFile, MimetypeMap.MIMETYPE_IMAGE_PNG,
                    new TransformationOptions());

            // check that the file exists
            if (!outputFile.exists() || outputFile.length() == 0)
            {
                throw new Exception("Image conversion failed: \n" +
                        "   from: " + inputFile + "\n" +
                        "   to: " + outputFile);
            }
            // we can be sure that it works
            setAvailable(true);
        }
        catch (Throwable e)
        {
            logger.error(
                    getClass().getSimpleName() + " not available: " +
                            (e.getMessage() != null ? e.getMessage() : ""));
            // debug so that we can trace the issue if required
            logger.debug(e);
        }
    }
}
 
Example 3
Source File: StandardQuotaStrategy.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
private void saveDiskUsage()
{
    File usageFile = new File(cache.getCacheRoot(), CACHE_USAGE_FILENAME);
    FileContentWriter writer = new FileContentWriter(usageFile);
    writer.putContent(currentUsageBytes.toString());
}