Tabnine Logo
StringWriter.<init>
Code IndexAdd Tabnine to your IDE (free)

How to use
java.io.StringWriter
constructor

Best Java code snippets using java.io.StringWriter.<init> (Showing top 20 results out of 65,016)

Refine searchRefine arrow

  • StringWriter.toString
  • PrintWriter.<init>
  • StringWriter.getBuffer
  • Transformer.transform
  • StreamResult.<init>
  • PrintWriter.println
  • PrintWriter.close
  • StringWriter.write
  • TransformerFactory.newTransformer
  • TransformerFactory.newInstance
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: 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: 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: apache/incubator-dubbo

/**
 * read string.
 *
 * @param reader Reader instance.
 * @return String.
 * @throws IOException
 */
public static String read(Reader reader) throws IOException {
  StringWriter writer = new StringWriter();
  try {
    write(reader, writer);
    return writer.getBuffer().toString();
  } finally {
    writer.close();
  }
}
origin: stanfordnlp/CoreNLP

public String toSummaryString() {
 StringWriter sw = new StringWriter();
 PrintWriter pw = new PrintWriter(sw);
 pw.println("Number of data points: " + size());
 pw.println("Number of active feature tokens: " + numFeatureTokens());
 pw.println("Number of active feature types:" + numFeatureTypes());
 return pw.toString();
}
origin: spring-projects/spring-framework

@Test
public void streamReaderSourceToStreamResult() throws Exception {
  XMLStreamReader streamReader = inputFactory.createXMLStreamReader(new StringReader(XML));
  StaxSource source = new StaxSource(streamReader);
  assertEquals("Invalid streamReader returned", streamReader, source.getXMLStreamReader());
  assertNull("EventReader returned", source.getXMLEventReader());
  StringWriter writer = new StringWriter();
  transformer.transform(source, new StreamResult(writer));
  assertThat("Invalid result", writer.toString(), isSimilarTo(XML));
}
origin: zzz40500/GsonFormat

private void handleDataError(Exception e2) {
  e2.printStackTrace();
  Writer writer = new StringWriter();
  PrintWriter printWriter = new PrintWriter(writer);
  e2.printStackTrace(printWriter);
  printWriter.close();
  operator.showError(Error.DATA_ERROR);
  operator.setErrorInfo(writer.toString());
}
origin: skylot/jadx

public static String getStackTrace(Throwable throwable) {
  if (throwable == null) {
    return "";
  }
  StringWriter sw = new StringWriter();
  PrintWriter pw = new PrintWriter(sw, true);
  filterRecursive(throwable);
  throwable.printStackTrace(pw);
  return sw.getBuffer().toString();
}
origin: JakeWharton/butterknife

private void logParsingError(Element element, Class<? extends Annotation> annotation,
  Exception e) {
 StringWriter stackTrace = new StringWriter();
 e.printStackTrace(new PrintWriter(stackTrace));
 error(element, "Unable to parse @%s binding.\n\n%s", annotation.getSimpleName(), stackTrace);
}
origin: spring-projects/spring-framework

@Test
public void marshalStreamResultWriter() throws Exception {
  StringWriter writer = new StringWriter();
  StreamResult result = new StreamResult(writer);
  marshaller.marshal(flights, result);
  assertThat("Marshaller writes invalid StreamResult", writer.toString(), isSimilarTo(EXPECTED_STRING));
}
origin: commons-io/commons-io

@Test
public void testFlush() throws IOException {
  final StringWriter writer = new StringWriter();
  final WriterOutputStream out = new WriterOutputStream(writer, "us-ascii", 1024, false);
  out.write("abc".getBytes("us-ascii"));
  assertEquals(0, writer.getBuffer().length());
  out.flush();
  assertEquals("abc", writer.toString());
  out.close();
}
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: 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: 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: apache/incubator-dubbo

/**
 * read string.
 *
 * @param reader Reader instance.
 * @return String.
 * @throws IOException
 */
public static String read(Reader reader) throws IOException {
  StringWriter writer = new StringWriter();
  try {
    write(reader, writer);
    return writer.getBuffer().toString();
  } finally {
    writer.close();
  }
}
origin: google/guava

@GwtIncompatible // Writer
private static void testStreamingEncodes(BaseEncoding encoding, String decoded, String encoded)
  throws IOException {
 StringWriter writer = new StringWriter();
 OutputStream encodingStream = encoding.encodingStream(writer);
 encodingStream.write(decoded.getBytes(UTF_8));
 encodingStream.close();
 assertThat(writer.toString()).isEqualTo(encoded);
}
origin: spring-projects/spring-framework

@Test
public void eventReaderSourceToStreamResult() throws Exception {
  XMLEventReader eventReader = inputFactory.createXMLEventReader(new StringReader(XML));
  StaxSource source = new StaxSource(eventReader);
  assertEquals("Invalid eventReader returned", eventReader, source.getXMLEventReader());
  assertNull("StreamReader returned", source.getXMLStreamReader());
  StringWriter writer = new StringWriter();
  transformer.transform(source, new StreamResult(writer));
  assertThat("Invalid result", writer.toString(), isSimilarTo(XML));
}
java.ioStringWriter<init>

Javadoc

Constructs a new StringWriter which has a StringBufferallocated with the default size of 16 characters. The StringBuffer is also the lock used to synchronize access to this writer.

Popular methods of StringWriter

  • toString
    Gets a copy of the contents of this writer as a string.
  • 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)
  • Top 12 Jupyter Notebook extensions
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