Tabnine Logo
StringWriter.toString
Code IndexAdd Tabnine to your IDE (free)

How to use
toString
method
in
java.io.StringWriter

Best Java code snippets using java.io.StringWriter.toString (Showing top 20 results out of 55,548)

Refine searchRefine arrow

  • StringWriter.<init>
  • PrintWriter.<init>
  • StringWriter.write
  • PrintWriter.println
  • PrintWriter.close
  • StreamResult.<init>
  • Test.<init>
  • PrintWriter.flush
origin: stackoverflow.com

 StringWriter writer = new StringWriter();
IOUtils.copy(inputStream, writer, encoding);
String theString = writer.toString();
origin: stackoverflow.com

 StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
e.printStackTrace(pw);
sw.toString(); // stack trace as a string
origin: apache/incubator-dubbo

public static String toString(Throwable e) {
  StringWriter w = new StringWriter();
  PrintWriter p = new PrintWriter(w);
  p.print(e.getClass().getName() + ": ");
  if (e.getMessage() != null) {
    p.print(e.getMessage() + "\n");
  }
  p.println();
  try {
    e.printStackTrace(p);
    return w.toString();
  } finally {
    p.close();
  }
}
origin: spring-projects/spring-framework

@Test
public void readCorrect() throws Exception {
  Transformer transformer = TransformerFactory.newInstance().newTransformer();
  StAXSource source = new StAXSource(streamReader);
  StringWriter writer = new StringWriter();
  transformer.transform(source, new StreamResult(writer));
  Predicate<Node> nodeFilter = n ->
      n.getNodeType() != Node.DOCUMENT_TYPE_NODE && n.getNodeType() != Node.PROCESSING_INSTRUCTION_NODE;
  assertThat(writer.toString(), isSimilarTo(XML).withNodeFilter(nodeFilter));
}
origin: alibaba/druid

public static String read(Reader reader) {
  try {
    StringWriter writer = new StringWriter();
    char[] buffer = new char[DEFAULT_BUFFER_SIZE];
    int n = 0;
    while (-1 != (n = reader.read(buffer))) {
      writer.write(buffer, 0, n);
    }
    return writer.toString();
  } catch (IOException ex) {
    throw new IllegalStateException("read error", ex);
  }
}
origin: spring-projects/spring-framework

@Test
public void copyFromReader() throws IOException {
  String content = "content";
  StringReader in = new StringReader(content);
  StringWriter out = new StringWriter();
  int count = FileCopyUtils.copy(in, out);
  assertEquals(content.length(), count);
  assertEquals(content, out.toString());
}
origin: ReactiveX/RxJava

@Test
public void printStackTrace() {
  StringWriter sw = new StringWriter();
  PrintWriter pw = new PrintWriter(sw);
  new CompositeException(new TestException()).printStackTrace(pw);
  assertTrue(sw.toString().contains("TestException"));
}
origin: alibaba/fastjson

private static String toString(org.w3c.dom.Node node) {
  try {
    TransformerFactory transFactory = TransformerFactory.newInstance();
    Transformer transformer = transFactory.newTransformer();
    DOMSource domSource = new DOMSource(node);
    StringWriter out = new StringWriter();
    transformer.transform(domSource, new StreamResult(out));
    return out.toString();
  } catch (TransformerException e) {
    throw new JSONException("xml node to string error", e);
  }
}
origin: apache/incubator-dubbo

public static String toString(Throwable e) {
  StringWriter w = new StringWriter();
  PrintWriter p = new PrintWriter(w);
  p.print(e.getClass().getName() + ": ");
  if (e.getMessage() != null) {
    p.print(e.getMessage() + "\n");
  }
  p.println();
  try {
    e.printStackTrace(p);
    return w.toString();
  } finally {
    p.close();
  }
}
origin: spring-projects/spring-framework

@Test
public void namespacePrefixes() throws Exception {
  Assume.assumeTrue(wwwSpringframeworkOrgIsAccessible());
  StringWriter stringWriter = new StringWriter();
  AbstractStaxHandler handler = createStaxHandler(new StreamResult(stringWriter));
  xmlReader.setContentHandler(handler);
  xmlReader.setProperty("http://xml.org/sax/properties/lexical-handler", handler);
  xmlReader.setFeature("http://xml.org/sax/features/namespaces", true);
  xmlReader.setFeature("http://xml.org/sax/features/namespace-prefixes", true);
  xmlReader.parse(new InputSource(new StringReader(COMPLEX_XML)));
  assertThat(stringWriter.toString(), isSimilarTo(COMPLEX_XML).withNodeFilter(nodeFilter));
}
origin: alibaba/druid

public static String getStackTrace(Throwable ex) {
  StringWriter buf = new StringWriter();
  ex.printStackTrace(new PrintWriter(buf));
  return buf.toString();
}
origin: libgdx/libgdx

/** Copy the data from an {@link InputStream} to a string using the specified charset.
 * @param estimatedSize Used to allocate the output buffer to possibly avoid an array copy.
 * @param charset May be null to use the platform's default charset. */
public static String copyStreamToString (InputStream input, int estimatedSize, String charset) throws IOException {
  InputStreamReader reader = charset == null ? new InputStreamReader(input) : new InputStreamReader(input, charset);
  StringWriter writer = new StringWriter(Math.max(0, estimatedSize));
  char[] buffer = new char[DEFAULT_BUFFER_SIZE];
  int charsRead;
  while ((charsRead = reader.read(buffer)) != -1) {
    writer.write(buffer, 0, charsRead);
  }
  return writer.toString();
}
origin: spring-projects/spring-framework

