Package org.apache.chemistry.opencmis.commons.impl.dataobjects

Examples of org.apache.chemistry.opencmis.commons.impl.dataobjects.ContentStreamImpl


    /**
     * Extract the content stream.
     */
    private void parseAtomContent(XMLStreamReader parser) throws Exception {
        atomContentStream = new ContentStreamImpl();

        // read attributes
        String type = "text";
        for (int i = 0; i < parser.getAttributeCount(); i++) {
            QName attrName = parser.getAttributeName(i);
View Full Code Here


    /**
     * Extract the content stream.
     */
    private void parseCmisContent(XMLStreamReader parser) throws Exception {
        cmisContentStream = new ContentStreamImpl();

        next(parser);

        // walk through all tags in content
        while (true) {
View Full Code Here

            contentBytes = "some content".getBytes("UTF-8");
        } catch (Exception e) {
            contentBytes = "some content".getBytes();
        }

        return new ContentStreamImpl("content.txt", BigInteger.valueOf(contentBytes.length), "text/plain",
                new ByteArrayInputStream(contentBytes));
    }
View Full Code Here

        StoredObject so = null;

        // check if content stream parameters are set and if not set some defaults
        if (null != contentStream && (contentStream.getFileName() == null || contentStream.getFileName().length() == 0 ||
            contentStream.getMimeType() == null || contentStream.getMimeType().length() == 0)) {
            ContentStreamImpl cs = new ContentStreamImpl();
            cs.setStream(contentStream.getStream());
            if (contentStream.getFileName() == null || contentStream.getFileName().length() == 0) {
                cs.setFileName(name);
            } else {
                cs.setFileName(contentStream.getFileName());
            }
            cs.setLength(contentStream.getBigLength());
            if (contentStream.getMimeType() == null || contentStream.getMimeType().length() == 0) {
                cs.setMimeType("application/octet-stream");
            } else {
                cs.setMimeType(contentStream.getMimeType());
            }
            cs.setExtensions(contentStream.getExtensions());
            contentStream = cs;
        }

        // Now we are sure to have document type definition:
        if (((DocumentTypeDefinition) typeDef).isVersionable()) {
View Full Code Here

        return convert(allowableActions.getAllowableActions());
    }

    public ContentStream getContentStream(String repositoryId, String objectId, String streamId, BigInteger offset,
            BigInteger length, ExtensionsData extension) {
        ContentStreamImpl result = new ContentStreamImpl();

        // find the link
        String link = null;
        if (streamId != null) {
            // use the alternate link per spec
            link = loadLink(repositoryId, objectId, Constants.REL_ALTERNATE, streamId);
            if (link != null) {
                streamId = null; // we have a full URL now
            }
        }
        if (link == null) {
            link = loadLink(repositoryId, objectId, AtomPubParser.LINK_REL_CONTENT, null);
        }

        if (link == null) {
            throw new CmisConstraintException("No content stream");
        }

        UrlBuilder url = new UrlBuilder(link);
        // using the content URL and adding a streamId param
        // is not spec-compliant
        url.addParameter(Constants.PARAM_STREAM_ID, streamId);

        // get the content
        HttpUtils.Response resp = HttpUtils.invokeGET(url, getSession(), offset, length);

        // check response code
        if ((resp.getResponseCode() != 200) && (resp.getResponseCode() != 206)) {
            throw convertStatusCode(resp.getResponseCode(), resp.getResponseMessage(), resp.getErrorContent(), null);
        }

        result.setFileName(null);
        result.setLength(resp.getContentLength());
        result.setMimeType(resp.getContentTypeHeader());
        result.setStream(resp.getStream());

        return result;
    }
View Full Code Here

            fTimeLoggerDelete.stop();
        }
    }

    private ContentStream createContent() {
        ContentStreamImpl content = new ContentStreamImpl();
        content.setFileName("data.txt");
        content.setMimeType("text/plain");
        int len = fContentSizeInK * 1024; // size of document in K
       
        LoreIpsum ipsum = new LoreIpsum();
        String text = ipsum.generateParagraphsPlainText(len, 80, true);
        content.setStream(new ByteArrayInputStream(text.getBytes()));
        return content;
    }
View Full Code Here

        content.setStream(new ByteArrayInputStream(text.getBytes()));
        return content;
    }

    private ContentStream createContentStaticText() {
        ContentStreamImpl content = new ContentStreamImpl();
        content.setFileName("data.txt");
        content.setMimeType("text/plain");
        int len = fContentSizeInK * 1024; // size of document in K
        byte[] b = { 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x0c, 0x0a,
                0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x0c, 0x0a }; // 32
        // Bytes
        ByteArrayOutputStream ba = new ByteArrayOutputStream(len);
        try {
            for (int j = 0; j < fContentSizeInK; j++) {
                // write 1K of data
                for (int i = 0; i < 32; i++) {
                    ba.write(b);
                }
            }
        } catch (IOException e) {
            throw new RuntimeException("Failed to fill content stream with data", e);
        }
        content.setStream(new ByteArrayInputStream(ba.toByteArray()));
        return content;
    }
View Full Code Here

    }

    // content stream

    public ContentStream createContentStream(String filename, long length, String mimetype, InputStream stream) {
        return new ContentStreamImpl(filename, BigInteger.valueOf(length), mimetype, stream);
    }
View Full Code Here

        StoredObject so = null;

        // check if content stream parameters are set and if not set some defaults
        if (null != contentStream && (contentStream.getFileName() == null || contentStream.getFileName().length() == 0 ||
            contentStream.getMimeType() == null || contentStream.getMimeType().length() == 0)) {
            ContentStreamImpl cs = new ContentStreamImpl();
            cs.setStream(contentStream.getStream());
            if (contentStream.getFileName() == null || contentStream.getFileName().length() == 0) {
                cs.setFileName(name);
            } else {
                cs.setFileName(contentStream.getFileName());
            }
            cs.setLength(contentStream.getBigLength());
            if (contentStream.getMimeType() == null || contentStream.getMimeType().length() == 0) {
                cs.setMimeType("application/octet-stream");
            } else {
                cs.setMimeType(contentStream.getMimeType());
            }
            cs.setExtensions(contentStream.getExtensions());
            contentStream = cs;
        }

        // Now we are sure to have document type definition:
        if (((DocumentTypeDefinition) typeDef).isVersionable()) {
View Full Code Here

            fTimeLoggerDelete.stop();
        }
    }

    public ContentStream createContentLoremIpsumHtml() {
        ContentStreamImpl content = new ContentStreamImpl();
        content.setFileName("data.html");
        content.setMimeType("text/html");
        int len = fContentSizeInK * 1024; // size of document in K
       
        LoremIpsum ipsum = new LoremIpsum();
        String text = ipsum.generateParagraphsFullHtml(len, true);
        content.setStream(new ByteArrayInputStream(text.getBytes()));
        return content;
    }
View Full Code Here

TOP

Related Classes of org.apache.chemistry.opencmis.commons.impl.dataobjects.ContentStreamImpl

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.