Java Code Examples for java.io.StringWriter.getBuffer()

The following are Jave code examples for showing how to use getBuffer() of the java.io.StringWriter class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: BiglyBT   File: BEncoder.java   View Source Code Vote up 6 votes
protected StringBuffer
encode(
	Map		map,
	boolean	simple )
{
	StringWriter	writer = new StringWriter(1024);

	setOutputWriter( writer );

	setGenericSimple( simple );

	writeGeneric( map );

	flushOutputStream();

	return( writer.getBuffer());
}
 
Example 2
Project: GitHub   File: JSONObject.java   View Source Code Vote up 5 votes
/**
 * Produce a string in double quotes with backslash sequences in all the
 * right places. A backslash will be inserted within </, producing <\/,
 * allowing JSON text to be delivered in HTML. In JSON text, a string cannot
 * contain a control character or an unescaped quote or backslash.
 *
 * @param string
 *            A String
 * @return A String correctly formatted for insertion in a JSON text.
 */
public static String quote(String string) {
    StringWriter sw = new StringWriter();
    synchronized (sw.getBuffer()) {
        try {
            return quote(string, sw).toString();
        } catch (IOException ignored) {
            // will never happen - we are writing to a string writer
            return "";
        }
    }
}
 
Example 3
Project: one   File: ExceptionUtils.java   View Source Code Vote up 5 votes
public static String getTraceInfo(Throwable t) {
    StringWriter stringWriter = new StringWriter();
    PrintWriter writer = new PrintWriter(stringWriter);
    t.printStackTrace(writer);
    StringBuffer buffer = stringWriter.getBuffer();
    return buffer.toString();
}
 
Example 4
Project: javaide   File: TwoColumnOutput.java   View Source Code Vote up 5 votes
/**
 * Constructs an instance.
 *
 * @param out {@code non-null;} writer to send final output to
 * @param leftWidth {@code > 0;} width of the left column, in characters
 * @param rightWidth {@code > 0;} width of the right column, in characters
 * @param spacer {@code non-null;} spacer string to sit between the two columns
 */
public TwoColumnOutput(Writer out, int leftWidth, int rightWidth,
                       String spacer) {
    if (out == null) {
        throw new NullPointerException("out == null");
    }

    if (leftWidth < 1) {
        throw new IllegalArgumentException("leftWidth < 1");
    }

    if (rightWidth < 1) {
        throw new IllegalArgumentException("rightWidth < 1");
    }

    if (spacer == null) {
        throw new NullPointerException("spacer == null");
    }

    StringWriter leftWriter = new StringWriter(1000);
    StringWriter rightWriter = new StringWriter(1000);

    this.out = out;
    this.leftWidth = leftWidth;
    this.leftBuf = leftWriter.getBuffer();
    this.rightBuf = rightWriter.getBuffer();
    this.leftColumn = new IndentingWriter(leftWriter, leftWidth);
    this.rightColumn =
        new IndentingWriter(rightWriter, rightWidth, spacer);
}
 
Example 5
Project: Banmanager   File: JSONObject.java   View Source Code Vote up 5 votes
/**
 * Produce a string in double quotes with backslash sequences in all the
 * right places. A backslash will be inserted within </, producing <\/,
 * allowing JSON text to be delivered in HTML. In JSON text, a string cannot
 * contain a control character or an unescaped quote or backslash.
 *
 * @param string A String
 * @return A String correctly formatted for insertion in a JSON text.
 */
public static String quote(String string) {
    StringWriter sw = new StringWriter();
    synchronized (sw.getBuffer()) {
        try {
            return quote(string, sw).toString();
        } catch (IOException ignored) {
            // will never happen - we are writing to a string writer
            return "";
        }
    }
}
 
Example 6
Project: monarch   File: TypedJson.java   View Source Code Vote up 5 votes
public String toString() {
  StringWriter w = new StringWriter();
  synchronized (w.getBuffer()) {
    try {
      return this.write(w).toString();
    } catch (Exception e) {
      return null;
    }
  }
}
 
