Page History
...
Code Block | ||
---|---|---|
| ||
InputStream stream = new ByteArrayInputStream(contentString.getBytes("UTF-8")); IUserData userData = context.getSessionScope().getActiveUser(); CustomContentProperties properties = new CustomContentProperties(); properties.setProperty("customProperty", new StringValue("value")); String contentName = "content name"; String contentType = "text/plain"; Long processId = null; String caseId = null; if(contentManager instanceof IChannelContentManager channelContentManager) { // Using the Java NIO-based API introduced in Blueriq 17.4 GUID contentId = channelContentManager.create(Channels.newChannel(stream), contentName, contentType, processId, caseId, properties, context.getSessionScope().getActiveUser())userData); } else { // Using the stream-based API that was deprecated in Blueriq 17.4 and might be released in a future release GUID contentId = contentManager.create(stream, contentName, contentType, processId, caseId, properties, context.getSessionScope().getActiveUser()userData); } |
The properties object may be used to store additional properties with the content. The contentId will be required to read, update or delete this content at a later time.
...
The following code snippet shows how to retrieve the string that was created in the previous example.
Code Block | ||
---|---|---|
| ||
IContentMetadata metadata =IUserData userData = context.getSessionScope().getActiveUser(); int size = (int) contentManager.readMetadata(contentId, context.getSessionScope().getActiveUser(), truefalse).getSize(); String contentString; if(contentManager instanceof IChannelContentManager channelContentManager) { // Using the Java NIO-based API introduced in Blueriq 17.4 ByteBuffer content = ByteBuffer.allocate(size); // Be sure to close the channel after use to prevent files from being locked try (ReadableByteChannel channel = contentManager.getReadableByteChannel(contentId, userData)) { channel.read(content); } contentString = new String(content.array(), StandardCharsets.UTF_8); } else { // Using the stream-based API that was deprecated in Blueriq 17.4 and might be released in a future release byte[] content = new byte[(int) metadata.getSize()size]; contentManager.readBytes(contentId, 0, content, 0, (int) metadata.getSize(), context.getSessionScope().getActiveUser())size, userData); contentString = new String(content, StandardCharsets.UTF_8); } |
...
Code Block | ||
---|---|---|
| ||
InputStream stream = new ByteArrayInputStream(newContentString.getBytes("UTF-8")); IUserData userData = context.getSessionScope().getActiveUser(); CustomContentProperties properties = new CustomContentProperties(); properties.setProperty("customProperty", new StringValue("newValue")); String contentName = "new content name"; String contentType = "text/plain"; Long processId = null; String caseId = null; if(contentManager instanceof IChannelContentManager channelContentManager) { // Using the Java NIO-based API introduced in Blueriq 17.4 contentManager.update(contentId, Channels.newChannel(stream), contentName, contentType, processId, caseId, properties, context.getSessionScope().getActiveUser())userData); } else { // Using the stream-based API that was deprecated in Blueriq 17.4 and might be released in a future release contentManager.update(contentId, stream, contentName, contentType, processId, caseId, properties, context.getSessionScope().getActiveUser()userData); } |
Delete content
The following example shows how to delete the content made in the previous example:
...
Overview
Content Tools