/* Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.camunda.bpm.model.xml.impl.util;

import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;

/**
 * @author Daniel Meyer
 * @author Sebastian Menski
 *
 */
public class IoUtil {

  public static void closeSilently(Closeable closeable) {
    try {
      if (closeable != null) {
        closeable.close();
      }
    } catch (Exception e) {
      // ignored
    }
  }

  /**
   * Convert an {@link InputStream} to a {@link String}
   *
   * @param inputStream the {@link InputStream} to convert
   * @return the resulting {@link String}
   * @throws IOException
   */
  public static String getStringFromInputStream(InputStream inputStream) throws IOException {
    return getStringFromInputStream(inputStream, true);
  }

  /**
   * Convert an {@link InputStream} to a {@link String}
   *
   * @param inputStream the {@link InputStream} to convert
   * @param trim trigger if whitespaces are trimmed in the output
   * @return the resulting {@link String}
   * @throws IOException
   */
  private static String getStringFromInputStream(InputStream inputStream, boolean trim) throws IOException {
    BufferedReader bufferedReader = null;
    StringBuilder stringBuilder = new StringBuilder();
    try {
      bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
      String line;
      while ((line = bufferedReader.readLine()) != null) {
        if (trim) {
          stringBuilder.append(line.trim());
        }
        else {
          stringBuilder.append(line).append("\n");
        }
      }
    }
    finally {
      closeSilently(bufferedReader);
    }

    return stringBuilder.toString();
  }

  /**
   * Converts a {@link OutputStream} to an {@link InputStream} by coping the data directly.
   * WARNING: Do not use for large data (>100MB). Only for testing purpose.
   *
   * @param outputStream the {@link OutputStream} to convert
   * @return the resulting {@link InputStream}
   */
  public static InputStream convertOutputStreamToInputStream(OutputStream outputStream) {
    byte[] data = ((ByteArrayOutputStream) outputStream).toByteArray();
    return new ByteArrayInputStream(data);
  }
}

@@ -610,217 +610,145 @@
 ort 
-java.io.BufferedReader;%0Aimport java.io.ByteArrayInputStream;%0Aimport java.io.ByteArrayOutputStream;%0Aimport java.io.Closeable;%0Aimport java.io.IOException;%0Aimport java.io.InputStream;%0Aimport java.io.Input
+org.w3c.dom.Document;%0A%0Aimport javax.xml.transform.*;%0Aimport javax.xml.transform.dom.DOMSource;%0Aimport javax.xml.transform.stream.
 StreamRe
 ader
@@ -743,20 +743,20 @@
 StreamRe
-ader
+sult
 ;%0Aimport
@@ -764,28 +764,17 @@
 java.io.
-OutputStream
+*
 ;%0A%0A/**%0A 
@@ -2802,11 +2802,776 @@
 ta);%0A  %7D
+%0A%0A  /**%0A   * Converts a %7B@link org.w3c.dom.Document%7D to its String representation%0A   *%0A   * @param document  the XML document to convert%0A   */%0A  public static String convertXmlDocumentToString(Document document) %7B%0A    StringWriter stringWriter = new StringWriter();%0A    try %7B%0A      Transformer transformer = TransformerFactory.newInstance().newTransformer();%0A      transformer.setOutputProperty(OutputKeys.ENCODING, %22UTF-8%22);%0A      transformer.setOutputProperty(OutputKeys.INDENT, %22yes%22);%0A      transformer.transform(new DOMSource(document), new StreamResult(stringWriter));%0A    %7D catch (TransformerConfigurationException e) %7B%0A      e.printStackTrace();%0A    %7D catch (TransformerException e) %7B%0A      e.printStackTrace();%0A    %7D%0A    return stringWriter.toString();%0A  %7D
 %0A%7D%0A

add convert xml to string method