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


Java ContentReader.getReader方法代码示例

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


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

示例1: testGetContentString_01

import org.alfresco.service.cmr.repository.ContentReader; //导入方法依赖的package包/类
public void testGetContentString_01()
{
    // To URL
    String url = SpoofedTextContentReader.createContentUrl(Locale.ENGLISH, 12345L, 56L, "harry");
    // To Reader
    ContentReader reader = new SpoofedTextContentReader(url);
    String readerText = reader.getContentString();
    assertEquals("harry have voice the from countered growth invited      ", readerText);
    // Cannot repeat
    try
    {
        reader.getContentString();
        fail("Should not be able to reread content.");
    }
    catch (ContentIOException e)
    {
        // Expected
    }
    // Get a new Reader
    reader = reader.getReader();
    // Get exactly the same text
    assertEquals(readerText, reader.getContentString());
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:24,代码来源:SpoofedTextContentReaderTest.java

示例2: testGetContentBinary_01

import org.alfresco.service.cmr.repository.ContentReader; //导入方法依赖的package包/类
public void testGetContentBinary_01() throws Exception
{
    // To URL
    String url = SpoofedTextContentReader.createContentUrl(Locale.ENGLISH, 12345L, 56L, "harry");
    // To Reader
    ContentReader reader = new SpoofedTextContentReader(url);
    InputStream is = reader.getContentInputStream();
    try
    {
        byte[] bytes = FileCopyUtils.copyToByteArray(is);
        assertEquals(56L, bytes.length);
    }
    finally
    {
        is.close();
    }
    // Compare readers
    ContentReader copyOne = reader.getReader();
    ContentReader copyTwo = reader.getReader();
    // Get exactly the same binaries
    assertTrue(AbstractContentReader.compareContentReaders(copyOne, copyTwo));
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:23,代码来源:SpoofedTextContentReaderTest.java

示例3: testDITAFileWithDoctype

import org.alfresco.service.cmr.repository.ContentReader; //导入方法依赖的package包/类
public void testDITAFileWithDoctype() throws Exception
{
    // Load the file as-is, with it's doctype
    ContentReader reader = getReader(FILE_DITA_FILE);
    assertTrue(reader.exists());
    
    // Check we have the doctype
    String contents = reader.getContentString();
    assertTrue("DOCTYPE should be present but wasn't", contents.indexOf("<!DOCTYPE") > -1);
    
    // Reset ready for the extraction test
    reader = reader.getReader();
    
    // Now test extraction
    doTestDITAFile(reader);
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:17,代码来源:XmlMetadataExtracterTest.java

示例4: testGetReader

import org.alfresco.service.cmr.repository.ContentReader; //导入方法依赖的package包/类
/**
 * Checks that the various methods of obtaining a reader are supported.
 */
@Test
public synchronized void testGetReader() throws Exception
{
    ContentStore store = getStore();
    ContentWriter writer = store.getWriter(ContentStore.NEW_CONTENT_CONTEXT);
    String contentUrl = writer.getContentUrl();
    
    // Check that a reader is available from the store
    ContentReader readerFromStoreBeforeWrite = store.getReader(contentUrl);
    assertNotNull("A reader must always be available from the store", readerFromStoreBeforeWrite);
    
    // check that a reader is available from the writer
    ContentReader readerFromWriterBeforeWrite = writer.getReader();
    assertNotNull("A reader must always be available from the writer", readerFromWriterBeforeWrite);
    
    String content = "Content for testGetReader";
    
    // write some content
    long before = System.currentTimeMillis();
    this.wait(1000L);
    writer.setMimetype("text/plain");
    writer.setEncoding("UTF-8");
    writer.setLocale(Locale.CHINESE);
    writer.putContent(content);
    this.wait(1000L);
    long after = System.currentTimeMillis();
    
    // get a reader from the store
    ContentReader readerFromStore = store.getReader(contentUrl);
    assertNotNull(readerFromStore);
    assertTrue(readerFromStore.exists());
    // Store-provided readers don't have context other than URLs
    // assertEquals(writer.getContentData(), readerFromStore.getContentData());
    assertEquals(content, readerFromStore.getContentString());
    
    // get a reader from the writer
    ContentReader readerFromWriter = writer.getReader();
    assertNotNull(readerFromWriter);
    assertTrue(readerFromWriter.exists());
    assertEquals(writer.getContentData(), readerFromWriter.getContentData());
    assertEquals(content, readerFromWriter.getContentString());
    
    // get another reader from the reader
    ContentReader readerFromReader = readerFromWriter.getReader();
    assertNotNull(readerFromReader);
    assertTrue(readerFromReader.exists());
    assertEquals(writer.getContentData(), readerFromReader.getContentData());
    assertEquals(content, readerFromReader.getContentString());
    
    // check that the length is correct
    int length = content.getBytes(writer.getEncoding()).length;
    assertEquals("Reader content length is incorrect", length, readerFromWriter.getSize());

    // check that the last modified time is correct
    long modifiedTimeCheck = readerFromWriter.getLastModified();

    // On some versionms of Linux (e.g. Centos) this test won't work as the 
    // modified time accuracy is only to the second.
    long beforeSeconds = before/1000L;
    long afterSeconds = after/1000L;
    long modifiedTimeCheckSeconds = modifiedTimeCheck/1000L;

    assertTrue("Reader last modified is incorrect", beforeSeconds <= modifiedTimeCheckSeconds);
    assertTrue("Reader last modified is incorrect", modifiedTimeCheckSeconds <= afterSeconds);
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:69,代码来源:AbstractWritableContentStoreTest.java


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