本文整理汇总了Java中org.apache.chemistry.opencmis.commons.data.ContentStream类的典型用法代码示例。如果您正苦于以下问题:Java ContentStream类的具体用法?Java ContentStream怎么用?Java ContentStream使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ContentStream类属于org.apache.chemistry.opencmis.commons.data包,在下文中一共展示了ContentStream类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: updateDescriptorFile
import org.apache.chemistry.opencmis.commons.data.ContentStream; //导入依赖的package包/类
@Override
public void updateDescriptorFile(String tenantId, String uuid, CMISEvidenceFile cmisFile) {
Session session = createSession();
Folder multitenantRootFolder = (Folder) session.getObjectByPath("/" + tenantId);
Folder uuidFolder = getUuidFolder(session, uuid, multitenantRootFolder, repoFolderNestingLevels, true);
for (CmisObject cmisObject : uuidFolder.getChildren()) {
if (cmisObject.getType().getId().equals(CMISEvidenceFile.PROPERTY_DOC_ID)) {
Document doc = (Document) cmisObject;
if (doc.getName().equals(cmisFile.getFileName())) {
Map<String, String> newDocProps = new HashMap<String, String>();
newDocProps.put(CMISEvidenceFile.PROPERTY_TRANSACTION_STATUS, cmisFile.getTransactionStatus());
doc.updateProperties(newDocProps);
// Recover mime type from stored content
ContentStream contentStream = new ContentStreamImpl(cmisFile.getFileName(), null, doc.getContentStreamMimeType(), cmisFile.getInputStream());
doc.setContentStream(contentStream, true);
} else {
log.warn("Found unexpected CMIS object type in descriptor folder: " + cmisObject.getName() + " - " + cmisObject.getType().getId() +
" (expected " + cmisFile.getFileName() + ")");
}
}
}
}
示例2: createDocument
import org.apache.chemistry.opencmis.commons.data.ContentStream; //导入依赖的package包/类
/**
* Creates a new document with the given name and content under the given
* folder.
*
* @param name
* the name of the document.
* @param rootFolder
* the root folder.
* @param content
* the content of the document.
* @return the created document.
*/
public Document createDocument(Folder rootFolder, String fileName, InputStream inputStream) {
logger.debug(DEBUG_CREATING_NEW_DOCUMENT, fileName, rootFolder);
Document document = null;
Map<String, Object> properties = new HashMap<String, Object>();
properties.put(PropertyIds.OBJECT_TYPE_ID, CMIS_DOCUMENT_TYPE);
properties.put(PropertyIds.NAME, fileName);
ContentStream contentStream = cmisSession.getObjectFactory().createContentStream(fileName, -1,
MIME_TYPE_TEXT_PLAIN_UTF_8, inputStream);
try {
document = rootFolder.createDocument(properties, contentStream, VersioningState.NONE);
} catch (CmisNameConstraintViolationException e) {
String errorMessage = MessageFormat.format(ERROR_FILE_ALREADY_EXISTS, fileName);
logger.error(errorMessage);
throw new CmisNameConstraintViolationException(errorMessage, e);
}
logger.debug(DEBUG_DOCUMENT_CREATED, fileName);
return document;
}
示例3: parseMimeType
import org.apache.chemistry.opencmis.commons.data.ContentStream; //导入依赖的package包/类
private String parseMimeType(ContentStream contentStream)
{
String mimeType = null;
String tmp = contentStream.getMimeType();
if(tmp != null)
{
int idx = tmp.indexOf(";");
if(idx != -1)
{
mimeType = tmp.substring(0, idx).trim();
}
else
{
mimeType = tmp;
}
}
return mimeType;
}
示例4: getContentStream
import org.apache.chemistry.opencmis.commons.data.ContentStream; //导入依赖的package包/类
@Override
public ContentStream getContentStream(
String repositoryId, String objectId, String streamId, BigInteger offset,
BigInteger length, ExtensionsData extension)
{
checkRepositoryId(repositoryId);
// what kind of object is it?
CMISNodeInfo info = getOrCreateNodeInfo(objectId, "Object");
// relationships cannot have content
if (info.isVariant(CMISObjectVariant.ASSOC))
{
throw new CmisInvalidArgumentException("Object is a relationship and cannot have content!");
}
// now get it
return connector.getContentStream(info, streamId, offset, length);
}
示例5: copyToTempFile
import org.apache.chemistry.opencmis.commons.data.ContentStream; //导入依赖的package包/类
private File copyToTempFile(ContentStream contentStream)
{
if (contentStream == null)
{
return null;
}
File result = null;
try
{
result = TempFileProvider.createTempFile(contentStream.getStream(), "cmis", "content");
}
catch (Exception e)
{
throw new CmisStorageException("Unable to store content: " + e.getMessage(), e);
}
if ((contentStream.getLength() > -1) && (result == null || contentStream.getLength() != result.length()))
{
removeTempFile(result);
throw new CmisStorageException("Expected " + contentStream.getLength() + " bytes but retrieved " +
(result == null ? -1 :result.length()) + " bytes!");
}
return result;
}
示例6: createDocument
import org.apache.chemistry.opencmis.commons.data.ContentStream; //导入依赖的package包/类
private static Document createDocument(Folder target, String newDocName, Session session)
{
Map<String, String> props = new HashMap<String, String>();
props.put(PropertyIds.OBJECT_TYPE_ID, "cmis:document");
props.put(PropertyIds.NAME, newDocName);
String content = "aegif Mind Share Leader Generating New Paradigms by aegif corporation.";
byte[] buf = null;
try
{
buf = content.getBytes("ISO-8859-1"); // set the encoding here for the content stream
}
catch (UnsupportedEncodingException e)
{
e.printStackTrace();
}
ByteArrayInputStream input = new ByteArrayInputStream(buf);
ContentStream contentStream = session.getObjectFactory().createContentStream(newDocName, buf.length,
"text/plain; charset=UTF-8", input); // additionally set the charset here
// NOTE that we intentionally specified the wrong charset here (as UTF-8)
// because Alfresco does automatic charset detection, so we will ignore this explicit request
return target.createDocument(props, contentStream, VersioningState.MAJOR);
}
示例7: create
import org.apache.chemistry.opencmis.commons.data.ContentStream; //导入依赖的package包/类
@Override
public String create(String repositoryId, Properties properties, String folderId,
ContentStream contentStream, VersioningState versioningState,
List<String> policies, ExtensionsData extension)
{
FileFilterMode.setClient(Client.cmis);
try
{
return super.create(
repositoryId,
properties,
folderId,
contentStream,
versioningState,
policies,
extension);
}
finally
{
FileFilterMode.clearClient();
}
}
示例8: createDocument
import org.apache.chemistry.opencmis.commons.data.ContentStream; //导入依赖的package包/类
/**
* Overridden to capture content upload for publishing to analytics service.
*/
@Override
public String createDocument(String repositoryId, Properties properties, String folderId,
ContentStream contentStream, VersioningState versioningState,
List<String> policies, Acl addAces, Acl removeAces, ExtensionsData extension)
{
String newId = super.createDocument(
repositoryId,
properties,
folderId,
contentStream,
versioningState,
policies,
addAces,
removeAces,
extension);
return newId;
}
示例9: setContentStream
import org.apache.chemistry.opencmis.commons.data.ContentStream; //导入依赖的package包/类
/**
* Overridden to capture content upload for publishing to analytics service.
*/
@Override
public void setContentStream(String repositoryId, Holder<String> objectId,
Boolean overwriteFlag, Holder<String> changeToken, ContentStream contentStream,
ExtensionsData extension)
{
FileFilterMode.setClient(Client.cmis);
try
{
super.setContentStream(repositoryId, objectId, overwriteFlag, changeToken, contentStream, extension);
}
finally
{
FileFilterMode.clearClient();
}
}
示例10: createNode
import org.apache.chemistry.opencmis.commons.data.ContentStream; //导入依赖的package包/类
private CmisObject createNode(Exchange exchange) throws Exception {
validateRequiredHeader(exchange, PropertyIds.NAME);
Message message = exchange.getIn();
String parentFolderPath = parentFolderPathFor(message);
Folder parentFolder = getFolderOnPath(exchange, parentFolderPath);
Map<String, Object> cmisProperties = filterTypeProperties(message.getHeaders());
if (isDocument(exchange)) {
String fileName = message.getHeader(PropertyIds.NAME, String.class);
String mimeType = getMimeType(message);
byte[] buf = getBodyData(message);
ContentStream contentStream = getSessionFacade().createContentStream(fileName, buf, mimeType);
return storeDocument(parentFolder, cmisProperties, contentStream);
} else if (isFolder(message)) {
return storeFolder(parentFolder, cmisProperties);
} else { // other types
return storeDocument(parentFolder, cmisProperties, null);
}
}
示例11: retrieve
import org.apache.chemistry.opencmis.commons.data.ContentStream; //导入依赖的package包/类
@Override
public T retrieve(String path, String documentName, Session session) throws Exception {
// Disable cache
session.getDefaultContext().setCacheEnabled(false);
Document object = (Document)FileUtils.getObject(path + documentName, session);
ContentStream contentStream = object.getContentStream();
Class<T> classP = getClassP();
T document = classP.newInstance();
document.setContentStream(IOUtils.toByteArray(contentStream.getStream()));
document.setContentStreamFilename(documentName);
document.setContentStreamLenght(contentStream.getLength());
document.setContentStreamMimeType(contentStream.getMimeType());
// Enable cache
session.getDefaultContext().setCacheEnabled(true);
return document;
}
示例12: create
import org.apache.chemistry.opencmis.commons.data.ContentStream; //导入依赖的package包/类
/**
* Create* dispatch for AtomPub.
*/
public ObjectData create(CallContext context, Properties properties, String folderId, ContentStream contentStream,
VersioningState versioningState, ObjectInfoHandler objectInfos) {
boolean userReadOnly = checkUser(context, true);
String typeId = FileBridgeUtils.getObjectTypeId(properties);
TypeDefinition type = typeManager.getInternalTypeDefinition(typeId);
if (type == null) {
throw new CmisObjectNotFoundException("Type '" + typeId + "' is unknown!");
}
String objectId = null;
if (type.getBaseTypeId() == BaseTypeId.CMIS_DOCUMENT) {
objectId = createDocument(context, properties, folderId, contentStream, versioningState);
} else if (type.getBaseTypeId() == BaseTypeId.CMIS_FOLDER) {
objectId = createFolder(context, properties, folderId);
} else {
throw new CmisObjectNotFoundException("Cannot create object of type '" + typeId + "'!");
}
return compileObjectData(context, getFile(objectId), null, false, false, userReadOnly, objectInfos);
}
示例13: createDocument
import org.apache.chemistry.opencmis.commons.data.ContentStream; //导入依赖的package包/类
public String createDocument(Folder parentFolder, String name, byte[] content) {
logger.debug("Prepparing to create document");
Document document = null;
try{
Map<String, Object> properties = new HashMap<String, Object>();
properties.put(PropertyIds.NAME, name);
properties.put(PropertyIds.OBJECT_TYPE_ID, "cmis:document");
InputStream stream = new ByteArrayInputStream(content);
ContentStream contentStream = new ContentStreamImpl(name,
BigInteger.valueOf(content.length), "text/plain", stream);
logger.info("Creating document in path: " + parentFolder.getPath());
document = parentFolder.createDocument(properties, contentStream, null);
logger.info("Document path: " + document.getPaths().get(0));
}
catch(Exception e){
logger.error("Failed to create document.", e);
}
return document.getPaths().get(0);
}
示例14: appendToContentStream
import org.apache.chemistry.opencmis.commons.data.ContentStream; //导入依赖的package包/类
public ContentStream appendToContentStream(ContentStream contentStream, String documentName, String mimeType){
ContentStream updatedContentStream = null;
try{
String contentStreamAsString = this.getContentAsString(contentStream);
String updatedContent = contentStreamAsString + "\n This is my new text";
byte[] updatedContentByteArray = updatedContent.getBytes();
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(updatedContentByteArray);
updatedContentStream = session.getObjectFactory().createContentStream(documentName,
updatedContentByteArray.length,
mimeType,
byteArrayInputStream);
}
catch(Exception e){
logger.error("Failed to add text to content stream.", e);
}
return updatedContentStream;
}
示例15: 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();
}