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

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


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

    public ContentStream createContentLoremIpsumText() {
        ContentStreamImpl content = new ContentStreamImpl();
        content.setFileName("data.txt");
        content.setMimeType("text/plain");
        int len = fContentSizeInK * 1024; // size of document in K
       
        LoremIpsum ipsum = new LoremIpsum();
        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;
    }

    public 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

    public ContentStream createContentFractalimageJpeg() {
        if (null == fractalGenerator)
            fractalGenerator = new FractalGenerator();

        ContentStreamImpl content = null;

        try {
            ByteArrayOutputStream bos = fractalGenerator.generateFractal();
            content = new ContentStreamImpl();
            content.setFileName("image.jpg");
            content.setMimeType("image/jpeg");
            content.setStream(new ByteArrayInputStream(bos.toByteArray()));
            bos.close();           
        } catch (IOException e) {
            System.err.println("Error when generating fractal image: " + e);
            e.printStackTrace();
        }
View Full Code Here

        return JSONConverter.convertRenditions(json);
    }

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

        // build URL
        UrlBuilder url = getObjectUrl(repositoryId, objectId, Constants.SELECTOR_CONTENT);
        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

        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

    public static ContentStream convert(CmisContentStreamType contentStream) {
        if (contentStream == null) {
            return null;
        }

        ContentStreamImpl result = new ContentStreamImpl();

        result.setFileName(contentStream.getFilename());
        result.setLength(contentStream.getLength());
        result.setMimeType(contentStream.getMimeType());
        if (contentStream.getStream() != null) {
            try {
                try {
                    if (contentStream.getStream() instanceof StreamingDataHandler) {
                        result.setStream(((StreamingDataHandler) contentStream.getStream()).readOnce());
                    } else {
                        result.setStream(contentStream.getStream().getInputStream());
                    }
                } catch (NoClassDefFoundError cnfe) {
                    // Fallback in case the JAX-WS RI is not available (optional
                    // resolution in OSGi)
                    result.setStream(contentStream.getStream().getInputStream());
                }
            } catch (IOException e) {
                throw new CmisRuntimeException("Could not get the stream: " + e.getMessage(), e);
            }
        }
View Full Code Here

        return new AccessControlListImpl(aces);
    }

    public static ContentStream createContentStream(HttpServletRequest request) {
        ContentStreamImpl result = null;

        if (request instanceof POSTHttpServletRequestWrapper) {
            POSTHttpServletRequestWrapper post = (POSTHttpServletRequestWrapper) request;
            if (post.getStream() != null) {
                result = new ContentStreamImpl(post.getFilename(), post.getSize(), post.getContentType(),
                        post.getStream());
            }
        }

        return result;
View Full Code Here

                removeACEs, extension);
        return id;
    }

    private ContentStream createContent() {
        ContentStreamImpl content = new ContentStreamImpl();
        content.setFileName("data.txt");
        content.setMimeType("text/plain");
        int len = 32 * 1024;
        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 i = 0; i < 1024; i++) {
                ba.write(b);
            }
        } catch (IOException e) {
            throw new RuntimeException("Failed to fill content stream with data", e);
        }
        content.setStream(new ByteArrayInputStream(ba.toByteArray()));
        content.setLength(BigInteger.valueOf(len));
        return content;
    }
View Full Code Here

        byte[] contentBytes = null;
        Document result = null;
        try {
            contentBytes = content.getBytes("UTF-8");
            ContentStream contentStream = new ContentStreamImpl(name, BigInteger.valueOf(contentBytes.length),
                    "text/plain", new ByteArrayInputStream(contentBytes));

            // create the document
            result = parent.createDocument(properties, contentStream, versioningState, null, null, null,
                    SELECT_ALL_NO_CACHE_OC);
View Full Code Here

        try {
            contentBytes = content.getBytes("UTF-8");
        } catch (UnsupportedEncodingException e) {
            contentBytes = content.getBytes();
        }
        ContentStream contentStream = new ContentStreamImpl(doc.getName(), BigInteger.valueOf(contentBytes.length),
                "text/plain", new ByteArrayInputStream(contentBytes));

        ObjectId newVersionId = pwc.checkIn(true, null, contentStream, "test version " + version);
        Document newVersion = (Document) session.getObject(newVersionId, SELECT_ALL_NO_CACHE_OC);
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.