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


Java ContentReader.getFileChannel方法代码示例

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


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

示例1: testRandomAccessRead

import org.alfresco.service.cmr.repository.ContentReader; //导入方法依赖的package包/类
/**
 * Tests random access reading
 * <p>
 * Only executes if the reader implements {@link RandomAccessContent}.
 */
@Test
public void testRandomAccessRead() throws Exception
{
    ContentStore store = getStore();
    String contentUrl = getExistingContentUrl();
    if (contentUrl == null)
    {
        logger.warn("Store test testRandomAccessRead not possible on " + store.getClass().getName());
        return;
    }
    // Get the reader
    ContentReader reader = store.getReader(contentUrl);
    assertNotNull("Reader should never be null", reader);

    FileChannel fileChannel = reader.getFileChannel();
    assertNotNull("No channel given", fileChannel);
    
    // check that no other content access is allowed
    try
    {
        reader.getReadableChannel();
        fail("Second channel access allowed");
    }
    catch (RuntimeException e)
    {
        // expected
    }
    fileChannel.close();
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:35,代码来源:AbstractReadOnlyContentStoreTest.java

示例2: testRandomAccessRead

import org.alfresco.service.cmr.repository.ContentReader; //导入方法依赖的package包/类
/**
 * Tests random access reading
 * <p>
 * Only executes if the reader implements {@link RandomAccessContent}.
 */
@Test
public void testRandomAccessRead() throws Exception
{
    ContentWriter writer = getWriter();
    // put some content
    String content = "ABC";
    byte[] bytes = content.getBytes();
    writer.putContent(content);
    ContentReader reader = writer.getReader();
    
    FileChannel fileChannel = reader.getFileChannel();
    assertNotNull("No channel given", fileChannel);
    
    // check that no other content access is allowed
    try
    {
        reader.getReadableChannel();
        fail("Second channel access allowed");
    }
    catch (RuntimeException e)
    {
        // expected
    }
    
    // read the content
    ByteBuffer buffer = ByteBuffer.allocate(bytes.length);
    int count = fileChannel.read(buffer);
    assertEquals("Incorrect number of bytes read", bytes.length, count);
    // transfer back to array
    buffer.rewind();
    buffer.get(bytes);
    String checkContent = new String(bytes);
    assertEquals("Content read failure", content, checkContent);
    fileChannel.close();
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:41,代码来源:AbstractWritableContentStoreTest.java

示例3: 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


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