Example 7
Project: JOsu   File: JSONObject.java   View Source Code Vote up 5 votes
/**
 * Produce a string in double quotes with backslash sequences in all the
 * right places. A backslash will be inserted within </, producing <\/,
 * allowing JSON text to be delivered in HTML. In JSON text, a string cannot
 * contain a control character or an unescaped quote or backslash.
 *
 * @param string
 *            A String
 * @return A String correctly formatted for insertion in a JSON text.
 */
public static String quote(String string) {
    StringWriter sw = new StringWriter();
    synchronized (sw.getBuffer()) {
        try {
            return quote(string, sw).toString();
        } catch (IOException ignored) {
            // will never happen - we are writing to a string writer
            return "";
        }
    }
}
 
Example 8
Project: apollo-custom   File: PropertiesUtil.java   View Source Code Vote up 5 votes
/**
 * Transform the properties to string format
 * @param properties the properties object
 * @return the string containing the properties
 * @throws IOException
 */
public static String toString(Properties properties) throws IOException {
  StringWriter writer = new StringWriter();
  properties.store(writer, null);
  StringBuffer stringBuffer = writer.getBuffer();
  filterPropertiesComment(stringBuffer);
  return stringBuffer.toString();
}
 
Example 9
Project: GitHub   File: JSONObject.java   View Source Code Vote up 3 votes
/**
 * Make a prettyprinted JSON text of this JSONObject.
 * <p>
 * Warning: This method assumes that the data structure is acyclical.
 *
 * @param indentFactor
 *            The number of spaces to add to each level of indentation.
 * @return a printable, displayable, portable, transmittable representation
 *         of the object, beginning with <code>{</code>&nbsp;<small>(left
 *         brace)</small> and ending with <code>}</code>&nbsp;<small>(right
 *         brace)</small>.
 * @throws JSONException
 *             If the object contains an invalid number.
 */
public String toString(int indentFactor) throws JSONException {
    StringWriter w = new StringWriter();
    synchronized (w.getBuffer()) {
        return this.write(w, indentFactor, 0).toString();
    }
}
 
Example 10
Project: GitHub   File: JSONArray.java   View Source Code Vote up 3 votes
/**
 * Make a prettyprinted JSON text of this JSONArray. Warning: This method
 * assumes that the data structure is acyclical.
 *
 * @param indentFactor
 *            The number of spaces to add to each level of indentation.
 * @return a printable, displayable, transmittable representation of the
 *         object, beginning with <code>[</code>&nbsp;<small>(left
 *         bracket)</small> and ending with <code>]</code>
 *         &nbsp;<small>(right bracket)</small>.
 * @throws JSONException
 */
public String toString(int indentFactor) throws JSONException {
    StringWriter sw = new StringWriter();
    synchronized (sw.getBuffer()) {
        return this.write(sw, indentFactor, 0).toString();
    }
}
 
Example 11
Project: FlarumSDK   File: JSONObject.java   View Source Code Vote up 3 votes
/**
 * Make a pretty-printed JSON text of this JSONObject.
 * 
 * <p>If <code>indentFactor > 0</code> and the {@link JSONObject}
 * has only one key, then the object will be output on a single line:
 * <pre>{@code {"key": 1}}</pre>
 * 
 * <p>If an object has 2 or more keys, then it will be output across
 * multiple lines: <code><pre>{
 *  "key1": 1,
 *  "key2": "value 2",
 *  "key3": 3
 * }</pre></code>
 * <p><b>
 * Warning: This method assumes that the data structure is acyclical.
 * </b>
 *
 * @param indentFactor
 *            The number of spaces to add to each level of indentation.
 * @return a printable, displayable, portable, transmittable representation
 *         of the object, beginning with <code>{</code>&nbsp;<small>(left
 *         brace)</small> and ending with <code>}</code>&nbsp;<small>(right
 *         brace)</small>.
 * @throws JSONException
 *             If the object contains an invalid number.
 */
