本文整理汇总了Java中org.apache.chemistry.opencmis.commons.data.ContentStream.getStream方法的典型用法代码示例。如果您正苦于以下问题:Java ContentStream.getStream方法的具体用法?Java ContentStream.getStream怎么用?Java ContentStream.getStream使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.chemistry.opencmis.commons.data.ContentStream
的用法示例。
在下文中一共展示了ContentStream.getStream方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getContentAsString
import org.apache.chemistry.opencmis.commons.data.ContentStream; //导入方法依赖的package包/类
public String getContentAsString(ContentStream stream) throws IOException {
StringBuilder sb = new StringBuilder();
Reader reader = new InputStreamReader(stream.getStream(), "UTF-8");
try {
final char[] buffer = new char[4 * 1024];
int b;
while (true) {
b = reader.read(buffer, 0, buffer.length);
if (b > 0) {
sb.append(buffer, 0, b);
} else if (b == -1) {
break;
}
}
} finally {
reader.close();
}
return sb.toString();
}
示例2: processNonFolderNode
import org.apache.chemistry.opencmis.commons.data.ContentStream; //导入方法依赖的package包/类
private void processNonFolderNode(CmisObject cmisObject, Folder parentFolder) throws Exception {
InputStream inputStream = null;
Map<String, Object> properties = CMISHelper.objectProperties(cmisObject);
properties.put(CamelCMISConstants.CMIS_FOLDER_PATH, parentFolder.getPath());
if (CMISHelper.isDocument(cmisObject) && readContent) {
ContentStream contentStream = ((Document)cmisObject).getContentStream();
if (contentStream != null) {
inputStream = contentStream.getStream();
}
}
sendNode(properties, inputStream);
}
示例3: appendContentStream
import org.apache.chemistry.opencmis.commons.data.ContentStream; //导入方法依赖的package包/类
@Override
public void appendContentStream(String repositoryId, Holder<String> objectId, Holder<String> changeToken,
ContentStream contentStream, boolean isLastChunk, ExtensionsData extension)
{
if ((contentStream == null) || (contentStream.getStream() == null))
{
throw new CmisInvalidArgumentException("No content!");
}
checkRepositoryId(repositoryId);
CMISNodeInfo info = getOrCreateNodeInfo(objectId.getValue(), "Object");
NodeRef nodeRef = info.getNodeRef();
if (((DocumentTypeDefinition) info.getType().getTypeDefinition(false)).getContentStreamAllowed() == ContentStreamAllowed.NOTALLOWED)
{
throw new CmisStreamNotSupportedException("Document type doesn't allow content!");
}
try
{
connector.appendContent(info, contentStream, isLastChunk);
objectId.setValue(connector.createObjectId(nodeRef));
}
catch(IOException e)
{
throw new ContentIOException("", e);
}
}
示例4: createDocument
import org.apache.chemistry.opencmis.commons.data.ContentStream; //导入方法依赖的package包/类
/**
* CMIS createDocument.
*/
public String createDocument(CallContext context, Properties properties, String folderId,
ContentStream contentStream, VersioningState versioningState) {
checkUser(context, true);
// check versioning state
if (VersioningState.NONE != versioningState) {
throw new CmisConstraintException("Versioning not supported!");
}
// get parent File
File parent = getFile(folderId);
if (!parent.isDirectory()) {
throw new CmisObjectNotFoundException("Parent is not a folder!");
}
// check properties
checkNewProperties(properties, BaseTypeId.CMIS_DOCUMENT);
// check the file
String name = FileBridgeUtils.getStringProperty(properties, PropertyIds.NAME);
File newFile = new File(parent, name);
if (newFile.exists()) {
throw new CmisNameConstraintViolationException("Document already exists!");
}
// create the file
try {
newFile.createNewFile();
} catch (IOException e) {
throw new CmisStorageException("Could not create file: " + e.getMessage(), e);
}
// write content, if available
if (contentStream != null && contentStream.getStream() != null) {
writeContent(newFile, contentStream.getStream());
}
return getId(newFile);
}
示例5: getInputStream
import org.apache.chemistry.opencmis.commons.data.ContentStream; //导入方法依赖的package包/类
@Override
public InputStream getInputStream(String sObjectId) throws IOException {
Session aSession = cmisService.startSession();
ObjectId aObjectId = aSession.createObjectId(sObjectId);
ContentStream aContentStream = aSession.getContentStream(aObjectId);
return aContentStream.getStream();
}
示例6: getRendition
import org.apache.chemistry.opencmis.commons.data.ContentStream; //导入方法依赖的package包/类
public Downloadable<byte[]> getRendition(String type, String objectId, String name) {
List<Rendition> renditions = getDocumentById(objectId).getRenditions();
Optional<Rendition> rendition = renditions!=null ?
renditions.stream().filter(r -> type.equals(r.getTitle())).findFirst() : Optional.empty();
InputStream is;
String mimeType;
if (rendition.isPresent()) {
ContentStream cs = rendition.get().getContentStream();
is = cs.getStream();
mimeType = cs.getMimeType();
}
else {
is = getClass().getResourceAsStream("resources/img/default-generic-icon.png");
mimeType = "image/png";
}
byte[] buffer;
try {
buffer = IOUtils.toByteArray(is);
}
catch (IOException e) {
// rendition non trovata
buffer = new byte[0];
}
return new RenditionDownloadable (name, buffer, buffer.length, mimeType);
}
示例7: getContentAsString
import org.apache.chemistry.opencmis.commons.data.ContentStream; //导入方法依赖的package包/类
/**
* Helper method to get the contents of a stream
*
* @param stream
* @return
* @throws IOException
*/
public static String getContentAsString(ContentStream stream)
{
StringBuilder sb = new StringBuilder();
try
{
Reader reader = new InputStreamReader(stream.getStream(), "UTF-8");
try
{
final char[] buffer = new char[4 * 1024];
int b;
while (true)
{
b = reader.read(buffer, 0, buffer.length);
if (b > 0)
{
sb.append(buffer, 0, b);
}
else if (b == -1)
{
break;
}
}
}
finally
{
reader.close();
}
}
catch (IOException exception)
{
System.out.println("Unable to read content. " + exception.getMessage());
}
return sb.toString();
}
示例8: appendContentStream
import org.apache.chemistry.opencmis.commons.data.ContentStream; //导入方法依赖的package包/类
@Override
public void appendContentStream(String repositoryId, Holder<String> objectId, Holder<String> changeToken,
ContentStream contentStream, boolean isLastChunk, ExtensionsData extension)
{
if ((contentStream == null) || (contentStream.getStream() == null))
{
throw new CmisInvalidArgumentException("No content!");
}
checkRepositoryId(repositoryId);
CMISNodeInfo info = getOrCreateNodeInfo(objectId.getValue(), "Object");
NodeRef nodeRef = info.getNodeRef();
if (((DocumentTypeDefinition) info.getType().getTypeDefinition(false)).getContentStreamAllowed() == ContentStreamAllowed.NOTALLOWED)
{
throw new CmisStreamNotSupportedException("Document type doesn't allow content!");
}
//ALF-21852 - Separated appendContent and objectId.setValue in two different transactions because
//after executing appendContent, the new objectId is not visible.
RetryingTransactionHelper helper = connector.getRetryingTransactionHelper();
helper.doInTransaction(new RetryingTransactionCallback<Void>()
{
public Void execute() throws Throwable
{
try
{
connector.appendContent(info, contentStream, isLastChunk);
}
catch(IOException e)
{
throw new ContentIOException("", e);
}
return null;
}
}, false, true);
String objId = helper.doInTransaction(new RetryingTransactionCallback<String>()
{
public String execute() throws Throwable
{
return connector.createObjectId(nodeRef);
}
}, true, true);
objectId.setValue(objId);
}
示例9: setContentStream
import org.apache.chemistry.opencmis.commons.data.ContentStream; //导入方法依赖的package包/类
@Override
public void setContentStream(
String repositoryId, Holder<String> objectId, Boolean overwriteFlag,
Holder<String> changeToken, final ContentStream contentStream, ExtensionsData extension)
{
checkRepositoryId(repositoryId);
CMISNodeInfo info = getOrCreateNodeInfo(objectId.getValue(), "Object");
if (!info.isVariant(CMISObjectVariant.CURRENT_VERSION) && !info.isVariant(CMISObjectVariant.PWC))
{
throw new CmisStreamNotSupportedException("Content can only be set on private working copies or current versions.");
}
final NodeRef nodeRef = info.getNodeRef();
if (((DocumentTypeDefinition) info.getType().getTypeDefinition(false)).getContentStreamAllowed() == ContentStreamAllowed.NOTALLOWED)
{
throw new CmisStreamNotSupportedException("Document type doesn't allow content!");
}
boolean existed = connector.getContentService().getReader(nodeRef, ContentModel.PROP_CONTENT) != null;
if (existed && !overwriteFlag)
{
throw new CmisContentAlreadyExistsException("Content already exists!");
}
if ((contentStream == null) || (contentStream.getStream() == null))
{
throw new CmisInvalidArgumentException("No content!");
}
//ALF-21852 - Separated setContent and objectId.setValue in two different transactions because
//after executing setContent, the new objectId is not visible.
RetryingTransactionHelper helper = connector.getRetryingTransactionHelper();
helper.doInTransaction(new RetryingTransactionCallback<Void>()
{
public Void execute() throws Throwable
{
String mimeType = parseMimeType(contentStream);
final File tempFile = copyToTempFile(contentStream);
String encoding = getEncoding(tempFile, mimeType);
try
{
ContentWriter writer = connector.getFileFolderService().getWriter(nodeRef);
writer.setMimetype(mimeType);
writer.setEncoding(encoding);
writer.putContent(tempFile);
}
finally
{
removeTempFile(tempFile);
}
connector.getActivityPoster().postFileFolderUpdated(info.isFolder(), nodeRef);
return null;
}
}, false, true);
String objId = helper.doInTransaction(new RetryingTransactionCallback<String>()
{
public String execute() throws Throwable
{
return connector.createObjectId(nodeRef);
}
}, true, true);
objectId.setValue(objId);
}
示例10: getObjectStream
import org.apache.chemistry.opencmis.commons.data.ContentStream; //导入方法依赖的package包/类
public final Path getObjectStream(String cmisId, Path destPath, String fileName) throws IOException{
Path streamPath = null;
Document document = (Document)session.getObject(cmisId);
ContentStream contentStream = document.getContentStream();
if(contentStream != null){
if(fileName == null) fileName = contentStream.getFileName();
streamPath = Paths.get(destPath.toString(),fileName);
File streamFile = new File(streamPath.toString());
InputStream inputStream = contentStream.getStream();
FileUtils.copyInputStreamToFile(inputStream, streamFile);
}
return streamPath;
}
示例11: setContentStream
import org.apache.chemistry.opencmis.commons.data.ContentStream; //导入方法依赖的package包/类
@Override
public void setContentStream(
String repositoryId, Holder<String> objectId, Boolean overwriteFlag,
Holder<String> changeToken, final ContentStream contentStream, ExtensionsData extension)
{
checkRepositoryId(repositoryId);
CMISNodeInfo info = getOrCreateNodeInfo(objectId.getValue(), "Object");
if (!info.isVariant(CMISObjectVariant.CURRENT_VERSION) && !info.isVariant(CMISObjectVariant.PWC))
{
throw new CmisStreamNotSupportedException("Content can only be set ondocuments!");
}
final NodeRef nodeRef = info.getNodeRef();
if (((DocumentTypeDefinition) info.getType().getTypeDefinition(false)).getContentStreamAllowed() == ContentStreamAllowed.NOTALLOWED)
{
throw new CmisStreamNotSupportedException("Document type doesn't allow content!");
}
boolean existed = connector.getContentService().getReader(nodeRef, ContentModel.PROP_CONTENT) != null;
if (existed && !overwriteFlag)
{
throw new CmisContentAlreadyExistsException("Content already exists!");
}
if ((contentStream == null) || (contentStream.getStream() == null))
{
throw new CmisInvalidArgumentException("No content!");
}
// copy stream to temp file
final File tempFile = copyToTempFile(contentStream);
final Charset encoding = getEncoding(tempFile, contentStream.getMimeType());
try
{
ContentWriter writer = connector.getFileFolderService().getWriter(nodeRef);
String mimeType = parseMimeType(contentStream);
writer.setMimetype(mimeType);
writer.setEncoding(encoding.name());
writer.putContent(tempFile);
}
finally
{
removeTempFile(tempFile);
}
objectId.setValue(connector.createObjectId(nodeRef));
connector.getActivityPoster().postFileFolderUpdated(info.isFolder(), nodeRef);
}
示例12: changeContentStream
import org.apache.chemistry.opencmis.commons.data.ContentStream; //导入方法依赖的package包/类
/**
* CMIS setContentStream, deleteContentStream, and appendContentStream.
*/
public void changeContentStream(CallContext context, Holder<String> objectId, Boolean overwriteFlag,
ContentStream contentStream, boolean append) {
checkUser(context, true);
if (objectId == null) {
throw new CmisInvalidArgumentException("Id is not valid!");
}
// get the file
File file = getFile(objectId.getValue());
if (!file.isFile()) {
throw new CmisStreamNotSupportedException("Not a file!");
}
// check overwrite
boolean owf = FileBridgeUtils.getBooleanParameter(overwriteFlag, true);
if (!owf && file.length() > 0) {
throw new CmisContentAlreadyExistsException("Content already exists!");
}
OutputStream out = null;
InputStream in = null;
try {
out = new BufferedOutputStream(new FileOutputStream(file, append), BUFFER_SIZE);
if (contentStream == null || contentStream.getStream() == null) {
// delete content
out.write(new byte[0]);
} else {
// set content
in = new BufferedInputStream(contentStream.getStream(), BUFFER_SIZE);
byte[] buffer = new byte[BUFFER_SIZE];
int b;
while ((b = in.read(buffer)) > -1) {
out.write(buffer, 0, b);
}
}
} catch (Exception e) {
throw new CmisStorageException("Could not write content: " + e.getMessage(), e);
} finally {
IOUtils.closeQuietly(out);
IOUtils.closeQuietly(in);
}
}
示例13: setContentStream
import org.apache.chemistry.opencmis.commons.data.ContentStream; //导入方法依赖的package包/类
/**
* See CMIS 1.0 section 2.2.4.16 setContentStream
*
* @throws CmisStorageException
*/
public RegistryObject setContentStream(ContentStream contentStream, boolean overwriteFlag) {
try {
//Check for existing data
Object dataObject = getNode().getContent();
int length = 0;
if (dataObject != null){
length = 1;
}
// check overwrite
if (!overwriteFlag && length != 0) {
throw new CmisContentAlreadyExistsException("Content already exists!");
}
RegistryVersionBase gregVersion = isVersionable() ? asVersion() : null;
boolean autoCheckout = gregVersion != null && !gregVersion.isCheckedOut();
RegistryVersionBase gregVersionContext = null;
if (autoCheckout) {
gregVersionContext = gregVersion.checkout();
} else {
gregVersionContext = gregVersion;
}
Resource resource = null;
// write content, if available
if(contentStream == null || contentStream.getStream() == null){
resource = gregVersionContext.getNode();
resource.setContent(null);
} else{
//Sets the content stream
resource = gregVersionContext.getNode();
resource.setContentStream(contentStream.getStream());
//TODO MIME-Type --> DONE
//contentStream.getMimeType();
}
//put to registry
String versionContextPath = gregVersionContext.getNode().getPath();
getRepository().put(versionContextPath, resource);
//set
gregVersionContext.setNode(getRepository().get(versionContextPath));
if (autoCheckout) {
// auto versioning -> return new version created by checkin
return gregVersionContext.checkin(null, null, "auto checkout");
} else if (gregVersionContext != null) {
// the node is checked out -> return pwc.
return gregVersionContext.getPwc();
} else {
// non versionable -> return this
return this;
}
}
catch (RegistryException e) {
log.error("Error occurred while setting content stream ", e);
throw new CmisStorageException(e.getMessage());
}
}
示例14: createDocument
import org.apache.chemistry.opencmis.commons.data.ContentStream; //导入方法依赖的package包/类
public RegistryObject createDocument(RegistryFolder parentFolder, String name, Properties properties, ContentStream contentStream, VersioningState versioningState) {
try {
Resource fileNode = repository.newResource();
// write content, if available
if(contentStream != null && contentStream.getStream() != null){
//set stream
fileNode.setProperty(CMISConstants.GREG_DATA, "true");
fileNode.setContentStream(contentStream.getStream());
}
//Put to registry AS A PWC (Look at getDestPathOfNode() )
String destinationPath = CommonUtil.getTargetPathOfNode(parentFolder, name);
repository.put(destinationPath, fileNode);
fileNode = repository.get(destinationPath);
// compile the properties
RegistryFolder.setProperties(repository, fileNode, getTypeDefinition(), properties);
//Set MIMETYPE
if (contentStream != null && contentStream.getMimeType() != null) {
fileNode.setProperty(CMISConstants.GREG_MIMETYPE, contentStream.getMimeType());
fileNode.setMediaType(contentStream.getMimeType());
}
repository.put(destinationPath, fileNode);
fileNode = repository.get(destinationPath);
if (versioningState == VersioningState.NONE) {
fileNode.setProperty(CMISConstants.GREG_UNVERSIONED_TYPE, "true");
repository.put(destinationPath, fileNode);
return new RegistryUnversionedDocument(repository, fileNode, typeManager, pathManager);
}
//Else, create as a PWC. See spec
//TODO Set the destination of this PWC to a temp and put it to it's intended location when checked in
fileNode.setProperty(CMISConstants.GREG_IS_CHECKED_OUT, "true");
//Put to registry
repository.put(destinationPath, fileNode);
RegistryObject gregFileNode = getGregNode(fileNode);
RegistryVersionBase gregVersion = gregFileNode.asVersion();
if(versioningState==VersioningState.CHECKEDOUT){
//Put to checked out tracker
Resource resource = null;
if(repository.resourceExists(CMISConstants.GREG_CHECKED_OUT_TRACKER)){
resource = repository.get(CMISConstants.GREG_CHECKED_OUT_TRACKER);
} else{
resource = repository.newResource();
//Have to set content, otherwise Greg will throw exception when browsing this file in Workbench
resource.setContent("tracker");
}
resource.setProperty(gregVersion.getNode().getPath(), "true");
repository.put(CMISConstants.GREG_CHECKED_OUT_TRACKER, resource);
//Set property saying this was created as a PWC
gregVersion.getNode().setProperty(CMISConstants.GREG_CREATED_AS_PWC, "true");
repository.put(gregVersion.getNode().getPath(), gregVersion.getNode());
gregVersion = getGregNode(repository.get(gregVersion.getNode().getPath())).asVersion();
return gregVersion.getPwc();
} else {
if( versioningState == VersioningState.MAJOR){
gregVersion.getNode().addProperty(CMISConstants.GREG_VERSION_STATE, CMISConstants.GREG_MAJOR_VERSION);
} else if (versioningState==VersioningState.MINOR){
gregVersion.getNode().addProperty(CMISConstants.GREG_VERSION_STATE, CMISConstants.GREG_MINOR_VERSION);
}
//put properties
repository.put(gregVersion.getNode().getPath(), gregVersion.getNode());
return gregVersion.checkin(null, null, "auto checkin");
}
}
catch (RegistryException e) {
log.debug(e.getMessage(), e);
throw new CmisStorageException(e.getMessage(), e);
}
}
示例15: preSign
import org.apache.chemistry.opencmis.commons.data.ContentStream; //导入方法依赖的package包/类
public DigestInfo preSign(List<DigestInfo> arg0, List<X509Certificate> certificates)
throws NoSuchAlgorithmException {
System.out.println("SignatureServiceImpl::preSign");
HttpSession session = getSession();
SignatureRequest request = (SignatureRequest)session.getAttribute(BeidConstants.SIGNATUREREQUEST_SESSION_NAME);
ContentStream content = request.getDocument().getContentStream();
try
{
Certificate[] chain = new Certificate[certificates.size()];
int index = 0;
for (X509Certificate cert: certificates)
{
//System.out.println("CERT: "+cert);
chain[index++] = cert;
}
// we create a reader and a stamper
PdfReader reader = new PdfReader(content.getStream());
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PdfStamper stamper = PdfStamper.createSignature(reader, baos, '\0');
// we create the signature appearance
PdfSignatureAppearance sap = stamper.getSignatureAppearance();
request.fillAppearance(sap, reader);
sap.setCertificate(chain[0]);
// we create the signature infrastructure
PdfSignature dic = new PdfSignature(PdfName.ADOBE_PPKLITE, PdfName.ADBE_PKCS7_DETACHED);
dic.setReason(sap.getReason());
dic.setLocation(sap.getLocation());
dic.setContact(sap.getContact());
dic.setDate(new PdfDate(sap.getSignDate()));
sap.setCryptoDictionary(dic);
HashMap<PdfName, Integer> exc = new HashMap<PdfName, Integer>();
exc.put(PdfName.CONTENTS, new Integer(8192 * 2 + 2));
sap.preClose(exc);
ExternalDigest externalDigest = new ExternalDigest() {
public MessageDigest getMessageDigest(String hashAlgorithm)
throws GeneralSecurityException {
return DigestAlgorithms.getMessageDigest(hashAlgorithm,
null);
}
};
PdfPKCS7 sgn = new PdfPKCS7(null, chain, "SHA256", null, externalDigest, false);
InputStream data = sap.getRangeStream();
byte hash[] = DigestAlgorithms.digest(data, externalDigest.getMessageDigest("SHA256"));
Calendar cal = Calendar.getInstance();
byte[] sh = sgn.getAuthenticatedAttributeBytes(hash, cal, null, null, CryptoStandard.CMS);
sh = MessageDigest.getInstance("SHA256", "BC").digest(sh);
// We store the objects we'll need for post signing in a session
session.setAttribute(BeidConstants.SIGNATURE_SESSION_NAME, sgn);
session.setAttribute(BeidConstants.HASH_SESSION_NAME, hash);
session.setAttribute(BeidConstants.CAL_SESSION_NAME, cal);
session.setAttribute(BeidConstants.SAP_SESSION_NAME, sap);
session.setAttribute(BeidConstants.BAOS_SESSION_NAME, baos);
DigestInfo info = new DigestInfo(sh, "SHA-256", "BeidSign");
return info;
}
catch(Exception e)
{
e.printStackTrace();
}
return null;
}