Пример #1
0
 static {
   // avoid security issues
   final StringBuilderWriter buf = new StringBuilderWriter(4);
   final PrintWriter out = new PrintWriter(buf);
   out.println();
   LINE_SEPARATOR = buf.toString();
   out.close();
 }
Пример #2
0
  public static String domToString(Node node) {
    try {
      Transformer transformer = TransformerUtils.getXMLIdentityTransformer();
      DOMSource source = new DOMSource(node);

      StringBuilderWriter writer = new StringBuilderWriter();
      transformer.transform(source, new StreamResult(writer));
      return writer.toString();
    } catch (TransformerException e) {
      throw new OXFException(e);
    }
  }
Пример #3
0
    @Override
    public Generator addStackTrace(final Throwable throwable) throws Exception {
      if (throwable != null) {
        if (isDetailedExceptionOutputType()) {
          // Use the identity of the throwable to determine uniqueness
          final Map<Throwable, Integer> seen = new IdentityHashMap<>();
          addStackTraceDetail(throwable, seen);
        }

        if (isFormattedExceptionOutputType()) {
          final StringBuilderWriter writer = new StringBuilderWriter();
          throwable.printStackTrace(new PrintWriter(writer));
          add(getKey(Key.STACK_TRACE), writer.toString());
        }
      }

      return this;
    }
Пример #4
0
 public static String readStreamAsString(Reader reader) throws IOException {
   final StringBuilderWriter writer = new StringBuilderWriter();
   copyStream(reader, writer);
   return writer.toString();
 }
Пример #5
0
 /**
  * Get the contents of an <code>InputStream</code> as a String using the specified character
  * encoding.
  *
  * <p>Character encoding names can be found at <a
  * href="http://www.iana.org/assignments/character-sets">IANA</a>.
  *
  * <p>This method buffers the input internally, so there is no need to use a <code>
  * BufferedInputStream</code>.
  *
  * @param input the <code>InputStream</code> to read from
  * @param encoding the encoding to use, null means platform default
  * @return the requested String
  * @throws NullPointerException if the input is null
  * @throws IOException if an I/O error occurs
  */
 public static String toString(final InputStream input, final String encoding) throws IOException {
   final StringBuilderWriter sw = new StringBuilderWriter();
   copy(input, sw, encoding);
   return sw.toString();
 }
Пример #6
0
 /**
  * Get the contents of a <code>Reader</code> as a String.
  *
  * <p>This method buffers the input internally, so there is no need to use a <code>BufferedReader
  * </code>.
  *
  * @param input the <code>Reader</code> to read from
  * @return the requested String
  * @throws NullPointerException if the input is null
  * @throws IOException if an I/O error occurs
  */
 public static String toString(final Reader input) throws IOException {
   final StringBuilderWriter sw = new StringBuilderWriter();
   copy(input, sw);
   return sw.toString();
 }