SQL State: 42703 error when applying fileDocument.setContents

0
Trying to come up with a workaround solution for the (understandable) fact that Mendix XML is created without linefeeds I am getting the contents of the XML, adding the linefeeds and then trying to set the contents of the file. However, I then get the SQL error: Exception occurred while updating data. (SQL State: 42703, Error Code: 0). Can it be that I am not setting the length parameter correctly with the buff.length value? The code (and any suggestions to improve are appreciated): ByteArrayOutputStream baos = new ByteArrayOutputStream(); InputStream is = Core.getFileDocumentContent(this.getContext(), fileDocument.getMendixObject()); StringWriter writer = new StringWriter(); IOUtils.copy(is, writer, "UTF-8"); is.close(); String xml = writer.toString(); try { document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new ByteArrayInputStream(xml.getBytes())).getDocumentElement(); keepDeclaration = xml.startsWith("<?xml"); } catch (Exception e) { e.printStackTrace(); } try { DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance(); DOMImplementationLS impl = (DOMImplementationLS)registry.getDOMImplementation("LS"); LSSerializer lsWriter = impl.createLSSerializer(); lsWriter.getDomConfig().setParameter("format-pretty-print", true); // Set this to true if the output needs to be beautified. lsWriter.getDomConfig().setParameter("xml-declaration", keepDeclaration); // Set this to true if the declaration is needed to be outputted. ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); Source xmlSource = new DOMSource(document); Result outputTarget = new StreamResult(outputStream); TransformerFactory.newInstance().newTransformer().transform(xmlSource, outputTarget); InputStream istr = new ByteArrayInputStream(outputStream.toByteArray()); byte[] buff = baos.toByteArray(); outputStream.close(); fileDocument.setContents(this.getContext(), istr, buff.length);
asked
1 answers
5

Normally I use Core.storeFileDocumentContent

answered