当前位置: 首页>>代码示例>>Java>>正文


Java ContentReader.getSize方法代码示例

本文整理汇总了Java中org.alfresco.service.cmr.repository.ContentReader.getSize方法的典型用法代码示例。如果您正苦于以下问题:Java ContentReader.getSize方法的具体用法?Java ContentReader.getSize怎么用?Java ContentReader.getSize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.alfresco.service.cmr.repository.ContentReader的用法示例。


在下文中一共展示了ContentReader.getSize方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: checkTransformable

import org.alfresco.service.cmr.repository.ContentReader; //导入方法依赖的package包/类
/**
 * Convenience method to check the transformability of a transformation
 * 
 * @param reader    content reader
 * @param writer    content writer
 * @param options   transformation options
 * @throws AlfrescoRuntimeException if the the transformation isn't supported
 */
protected void checkTransformable(ContentReader reader, ContentWriter writer, TransformationOptions options)
{
    String sourceMimetype = getMimetype(reader);
    String targetMimetype = getMimetype(writer);
    long sourceSize = reader.getSize();
    boolean transformable = isTransformable(sourceMimetype, sourceSize, targetMimetype, options);
    if (transformable == false)
    {
        // This method is only called once a transformer has been selected, so it should be able to
        // handle the mimetypes but might not be able to handle all the limits as it might be part of
        // of a complex (compound) transformer. So report the max size if set.
        long maxSourceSizeKBytes = getMaxSourceSizeKBytes(sourceMimetype, targetMimetype, options);
        boolean sizeOkay = maxSourceSizeKBytes < 0 || (maxSourceSizeKBytes > 0 && sourceSize <= maxSourceSizeKBytes*1024);
        AlfrescoRuntimeException e = new UnsupportedTransformationException("Unsupported transformation: " +
                getBeanName()+' '+sourceMimetype+" to "+targetMimetype+' '+
                (sizeOkay
                ? ""
                : transformerDebug.fileSize(sourceSize)+" > "+ transformerDebug.fileSize(maxSourceSizeKBytes*1024)));
        throw transformerDebug.setCause(e);
    }
    // it all checks out OK
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:31,代码来源:AbstractContentTransformer2.java

示例2: put

import org.alfresco.service.cmr.repository.ContentReader; //导入方法依赖的package包/类
@Override
public boolean put(String contentUrl, ContentReader source)
{
    File tempFile = createCacheFile();
    
    // Copy the content from the source into a cache file
    if (source.getSize() > 0L)
    {
        source.getContent(tempFile);
        File cacheFile = renameTempToActive(tempFile);
        // Add a record of the cached file to the in-memory cache.
        recordCacheEntries(contentUrl, cacheFile);
        return true;
    }

    return false;
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:18,代码来源:ContentCacheImpl.java

示例3: compareContentReaders

import org.alfresco.service.cmr.repository.ContentReader; //导入方法依赖的package包/类
/**
 * Does a comparison of the binaries associated with two readers.  Several shortcuts are assumed to be valid:<br/>
 *  - if the readers are the same instance, then the binaries are the same<br/>
 *  - if the size field is different, then the binaries are different<br/>
 * Otherwise the binaries are {@link EqualsHelper#binaryStreamEquals(InputStream, InputStream) compared}.
 * 
 * @return          Returns <tt>true</tt> if the underlying binaries are the same
 * @throws ContentIOException
 */
public static boolean compareContentReaders(ContentReader left, ContentReader right) throws ContentIOException
{
    if (left == right)
    {
        return true;
    }
    else if (left == null || right == null)
    {
        return false;
    }
    else if (left.getSize() != right.getSize())
    {
        return false;
    }
    InputStream leftIs = left.getContentInputStream();
    InputStream rightIs = right.getContentInputStream();
    try
    {
        return EqualsHelper.binaryStreamEquals(leftIs, rightIs);
    }
    catch (IOException e)
    {
        throw new ContentIOException(
                "Failed to compare content reader streams: \n" +
                "   Left:  " + left + "\n" +
                "   right: " + right);
    }
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:38,代码来源:AbstractContentReader.java

示例4: isTransformable

import org.alfresco.service.cmr.repository.ContentReader; //导入方法依赖的package包/类
/**
 * @see org.alfresco.service.cmr.repository.ContentService#isTransformable(org.alfresco.service.cmr.repository.ContentReader, org.alfresco.service.cmr.repository.ContentWriter, org.alfresco.service.cmr.repository.TransformationOptions)
 */
public boolean isTransformable(ContentReader reader, ContentWriter writer, TransformationOptions options)
{
 // check that source and target mimetypes are available
    String sourceMimetype = reader.getMimetype();
    if (sourceMimetype == null)
    {
        throw new AlfrescoRuntimeException("The content reader mimetype must be set: " + reader);
    }
    String targetMimetype = writer.getMimetype();
    if (targetMimetype == null)
    {
        throw new AlfrescoRuntimeException("The content writer mimetype must be set: " + writer);
    }
    
    long sourceSize = reader.getSize();
    try
    {
        // look for a transformer
        transformerDebug.pushAvailable(reader.getContentUrl(), sourceMimetype, targetMimetype, options);
        List<ContentTransformer> transformers = getActiveTransformers(sourceMimetype, sourceSize, targetMimetype, options);
        transformerDebug.availableTransformers(transformers, sourceSize, options, "ContentService.isTransformable(...)");
        
        return transformers.size() > 0; 
    }
    finally
    {
        transformerDebug.popAvailable();
    }
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:33,代码来源:ContentServiceImpl.java

示例5: testCreateRenditionThumbnailFromPdfPage2

import org.alfresco.service.cmr.repository.ContentReader; //导入方法依赖的package包/类
public void testCreateRenditionThumbnailFromPdfPage2() throws Exception
{
    ImageTransformationOptions options = new ImageTransformationOptions();
    PagedSourceOptions pagedSourceOptions = new PagedSourceOptions();
    pagedSourceOptions.setStartPageNumber(new Integer(2));
    pagedSourceOptions.setEndPageNumber(new Integer(2));
    options.addSourceOptions(pagedSourceOptions);
    
    ThumbnailDefinition thumbnailDefinition = new ThumbnailDefinition(MimetypeMap.MIMETYPE_PDF, options, "doclib_2");
    thumbnailService.getThumbnailRegistry().addThumbnailDefinition(thumbnailDefinition);

    checkTransformer();

    NodeRef pdfOrig = createOriginalContent(this.folder, MimetypeMap.MIMETYPE_PDF);

    NodeRef thumbnail0 = this.thumbnailService.createThumbnail(pdfOrig, ContentModel.PROP_CONTENT,
                MimetypeMap.MIMETYPE_IMAGE_JPEG, thumbnailDefinition.getTransformationOptions(), "doclib_2");
    assertNotNull(thumbnail0);
    checkRenditioned(pdfOrig, Collections.singletonList(new ExpectedAssoc(RegexQNamePattern.MATCH_ALL, "doclib_2", 1)));
    checkRendition("doclib_2", thumbnail0);
    
    // Check the length
    File tempFile = TempFileProvider.createTempFile("thumbnailServiceImplTest", ".jpg");
    ContentReader reader = this.contentService.getReader(thumbnail0, ContentModel.PROP_CONTENT);
    
    long size = reader.getSize();
    System.out.println("size=" + size);
    assertTrue("Page 2 should be blank and less than 4500 bytes", size < 4500);
    
    reader.getContent(tempFile);
    System.out.println("doclib_2 test: " + tempFile.getPath());
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:33,代码来源:ThumbnailServiceImplTest.java

示例6: testAutoSettingOfProperties

import org.alfresco.service.cmr.repository.ContentReader; //导入方法依赖的package包/类
/**
 * Checks that the URL, mimetype and encoding are automatically set on the readers
 * and writers
 */
public void testAutoSettingOfProperties() throws Exception
{
    // get a writer onto the node
    ContentWriter writer = contentService.getWriter(contentNodeRef, ContentModel.PROP_CONTENT, true);
    assertNotNull("Writer should not be null", writer);
    assertNotNull("Content URL should not be null", writer.getContentUrl());
    assertNotNull("Content mimetype should not be null", writer.getMimetype());
    assertNotNull("Content encoding should not be null", writer.getEncoding());
    assertNotNull("Content locale should not be null", writer.getLocale());
    
    // write some content
    writer.putContent(SOME_CONTENT);
    
    // get the reader
    ContentReader reader = contentService.getReader(contentNodeRef, ContentModel.PROP_CONTENT);
    assertNotNull("Reader should not be null", reader);
    assertNotNull("Content URL should not be null", reader.getContentUrl());
    assertNotNull("Content mimetype should not be null", reader.getMimetype());
    assertNotNull("Content encoding should not be null", reader.getEncoding());
    assertNotNull("Content locale should not be null", reader.getLocale());
    
    // check that the content length is correct
    // - note encoding is important as we get the byte length
    long length = SOME_CONTENT.getBytes(reader.getEncoding()).length;  // ensures correct decoding
    long checkLength = reader.getSize();
    assertEquals("Content length incorrect", length, checkLength);

    // check the content - the encoding will come into effect here
    String contentCheck = reader.getContentString();
    assertEquals("Content incorrect", SOME_CONTENT, contentCheck);
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:36,代码来源:RoutingContentServiceTest.java

示例7: testFailingEmbedder

import org.alfresco.service.cmr.repository.ContentReader; //导入方法依赖的package包/类
/**
 * Test that a failing embedder does not destroy the original content
 */
public void testFailingEmbedder()
{
    MetadataExtracterRegistry registry = (MetadataExtracterRegistry) applicationContext.getBean("metadataExtracterRegistry");
    FailingEmbedder embedder = new FailingEmbedder(Arrays.asList(MimetypeMap.MIMETYPE_PDF));
    embedder.setRegistry(registry);
    embedder.setDictionaryService(this.dictionaryService);
    embedder.setMimetypeService(this.mimetypeService);
    embedder.register();
    
    String myCreator = "Embedded creator";

    // Get the old props
    Map<QName, Serializable> props = this.nodeService.getProperties(this.nodeRef);
    props.put(ContentModel.PROP_AUTHOR, myCreator);
    this.nodeService.setProperties(this.nodeRef, props);

    // Execute the action
    ActionImpl action = new ActionImpl(null, ID, SetPropertyValueActionExecuter.NAME, null);
    
    ContentReader origReader = this.contentService.getReader(this.nodeRef, ContentModel.PROP_CONTENT);
    long origSize = origReader.getSize();
    assertTrue(origSize > 0);

    this.executer.execute(action, this.nodeRef);
    
    ContentReader embeddedReader = this.contentService.getReader(this.nodeRef, ContentModel.PROP_CONTENT);
    
    assertEquals("The original content should remain unchanged on embed failures", origSize, embeddedReader.getSize());
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:33,代码来源:ContentMetadataEmbedderTest.java

示例8: BinaryProperty

import org.alfresco.service.cmr.repository.ContentReader; //导入方法依赖的package包/类
/**
 * This is the preferred constructor to use. Takes the properties from content reader that it needs.
 * @param reader ContentReader
 */
public BinaryProperty(ContentReader reader)
{
    super();
    this.mimeType = reader.getMimetype();
    this.encoding = reader.getEncoding();
    this.length = reader.getSize();
    this.locale = reader.getLocale();
}
 
开发者ID:Alfresco,项目名称:alfresco-remote-api,代码行数:13,代码来源:BinaryProperty.java

示例9: run

import org.alfresco.service.cmr.repository.ContentReader; //导入方法依赖的package包/类
String run(String sourceExtension, String targetExtension, String use)
{
    String debug;
    
    String targetMimetype = getMimetype(targetExtension, false);
    String sourceMimetype = getMimetype(sourceExtension, true);
    URL sourceURL = loadQuickTestFile(sourceExtension);
    if (sourceURL == null)
    {
        throw new IllegalArgumentException("There is no test file with a "+sourceExtension+" extension.");
    }
    
    // This URL may point to a file on the filesystem or to an entry in a jar.
    // To use the transform method below, we need the content to be accessible from a ContentReader.
    // This is possible for a File but not a (non-file) URL.
    //
    // Therefore, we'll always copy the URL content to a temporary local file.
    final File sourceFile = TempFileProvider.createTempFile(TransformerDebug.class.getSimpleName() + "-tmp-", "");
    
    try   { FileUtils.copyURLToFile(sourceURL, sourceFile); }
    catch (IOException shouldNeverHappen)
    {
        // The sourceURL should always be readable as we're reading data that Alfresco is distributing.
        // But just in case...
        throw new IllegalArgumentException("Cannot read content of test file with a " +
                                           sourceExtension + " extension.", shouldNeverHappen);
    }
    
    ContentReader reader = new FileContentReader(sourceFile);
    reader.setMimetype(sourceMimetype);
    File tempFile = TempFileProvider.createTempFile(
            "TestTransform_" + sourceExtension + "_", "." + targetExtension);
    ContentWriter writer = new FileContentWriter(tempFile);
    writer.setMimetype(targetMimetype);

    long sourceSize = reader.getSize();
    TransformationOptions options = new TransformationOptions();
    options.setUse(use);

    debug = isTransformable(sourceMimetype, sourceSize, targetMimetype, options);
    if (debug == null)
    {
        StringBuilder sb = new StringBuilder();
        try
        {
            setStringBuilder(sb);
            transform(reader, writer, options);
        }
        catch (AlfrescoRuntimeException e)
        {
            sb.append(e.getMessage());
        }
        finally
        {
            setStringBuilder(null);
        }
        debug = sb.toString();
    }
    return debug;
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:61,代码来源:TransformerDebug.java

示例10: cacheAndRead

import org.alfresco.service.cmr.repository.ContentReader; //导入方法依赖的package包/类
private ContentReader cacheAndRead(String url)
{
    WriteLock writeLock = readWriteLock(url).writeLock();
    writeLock.lock();
    try
    {
        for (int i = 0; i < maxCacheTries; i++)
        {
            ContentReader backingStoreReader = backingStore.getReader(url);
            long contentSize = backingStoreReader.getSize();
            
            if (!quota.beforeWritingCacheFile(contentSize))
            {
                return backingStoreReader;
            }
            
            ContentReader reader = attemptCacheAndRead(url);
            
            if (reader != null)
            {
                boolean keepCacheFile = quota.afterWritingCacheFile(contentSize);
                if (keepCacheFile)
                {
                    return reader;
                }
                else
                {
                    // Quota strategy has requested cache file not to be kept.
                    cache.deleteFile(url);
                    cache.remove(url);
                    return backingStore.getReader(url);
                }
            }
        }
        // Have tried multiple times to cache the item and read it back from the cache
        // but there is a recurring problem - give up and return the item from the backing store.
        if (log.isWarnEnabled())
        {
            log.warn("Attempted " + maxCacheTries + " times to cache content item and failed - "
                        + "returning reader from backing store instead [" + 
                        "backingStore=" + backingStore + 
                        ", url=" + url +
                        "]");
        }
        return backingStore.getReader(url);
    }
    finally
    {
        writeLock.unlock();
    }
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:52,代码来源:CachingContentStore.java

示例11: doTest

import org.alfresco.service.cmr.repository.ContentReader; //导入方法依赖的package包/类
private static void doTest(ApplicationContext ctx, String baseUrl, String contentUrl) throws Exception
{
    ServiceRegistry serviceRegistry = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY);
    TransactionService transactionService = serviceRegistry.getTransactionService();
    AuthenticationService authenticationService = serviceRegistry.getAuthenticationService();
    // Construct the store
    HttpAlfrescoStore store = new HttpAlfrescoStore();
    store.setTransactionService(transactionService);
    store.setAuthenticationService(authenticationService);
    store.setBaseHttpUrl(baseUrl);
    
    // Now test
    System.out.println(
            "   Retrieving reader for URL " + contentUrl);
    ContentReader reader = store.getReader(contentUrl);
    System.out.println(
            "   Retrieved reader for URL " + contentUrl);
    // Check if the content exists
    boolean exists = reader.exists();
    if (!exists)
    {
        System.out.println(
                "   Content doesn't exist: " + contentUrl);
        return;
    }
    else
    {
        System.out.println(
                "   Content exists: " + contentUrl);
    }
    // Get the content data
    ContentData contentData = reader.getContentData();
    System.out.println(
            "   Retrieved content data: " + contentData);
    
    // Now get the content
    ByteBuffer buffer = ByteBuffer.allocate((int)reader.getSize());
    FileChannel channel = reader.getFileChannel();
    try
    {
        int count = channel.read(buffer);
        if (count != reader.getSize())
        {
            System.err.println("The number of bytes read was " + count + " but expected " + reader.getSize());
            return;
        }
    }
    finally
    {
        channel.close();
    }
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:53,代码来源:HttpAlfrescoStore.java

示例12: transform

import org.alfresco.service.cmr.repository.ContentReader; //导入方法依赖的package包/类
/**
 * @see org.alfresco.repo.content.transform.ContentTransformerRegistry
 * @see org.alfresco.repo.content.transform.ContentTransformer
 */
public void transform(ContentReader reader, ContentWriter writer, TransformationOptions options) 
    throws NoTransformerException, ContentIOException
{
    // check that source and target mimetypes are available
    if (reader == null)
    {
        throw new AlfrescoRuntimeException("The content reader must be set");
    }
    String sourceMimetype = reader.getMimetype();
    if (sourceMimetype == null)
    {
        throw new AlfrescoRuntimeException("The content reader mimetype must be set: " + reader);
    }
    String targetMimetype = writer.getMimetype();
    if (targetMimetype == null)
    {
        throw new AlfrescoRuntimeException("The content writer mimetype must be set: " + writer);
    }

    long sourceSize = reader.getSize();
    try
    {
        // look for a transformer
        transformerDebug.pushAvailable(reader.getContentUrl(), sourceMimetype, targetMimetype, options);
        List<ContentTransformer> transformers = getActiveTransformers(sourceMimetype, sourceSize, targetMimetype, options);
        transformerDebug.availableTransformers(transformers, sourceSize, options, "ContentService.transform(...)");
        
        int count = transformers.size(); 
        if (count == 0)
        {
            throw new NoTransformerException(sourceMimetype, targetMimetype);
        }
        
        if (count == 1 || !transformerFailover)
        {
            ContentTransformer transformer = transformers.size() == 0 ? null : transformers.get(0);
            transformer.transform(reader, writer, options);
        }
        else
        {
            failoverTransformers(reader, writer, options, targetMimetype, transformers);
        }
    }
    finally
    {
        if (transformerDebug.isEnabled())
        {
            transformerDebug.popAvailable();
            debugTransformations(sourceMimetype, targetMimetype, sourceSize, options);
        }
    }
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:57,代码来源:ContentServiceImpl.java


注:本文中的org.alfresco.service.cmr.repository.ContentReader.getSize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。