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


Java ContentReader.getContentInputStream方法代码示例

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


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

示例1: getLogInputStream

import org.alfresco.service.cmr.repository.ContentReader; //导入方法依赖的package包/类
public InputStream getLogInputStream(String transferId)
        throws TransferException
{
    NodeRef transferRecord = getTransferRecord(transferId);
    
    ContentReader reader = contentService.getReader(transferRecord, ContentModel.PROP_CONTENT); 
    
    if(reader != null)
    {
        return reader.getContentInputStream();
    }
    else
    {
        return null;
    }
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:17,代码来源:RepoTransferProgressMonitorImpl.java

示例2: saveContentInUtf8File

import org.alfresco.service.cmr.repository.ContentReader; //导入方法依赖的package包/类
/**
 * Populates a file with the content in the reader, but also converts the encoding to UTF-8.
 */
private void saveContentInUtf8File(ContentReader reader, File file)
{
    String encoding = reader.getEncoding();
    try
    {
        Reader in = new InputStreamReader(reader.getContentInputStream(), encoding);
        Writer out = new OutputStreamWriter(new BufferedOutputStream(new FileOutputStream(file)), "UTF-8");

        FileCopyUtils.copy(in, out);  // both streams are closed
    }
    catch (IOException e)
    {
        throw new ContentIOException("Failed to copy content to file and convert "+encoding+" to UTF-8: \n" +
                "   file: " + file,
                e);
    }
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:21,代码来源:OOoContentTransformerHelper.java

示例3: putContent

import org.alfresco.service.cmr.repository.ContentReader; //导入方法依赖的package包/类
/**
 * @see ContentReader#getContentInputStream()
 * @see #putContent(InputStream) 
 */
public void putContent(ContentReader reader) throws ContentIOException
{
    try
    {
        // get the stream to read from
        InputStream is = reader.getContentInputStream();
        // put the content
        putContent(is);
    }
    catch (Throwable e)
    {
        throw new ContentIOException("Failed to copy reader content to writer: \n" +
                "   writer: " + this + "\n" +
                "   source reader: " + reader,
                e);
    }
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:22,代码来源:AbstractContentWriter.java

示例4: doGuessEncoding

import org.alfresco.service.cmr.repository.ContentReader; //导入方法依赖的package包/类
private void doGuessEncoding()
{
    ContentCharsetFinder charsetFinder = mimetypeService.getContentCharsetFinder();
    
    ContentReader reader = getReader();
    InputStream is = reader.getContentInputStream();
    Charset charset = charsetFinder.getCharset(is, getMimetype());
    try
    {
        is.close();
    }
    catch(IOException e)
    {}
    
    setEncoding(charset.name());
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:17,代码来源:AbstractContentWriter.java

示例5: getReader

import org.alfresco.service.cmr.repository.ContentReader; //导入方法依赖的package包/类
public Reader getReader()
{
    ContentService contentService = services.getContentService();
    ContentReader reader = contentService.getReader(nodeRef, property);
    
    if (reader != null && reader.exists())
    {
        try
        {
            return (contentData.getEncoding() == null) ? new InputStreamReader(reader.getContentInputStream()) : new InputStreamReader(reader.getContentInputStream(), contentData.getEncoding());
        }
        catch (IOException e)
        {
            // NOTE: fall-through
        }
    }
    return null;
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:19,代码来源:ScriptNode.java

示例6: getRelativeResource

import org.alfresco.service.cmr.repository.ContentReader; //导入方法依赖的package包/类
@Override
protected InputStream getRelativeResource(String name)
{
    InputStream stream = null;
    NodeRef parentRef = nodeService.getPrimaryParent(nodeRef).getParentRef();
    NodeRef child = nodeService.getChildByName(parentRef, ContentModel.ASSOC_CONTAINS, name);
    if (child != null)
    {
        ContentReader contentReader = contentService.getReader(child, ContentModel.PROP_CONTENT);
        if (contentReader.exists())
        {
            stream = contentReader.getContentInputStream();
        }
    }
    return stream;
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:17,代码来源:ClassPathRepoTemplateLoader.java

示例7: guessMimetype

import org.alfresco.service.cmr.repository.ContentReader; //导入方法依赖的package包/类
/**
 * Uses Tika to try to identify the mimetype of the file, falling back on
 * {@link #guessMimetype(String)} for an extension based one if Tika can't
 * help.
 */
public String guessMimetype(String filename, ContentReader reader)
{
    // ALF-10813: MimetypeMap.guessMimetype consumes 30% of file upload time
    // Let's only 'guess' if we need to
    if (reader != null && reader.getMimetype() != null && !reader.getMimetype().equals(MimetypeMap.MIMETYPE_BINARY))
    {
        // It was set to something other than the default.
        // Possibly someone used this method before (like the UI does) or
        // they just
        // know what their files are.
        return reader.getMimetype();
    }
    InputStream input = (reader != null ? reader.getContentInputStream() : null);
    return guessMimetype(filename, input);
}
 
开发者ID:Alfresco,项目名称:alfresco-data-model,代码行数:21,代码来源:MimetypeMap.java

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

示例9: testReadAndWriteStreamByPush

import org.alfresco.service.cmr.repository.ContentReader; //导入方法依赖的package包/类
@Test
public void testReadAndWriteStreamByPush() throws Exception
{
    ContentWriter writer = getWriter();

    String content = "Some Random Content";
    // get the content output stream
    OutputStream os = writer.getContentOutputStream();
    os.write(content.getBytes());
    assertFalse("Stream has not been closed", writer.isClosed());
    // close the stream and check again
    os.close();
    assertTrue("Stream close not detected", writer.isClosed());
    
    // pull the content from a stream
    ContentReader reader = writer.getReader();
    InputStream is = reader.getContentInputStream();
    byte[] buffer = new byte[100];
    int count = is.read(buffer);
    assertEquals("No content read", content.length(), count);
    is.close();
    String check = new String(buffer, 0, count);
    
    assertEquals("Write out of and read into files failed", content, check);
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:26,代码来源:AbstractWritableContentStoreTest.java

示例10: createM2Model

import org.alfresco.service.cmr.repository.ContentReader; //导入方法依赖的package包/类
/**
 * Create a M2Model from a dictionary model node
 * 
 * @param nodeRef   the dictionary model node reference
 * @return          the M2Model
 */
public M2Model createM2Model(NodeRef nodeRef)
{
    M2Model model = null;
    ContentReader contentReader = this.contentService.getReader(nodeRef, ContentModel.PROP_CONTENT);
    if (contentReader != null)
    {
        if (contentReader instanceof EmptyContentReader)
        {
            // belts-and-braces
            logger.error("Failed to create model (due to EmptyContentReader): "+nodeRef);
        }
        else
        {
            InputStream is = null;
            try
            {
                is = contentReader.getContentInputStream();
                model = M2Model.createModel(is);
            }
            finally
            {
                if (is != null)
                {
                    try
                    {
                        is.close();
                    }
                    catch (IOException e)
                    {
                        logger.error("Failed to close input stream for " + nodeRef);
                    }
                }
            }
        }
    }
    // TODO should we inactivate the model node and put the error somewhere??
    return model;
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:45,代码来源:DictionaryRepositoryBootstrap.java

示例11: getM2Model

import org.alfresco.service.cmr.repository.ContentReader; //导入方法依赖的package包/类
private M2Model getM2Model(final NodeRef modelNodeRef)
{
    ContentReader reader = contentService.getReader(modelNodeRef, ContentModel.PROP_CONTENT);
    if (reader == null)
    {
        return null;
    }
    InputStream in = reader.getContentInputStream();
    try
    {
        return M2Model.createModel(in);
    }
    finally
    {
        if (in != null)
        {
            try
            {
                in.close();
            }
            catch (IOException e)
            {
                logger.error("Failed to close input stream for " + modelNodeRef);
            }
        }
    }
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:28,代码来源:CustomModelServiceImpl.java

示例12: transformInternal

import org.alfresco.service.cmr.repository.ContentReader; //导入方法依赖的package包/类
@Override
protected void transformInternal(ContentReader reader, ContentWriter writer, TransformationOptions options) throws Exception
{
    InputStream contentInputStream = null;
    try{
        contentInputStream = reader.getContentInputStream();
        MimeMessage mimeMessage = new MimeMessage(Session.getDefaultInstance(new Properties()), contentInputStream);

        final StringBuilder sb = new StringBuilder();
        Object content = mimeMessage.getContent();
        if (content instanceof Multipart)
        {
            processMultiPart((Multipart) content,sb);
        }
        else
        {
            sb.append(content.toString());
        }
        writer.putContent(sb.toString());
    }
    finally
    {
        if (contentInputStream != null)
        {
            try
            {
            contentInputStream.close();
            }
            catch ( IOException e)
            {
                //stop exception propagation
            }
        }
    }
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:36,代码来源:EMLTransformer.java

示例13: getInputStream

import org.alfresco.service.cmr.repository.ContentReader; //导入方法依赖的package包/类
/**
 * There seems to be some sort of issue with some downstream
 *  3rd party libraries, and input streams that come from
 *  a {@link ContentReader}. This happens most often with
 *  JPEG and Tiff files.
 * For these cases, buffer out to a local file if not
 *  already there
 */
protected InputStream getInputStream(ContentReader reader) throws IOException
{
   // Prefer the File if available, it's generally quicker
   if(reader instanceof FileContentReader) 
   {
      return TikaInputStream.get( ((FileContentReader)reader).getFile() );
   }
   
   // Grab the InputStream for the Content
   InputStream input = reader.getContentInputStream();
   
   // Images currently always require a file
   if(MimetypeMap.MIMETYPE_IMAGE_JPEG.equals(reader.getMimetype()) ||
      MimetypeMap.MIMETYPE_IMAGE_TIFF.equals(reader.getMimetype())) 
   {
      TemporaryResources tmp = new TemporaryResources();
      TikaInputStream stream = TikaInputStream.get(input, tmp);
      stream.getFile(); // Have it turned into File backed
      return stream;
   }
   else
   {
      // The regular Content InputStream should be fine
      return input; 
   }
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:35,代码来源:TikaPoweredMetadataExtracter.java

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

示例15: openContentStream

import org.alfresco.service.cmr.repository.ContentReader; //导入方法依赖的package包/类
@Override
public InputStream openContentStream(NodeRef nodeRef) throws ActualEnvironmentException
{
    ContentReader contentReader = apiFacet.getContentService().getReader(nodeRef,
                                                                         ContentModel.PROP_CONTENT);
    return contentReader.getContentInputStream();
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:8,代码来源:AlfrescoEnviroment.java


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