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

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


            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
        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


        } catch (FileNotFoundException e) {
            throw new CmisObjectNotFoundException(e.getMessage(), e);
        }

        // compile data
        ContentStreamImpl result = new ContentStreamImpl();
        result.setFileName(file.getName());
        result.setLength(BigInteger.valueOf(file.length()));
        result.setMimeType(MIMETypes.getMIMEType(file));
        result.setStream(stream);

        return result;
    }
View Full Code Here

 
    // content
    String contentString = "CMIS Testdata "+name;
    byte[] content = contentString.getBytes();
    InputStream stream = new ByteArrayInputStream(content);
    ContentStream contentStream = new ContentStreamImpl(name, new BigInteger(content), "text/plain", stream);
 
    // create a major version
    folder.createDocument(contentProperties, contentStream, null);
    stream.close();
  }
View Full Code Here

      objectId = result.getPropertyById("cmis:objectId").getFirstValue().toString();
    }

    byte[] newContentByteArray = newContent.getBytes();
    InputStream stream = new ByteArrayInputStream(newContentByteArray);
    ContentStream contentStream = new ContentStreamImpl(name, new BigInteger(newContentByteArray), "text/plain", stream);
    Document documentToUpdate = (Document) session.getObject(objectId);
    documentToUpdate.setContentStream(contentStream, true);
  }
View Full Code Here

 
    // content
    String contentString = "CMIS Testdata "+name;
    byte[] content = contentString.getBytes();
    InputStream stream = new ByteArrayInputStream(content);
    ContentStream contentStream = new ContentStreamImpl(name, new BigInteger(content), "text/plain", stream);
 
    // create a major version
    folder.createDocument(contentProperties, contentStream, null);
    stream.close();
  }
View Full Code Here

      objectId = result.getPropertyById("cmis:objectId").getFirstValue().toString();
    }
   
    byte[] newContentByteArray = newContent.getBytes();
    InputStream stream = new ByteArrayInputStream(newContentByteArray);
    ContentStream contentStream = new ContentStreamImpl(name, new BigInteger(newContentByteArray), "text/plain", stream);
    Document documentToUpdate = (Document) session.getObject(objectId);
    documentToUpdate.setContentStream(contentStream, true);
  }
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

     * .lang.String, java.lang.String, java.lang.String, java.math.BigInteger,
     * java.math.BigInteger, org.apache.opencmis.client.provider.ExtensionsData)
     */
    public ContentStream getContentStream(String repositoryId, String objectId, String streamId, BigInteger offset,
            BigInteger length, ExtensionsData extension) {
        ContentStreamImpl result = new ContentStreamImpl();

        // find the link
        String link = loadLink(repositoryId, objectId, AtomPubParser.LINK_REL_CONTENT, null);

        if (link == null) {
            throwLinkException(repositoryId, objectId, AtomPubParser.LINK_REL_CONTENT, null);
        }

        UrlBuilder url = new UrlBuilder(link);
        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

     * @see
     * org.apache.opencmis.client.api.repository.ObjectFactory#createContentStream
     * (java.lang.String, long, java.lang.String, java.io.InputStream)
     */
    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

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.