public String toString(int indentFactor) throws JSONException {
    StringWriter w = new StringWriter();
    synchronized (w.getBuffer()) {
        return this.write(w, indentFactor, 0).toString();
    }
}
 
Example 12
Project: CodeGenerate   File: JSONObject.java   View Source Code Vote up 3 votes
/**
 * Make a prettyprinted JSON text of this JSONObject.
 * <p>
 * Warning: This method assumes that the data structure is acyclical.
 *
 * @param indentFactor
 *            The number of spaces to add to each level of indentation.
 * @return a printable, displayable, portable, transmittable representation
 *         of the object, beginning with <code>{</code>&nbsp;<small>(left
 *         brace)</small> and ending with <code>}</code>&nbsp;<small>(right
 *         brace)</small>.
 * @throws JSONException
 *             If the object contains an invalid number.
 */
public String toString(int indentFactor) throws JSONException {
    StringWriter w = new StringWriter();
    synchronized (w.getBuffer()) {
        return this.write(w, indentFactor, 0).toString();
    }
}
 
Example 13
Project: encdroidMC   File: JSONObject.java   View Source Code Vote up 3 votes
/**
 * Make a prettyprinted JSON text of this JSONObject.
 * <p>
 * Warning: This method assumes that the data structure is acyclical.
 *
 * @param indentFactor
 *            The number of spaces to add to each level of indentation.
 * @return a printable, displayable, portable, transmittable representation
 *         of the object, beginning with <code>{</code>&nbsp;<small>(left
 *         brace)</small> and ending with <code>}</code>&nbsp;<small>(right
 *         brace)</small>.
 * @throws JSONException
 *             If the object contains an invalid number.
 */
public String toString(int indentFactor) throws JSONException {
    StringWriter w = new StringWriter();
    synchronized (w.getBuffer()) {
        return this.write(w, indentFactor, 0).toString();
    }
}
 
Example 14
Project: CPG   File: JSONObject.java   View Source Code Vote up 3 votes
/**
 * Make a prettyprinted JSON text of this JSONObject.
 * <p>
 * Warning: This method assumes that the data structure is acyclical.
 *
 * @param indentFactor
 *            The number of spaces to add to each level of indentation.
 * @return a printable, displayable, portable, transmittable representation
 *         of the object, beginning with <code>{</code>&nbsp;<small>(left
 *         brace)</small> and ending with <code>}</code>&nbsp;<small>(right
 *         brace)</small>.
 * @throws JSONException
 *             If the object contains an invalid number.
 */
public String toString(int indentFactor) throws JSONException {
    StringWriter w = new StringWriter();
    synchronized (w.getBuffer()) {
        return this.write(w, indentFactor, 0).toString();
    }
}
 
Example 15
Project: qcloudClient   File: JSONObject.java   View Source Code Vote up 3 votes
/**
 * Make a prettyprinted JSON text of this JSONObject.
 * <p>
 * Warning: This method assumes that the data structure is acyclical.
 *
 * @param indentFactor
 *            The number of spaces to add to each level of indentation.
 * @return a printable, displayable, portable, transmittable representation
 *         of the object, beginning with <code>{</code>&nbsp;<small>(left
 *         brace)</small> and ending with <code>}</code>&nbsp;<small>(right
 *         brace)</small>.
 * @throws JSONException
 *             If the object contains an invalid number.
 */
public String toString(int indentFactor) throws JSONException {
    StringWriter w = new StringWriter();
    synchronized (w.getBuffer()) {
        return this.write(w, indentFactor, 0).toString();
    }
}
 