@Test
public void marshalStaxResultXMLStreamWriter() throws Exception {
  XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
  StringWriter writer = new StringWriter();
  XMLStreamWriter streamWriter = outputFactory.createXMLStreamWriter(writer);
  Result result = StaxUtils.createStaxResult(streamWriter);
  marshaller.marshal(flight, result);
  assertThat("Marshaller writes invalid StreamResult", writer.toString(), isSimilarTo(EXPECTED_STRING));
}
origin: spring-projects/spring-framework

@Test
public void testExceptionStackTrace() {
  JMSException jmsEx = new JMSException("could not connect");
  Exception innerEx = new Exception("host not found");
  jmsEx.setLinkedException(innerEx);
  JmsException springJmsEx = JmsUtils.convertJmsAccessException(jmsEx);
  StringWriter sw = new StringWriter();
  PrintWriter out = new PrintWriter(sw);
  springJmsEx.printStackTrace(out);
  String trace = sw.toString();
  assertTrue("inner jms exception not found", trace.indexOf("host not found") > 0);
}
origin: stackoverflow.com

 TransformerFactory transFactory = TransformerFactory.newInstance();
Transformer transformer = transFactory.newTransformer();
StringWriter buffer = new StringWriter();
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
transformer.transform(new DOMSource(node),
   new StreamResult(buffer));
String str = buffer.toString();
origin: facebook/stetho

private static String formatThrowable(Throwable t) {
 StringWriter buf = new StringWriter();
 PrintWriter writer = new PrintWriter(buf);
 t.printStackTrace();
 writer.flush();
 return buf.toString();
}
origin: spring-projects/spring-framework

@Test
public void noNamespacePrefixes() throws Exception {
  Assume.assumeTrue(wwwSpringframeworkOrgIsAccessible());
  StringWriter stringWriter = new StringWriter();
  AbstractStaxHandler handler = createStaxHandler(new StreamResult(stringWriter));
  xmlReader.setContentHandler(handler);
  xmlReader.setProperty("http://xml.org/sax/properties/lexical-handler", handler);
  xmlReader.setFeature("http://xml.org/sax/features/namespaces", true);
  xmlReader.setFeature("http://xml.org/sax/features/namespace-prefixes", false);
  xmlReader.parse(new InputSource(new StringReader(COMPLEX_XML)));
  assertThat(stringWriter.toString(), isSimilarTo(COMPLEX_XML).withNodeFilter(nodeFilter));
}
origin: alibaba/druid

public String getLastStatementStatckTrace() {
  if (lastStatementStatckTraceException == null) {
    return null;
  }
  StringWriter buf = new StringWriter();
  lastStatementStatckTraceException.printStackTrace(new PrintWriter(buf));
  return buf.toString();
}
origin: libgdx/libgdx

/** Copy the data from an {@link InputStream} to a string using the specified charset.
 * @param estimatedSize Used to allocate the output buffer to possibly avoid an array copy.
 * @param charset May be null to use the platform's default charset. */
public static String copyStreamToString (InputStream input, int estimatedSize, String charset) throws IOException {
  InputStreamReader reader = charset == null ? new InputStreamReader(input) : new InputStreamReader(input, charset);
  StringWriter writer = new StringWriter(Math.max(0, estimatedSize));
  char[] buffer = new char[DEFAULT_BUFFER_SIZE];
  int charsRead;
  while ((charsRead = reader.read(buffer)) != -1) {
    writer.write(buffer, 0, charsRead);
  }
  return writer.toString();
}
origin: spring-projects/spring-framework

@Test
public void marshalStaxResultStreamWriter() throws Exception {
  XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
  StringWriter writer = new StringWriter();
  XMLStreamWriter streamWriter = outputFactory.createXMLStreamWriter(writer);
  Result result = StaxUtils.createStaxResult(streamWriter);
  marshaller.marshal(flights, result);
  assertThat("Marshaller writes invalid StreamResult", writer.toString(), isSimilarTo(EXPECTED_STRING));
}
java.ioStringWritertoString

Javadoc

Gets a copy of the contents of this writer as a string.

Popular methods of StringWriter

  • <init>
    Constructs a new StringWriter which has a StringBufferallocated with a size of initialSize character
  • getBuffer
    Return the string buffer itself.
  • write
    Writes count characters starting at offset in bufto this writer's StringBuffer.
  • close
    Calling this method has no effect. In contrast to most Writer subclasses, the other methods in Strin
  • flush
    Calling this method has no effect.
  • append

Popular in Java

  • Creating JSON documents from java classes using gson
  • onRequestPermissionsResult (Fragment)
  • scheduleAtFixedRate (Timer)
  • getExternalFilesDir (Context)
  • Color (java.awt)
    The Color class is used to encapsulate colors in the default sRGB color space or colors in arbitrary
  • Rectangle (java.awt)
    A Rectangle specifies an area in a coordinate space that is enclosed by the Rectangle object's top-
  • Callable (java.util.concurrent)
    A task that returns a result and may throw an exception. Implementors define a single method with no
  • BasicDataSource (org.apache.commons.dbcp)
    Basic implementation of javax.sql.DataSource that is configured via JavaBeans properties. This is no
  • Table (org.hibernate.mapping)
    A relational table
  • Option (scala)
  • Github Copilot alternatives
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now