<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How to update content with ContentWriter class in Alfresco Archive</title>
    <link>https://connect.hyland.com/t5/alfresco-archive/how-to-update-content-with-contentwriter-class/m-p/132947#M93376</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Related to this post, what if I did want to append text to the existing content of a file?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I've tried append, but it only overwrites the whole content with the new string.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;A simplified code example:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="language-none line-numbers"&gt;&lt;CODE&gt;ContentService contentService = this.serviceRegistry.getContentService();&lt;BR /&gt;ContentWriter contentWriter = contentService.getWriter(nodeCurrentLogFile, ContentModel.PROP_CONTENT, true);&lt;BR /&gt;contentWriter.setMimetype("text/plain");&lt;BR /&gt;OutputStream outputStream = contentWriter.getContentOutputStream();&lt;BR /&gt;PrintWriter printWriter = new PrintWriter(outputStream);&lt;BR /&gt;&lt;BR /&gt;//printWriter.println(logLine); // Replaces the whole content with logLine.&lt;BR /&gt;//printWriter.append(logLine); // Replaces the whole content with logLine.&lt;BR /&gt;printWriter.write(logLine, (int) contentWriter.getSize(), logLine.length());&amp;nbsp; // Replaces the whole content with logLine.&lt;BR /&gt;&lt;BR /&gt;printWriter.flush();&lt;BR /&gt;printWriter.close();&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;BR /&gt;&lt;SPAN&gt;Am I missing something fundamental here?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 21 Jan 2009 14:24:23 GMT</pubDate>
    <dc:creator>tommorris</dc:creator>
    <dc:date>2009-01-21T14:24:23Z</dc:date>
    <item>
      <title>How to update content with ContentWriter class</title>
      <link>https://connect.hyland.com/t5/alfresco-archive/how-to-update-content-with-contentwriter-class/m-p/132942#M93371</link>
      <description>Hi all.I need to modify the content (plain/text) of an existing node programatically. At first, I thought to use the ContentWriter class and its put() method.I have to replace the content of a node entirely so I tried to get the ContentReader associated to the node, to store it into a String variabl</description>
      <pubDate>Fri, 21 Dec 2007 13:34:39 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-archive/how-to-update-content-with-contentwriter-class/m-p/132942#M93371</guid>
      <dc:creator>sergio</dc:creator>
      <dc:date>2007-12-21T13:34:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to update content with ContentWriter class</title>
      <link>https://connect.hyland.com/t5/alfresco-archive/how-to-update-content-with-contentwriter-class/m-p/132943#M93372</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi Sergio,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I don't know what the preferred way is, since I'm not an Alfresco developer or something, but this might work:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Create a new ContentData object and assign it to the node with the nodeService:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="language-none line-numbers"&gt;&lt;CODE&gt;&lt;BR /&gt;ContentData content&amp;nbsp; = ContentData.createContentProperty("My content.");&lt;BR /&gt;nodeService.setProperty(nodeRef, ContentModel.PROP_CONTENT, content);&lt;BR /&gt;&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 21 Dec 2007 22:54:30 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-archive/how-to-update-content-with-contentwriter-class/m-p/132943#M93372</guid>
      <dc:creator>stijndereede</dc:creator>
      <dc:date>2007-12-21T22:54:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to update content with ContentWriter class</title>
      <link>https://connect.hyland.com/t5/alfresco-archive/how-to-update-content-with-contentwriter-class/m-p/132944#M93373</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thank for your adivices, but I think that the method you suggested me is only responsible for modifying the &lt;/SPAN&gt;&lt;STRONG&gt;content property &lt;/STRONG&gt;&lt;SPAN&gt;of a node and not for modifying the content of the associated file, too.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Did you try the suggested method by yourself to update the content of a node associated file? Did you do it after creating a node or just during its first creation?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;At the moment, the only way I am going to try (but I am not sure it could be the most correct at all) consists of creating programmatically a new node, getting its content writer, writing the new content, then renaming the new node as the old one after deleting this one.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Other suggestions for getting this goal will be very appreciated.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;All the best,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Sergio&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 28 Dec 2007 22:55:48 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-archive/how-to-update-content-with-contentwriter-class/m-p/132944#M93373</guid>
      <dc:creator>sergio</dc:creator>
      <dc:date>2007-12-28T22:55:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to update content with ContentWriter class</title>
      <link>https://connect.hyland.com/t5/alfresco-archive/how-to-update-content-with-contentwriter-class/m-p/132945#M93374</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;I need to &lt;STRONG&gt;modify the content &lt;/STRONG&gt;(plain/text) of an existing node programatically. At first, I thought to use the &lt;STRONG&gt;ContentWriter &lt;/STRONG&gt;class and its put() method.&lt;BR /&gt;&lt;BR /&gt;I have to replace the content of a node entirely so I tried to get the ContentReader associated to the node, to store it into a String variable, to modify the string itself accordingly to my custom needs, then to write the new string to the ContentWriter. I noticed that the put() method does not replace the content but appends a new content to the old one, doesn't it?&lt;BR /&gt;&lt;BR /&gt;How can I update the content of a node?&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt;Use ContentWriter - the put() method will overwrite the existing content (ensure the String you have manipulated does not still contain the old content!)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Kevin&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 17 Jan 2008 13:39:43 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-archive/how-to-update-content-with-contentwriter-class/m-p/132945#M93374</guid>
      <dc:creator>kevinr</dc:creator>
      <dc:date>2008-01-17T13:39:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to update content with ContentWriter class</title>
      <link>https://connect.hyland.com/t5/alfresco-archive/how-to-update-content-with-contentwriter-class/m-p/132946#M93375</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi Kevin.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You are perfectly right! I made a mistake when manipulating different java streams and I was not able to find the problem, at a first glance. So I thought the ContentWriter.put() method did not overwrite the content but appended it in such a way I was not able to understand. Sorry.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Actually, the method ContentWriter.put() does exactly what expected: it is responsible for updating the content of a node.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Many thanks and all the best.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Sergio&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 17 Jan 2008 13:57:13 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-archive/how-to-update-content-with-contentwriter-class/m-p/132946#M93375</guid>
      <dc:creator>sergio</dc:creator>
      <dc:date>2008-01-17T13:57:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to update content with ContentWriter class</title>
      <link>https://connect.hyland.com/t5/alfresco-archive/how-to-update-content-with-contentwriter-class/m-p/132947#M93376</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Related to this post, what if I did want to append text to the existing content of a file?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I've tried append, but it only overwrites the whole content with the new string.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;A simplified code example:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="language-none line-numbers"&gt;&lt;CODE&gt;ContentService contentService = this.serviceRegistry.getContentService();&lt;BR /&gt;ContentWriter contentWriter = contentService.getWriter(nodeCurrentLogFile, ContentModel.PROP_CONTENT, true);&lt;BR /&gt;contentWriter.setMimetype("text/plain");&lt;BR /&gt;OutputStream outputStream = contentWriter.getContentOutputStream();&lt;BR /&gt;PrintWriter printWriter = new PrintWriter(outputStream);&lt;BR /&gt;&lt;BR /&gt;//printWriter.println(logLine); // Replaces the whole content with logLine.&lt;BR /&gt;//printWriter.append(logLine); // Replaces the whole content with logLine.&lt;BR /&gt;printWriter.write(logLine, (int) contentWriter.getSize(), logLine.length());&amp;nbsp; // Replaces the whole content with logLine.&lt;BR /&gt;&lt;BR /&gt;printWriter.flush();&lt;BR /&gt;printWriter.close();&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;BR /&gt;&lt;SPAN&gt;Am I missing something fundamental here?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 21 Jan 2009 14:24:23 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-archive/how-to-update-content-with-contentwriter-class/m-p/132947#M93376</guid>
      <dc:creator>tommorris</dc:creator>
      <dc:date>2009-01-21T14:24:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to update content with ContentWriter class</title>
      <link>https://connect.hyland.com/t5/alfresco-archive/how-to-update-content-with-contentwriter-class/m-p/132948#M93377</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Solved this problem. Wasn't thinking properly. Silly me.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Simplified code working example:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="language-none line-numbers"&gt;&lt;CODE&gt;&lt;BR /&gt;ContentWriter contentWriter = contentService.getWriter(nodeCurrentLogFile, ContentModel.PROP_CONTENT, true);&lt;BR /&gt;contentWriter.setMimetype("text/plain");&lt;BR /&gt;FileChannel fileChannel = contentWriter.getFileChannel(false);&lt;BR /&gt;ByteBuffer bf = ByteBuffer.wrap(logLine.getBytes());&lt;BR /&gt;fileChannel.position(contentWriter.getSize());&lt;BR /&gt;fileChannel.write(bf);&lt;BR /&gt;fileChannel.force(false);&lt;BR /&gt;fileChannel.close();&lt;BR /&gt;&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 21 Jan 2009 16:55:00 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-archive/how-to-update-content-with-contentwriter-class/m-p/132948#M93377</guid>
      <dc:creator>tommorris</dc:creator>
      <dc:date>2009-01-21T16:55:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to update content with ContentWriter class</title>
      <link>https://connect.hyland.com/t5/alfresco-archive/how-to-update-content-with-contentwriter-class/m-p/132949#M93378</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm attempting to do this, but having tried both approaches shown above (FileChannel, PrintWriter), although the write appears to complete, I then get the following exception shown in the log, and no data is present in the file&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;DIV class=""&gt;&lt;P class="" data-darkreader-inline-bgcolor="" style="box-sizing: border-box; margin: 0px; padding: 0px 15px; cursor: pointer; background-color: #c5cae9;"&gt;2019-06-05 09:04:57,497 ERROR [extensions.webscripts.AbstractRuntime] [http-nio-8080-exec-7] Exception from executeScript: Transaction silently rolled back because it has been marked as rollback-only&lt;/P&gt;&lt;P class="" data-darkreader-inline-bgcolor="" style="box-sizing: border-box; margin: 0px; padding: 0px 15px; cursor: pointer; background-color: #c5cae9;"&gt;&lt;/P&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 05 Jun 2019 09:08:48 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-archive/how-to-update-content-with-contentwriter-class/m-p/132949#M93378</guid>
      <dc:creator>afielden</dc:creator>
      <dc:date>2019-06-05T09:08:48Z</dc:date>
    </item>
  </channel>
</rss>