Example 16
Project: authlib-injector   File: JSONArray.java   View Source Code Vote up 3 votes
/**
 * Make a prettyprinted JSON text of this JSONArray. Warning: This method
 * assumes that the data structure is acyclical.
 *
 * @param indentFactor
 *            The number of spaces to add to each level of
 *            indentation.
 * @return a printable, displayable, transmittable representation of the
 *         object, beginning with <code>[</code>&nbsp;<small>(left
 *         bracket)</small> and ending with <code>]</code> &nbsp;
 *         <small>(right bracket)</small>.
 * @throws JSONException
 *             If the data structure is not acyclical
 */
public String toString(int indentFactor) throws JSONException {
	StringWriter sw = new StringWriter();
	synchronized (sw.getBuffer()) {
		return this.write(sw, indentFactor, 0).toString();
	}
}
 
Example 17
Project: marathonv5   File: JSONArray.java   View Source Code Vote up 3 votes
/**
 * Make a prettyprinted JSON text of this JSONArray. Warning: This method
 * assumes that the data structure is acyclical.
 * 
 * @param indentFactor
 *            The number of spaces to add to each level of indentation.
 * @return a printable, displayable, transmittable representation of the
 *         object, beginning with <code>[</code>&nbsp;<small>(left
 *         bracket)</small> and ending with <code>]</code> &nbsp;
 *         <small>(right bracket)</small>.
 * @throws JSONException
 */
public String toString(int indentFactor) throws JSONException {
    StringWriter sw = new StringWriter();
    synchronized (sw.getBuffer()) {
        return this.write(sw, indentFactor, 0).toString();
    }
}
 
Example 18
Project: JOsu   File: JSONObject.java   View Source Code Vote up 3 votes
/**
 * Make a prettyprinted JSON text of this JSONObject.
 * <p>
 * Warning: This method assumes that the data structure is acyclical.
 *
 * @param indentFactor
 *            The number of spaces to add to each level of indentation.
 * @return a printable, displayable, portable, transmittable representation
 *         of the object, beginning with <code>{</code>&nbsp;<small>(left
 *         brace)</small> and ending with <code>}</code>&nbsp;<small>(right
 *         brace)</small>.
 * @throws JSONException
 *             If the object contains an invalid number.
 */
public String toString(int indentFactor) throws JSONException {
    StringWriter w = new StringWriter();
    synchronized (w.getBuffer()) {
        return this.write(w, indentFactor, 0).toString();
    }
}
 
Example 19
Project: encdroidMC   File: JSONArray.java   View Source Code Vote up 3 votes
/**
 * Make a prettyprinted JSON text of this JSONArray. Warning: This method
 * assumes that the data structure is acyclical.
 *
 * @param indentFactor
 *            The number of spaces to add to each level of indentation.
 * @return a printable, displayable, transmittable representation of the
 *         object, beginning with <code>[</code>&nbsp;<small>(left
 *         bracket)</small> and ending with <code>]</code>
 *         &nbsp;<small>(right bracket)</small>.
 * @throws JSONException
 */
public String toString(int indentFactor) throws JSONException {
    StringWriter sw = new StringWriter();
    synchronized (sw.getBuffer()) {
        return this.write(sw, indentFactor, 0).toString();
    }
}
 
Example 20
Project: openrouteservice   File: JSONArray.java   View Source Code Vote up 3 votes
/**
 * Make a prettyprinted JSON text of this JSONArray. Warning: This method
 * assumes that the data structure is acyclical.
 *
 * @param indentFactor
 *            The number of spaces to add to each level of indentation.
 * @return a printable, displayable, transmittable representation of the
 *         object, beginning with <code>[</code>&nbsp;<small>(left
 *         bracket)</small> and ending with <code>]</code>
 *         &nbsp;<small>(right bracket)</small>.
 * @throws JSONException
 */
public String toString(int indentFactor) throws JSONException {
    StringWriter sw = new StringWriter();
    synchronized (sw.getBuffer()) {
        return this.write(sw, indentFactor, 0).toString();
    }
}