java.io.StringWriter

Here are the examples of the java api class java.io.StringWriter taken from open source projects.

1. AddDep#toEditString()

Project: CoreNLP
Source File: AddDep.java
View license
/**
   * Emits a parseable instruction string.
   */
@Override
public String toEditString() {
    StringWriter buf = new StringWriter();
    buf.write(LABEL);
    buf.write("\t");
    buf.write(Ssurgeon.GOV_NODENAME_ARG);
    buf.write(" ");
    buf.write(govNodeName);
    buf.write("\t");
    buf.write(Ssurgeon.RELN_ARG);
    buf.write(" ");
    buf.write(relation.toString());
    buf.write("\t");
    buf.write(Ssurgeon.NODE_PROTO_ARG);
    buf.write(" ");
    buf.write("\"");
    //  buf.write(newNodePrototype.toString("map")); buf.write("\"\t")
    buf.write(cheapWordToString(newNodePrototype));
    buf.write("\"\t");
    buf.write(Ssurgeon.WEIGHT_ARG);
    buf.write(" ");
    buf.write(String.valueOf(weight));
    return buf.toString();
}

2. AddEdge#toEditString()

Project: CoreNLP
Source File: AddEdge.java
View license
@Override
public String toEditString() {
    StringWriter buf = new StringWriter();
    buf.write(LABEL);
    buf.write("\t");
    buf.write(Ssurgeon.GOV_NODENAME_ARG);
    buf.write(" ");
    buf.write(govName);
    buf.write("\t");
    buf.write(Ssurgeon.DEP_NODENAME_ARG);
    buf.write(" ");
    buf.write(depName);
    buf.write("\t");
    buf.write(Ssurgeon.RELN_ARG);
    buf.write(" ");
    buf.write(relation.toString());
    buf.write("\t");
    buf.write(Ssurgeon.WEIGHT_ARG);
    buf.write(" ");
    buf.write(String.valueOf(weight));
    return buf.toString();
}

3. RemoveEdge#toEditString()

Project: CoreNLP
Source File: RemoveEdge.java
View license
@Override
public String toEditString() {
    StringWriter buf = new StringWriter();
    buf.write(LABEL);
    buf.write("\t");
    buf.write(Ssurgeon.RELN_ARG);
    buf.write(" ");
    buf.write(relation.toString());
    buf.write("\t");
    buf.write(Ssurgeon.GOV_NODENAME_ARG);
    buf.write(" ");
    buf.write(govName);
    buf.write("\t");
    buf.write(Ssurgeon.DEP_NODENAME_ARG);
    buf.write(" ");
    buf.write(depName);
    return buf.toString();
}

4. RemoveNamedEdge#toEditString()

Project: CoreNLP
Source File: RemoveNamedEdge.java
View license
@Override
public String toEditString() {
    StringWriter buf = new StringWriter();
    buf.write(LABEL);
    buf.write("\t");
    buf.write(Ssurgeon.EDGE_NAME_ARG);
    buf.write(" ");
    buf.write(edgeName);
    buf.write("\t");
    buf.write(Ssurgeon.GOV_NODENAME_ARG);
    buf.write(" ");
    buf.write(govName);
    buf.write("\t");
    buf.write(Ssurgeon.DEP_NODENAME_ARG);
    buf.write(" ");
    buf.write(depName);
    return buf.toString();
}

5. SupportJVMRuntimeUtil#memoryUse()

Project: esper
Source File: SupportJVMRuntimeUtil.java
View license
private String memoryUse() {
    StringWriter writer = new StringWriter();
    Runtime runtime = Runtime.getRuntime();
    int mb = 1024 * 1024;
    writer.append("Used Memory MB:");
    writer.append(Double.toString((runtime.totalMemory() - runtime.freeMemory()) / mb));
    writer.append("  Free Memory MB:");
    writer.append(Double.toString(runtime.freeMemory() / mb));
    writer.append("  Total Memory MB:");
    writer.append(Double.toString(runtime.totalMemory() / mb));
    writer.append("  Max Memory:");
    writer.append(Double.toString(runtime.maxMemory() / mb));
    return writer.toString();
}

6. AccessibilityLogEvent#toString()

Project: ferret
Source File: AccessibilityLogEvent.java
View license
public String toString() {
    StringWriter sw = new StringWriter();
    sw.append(getIdentifierId() + "-");
    sw.append(getEventTypeName() + "-");
    sw.append(getwClassName() + "-");
    sw.append(getwText() + "-");
    sw.append(getwPackageName());
    if (getwResourceName() != null) {
        sw.append("-" + getwResourceName());
    }
    sw.append("-" + getTimeStamp());
    sw.append("-" + getIdentifier());
    return sw.toString();
}

7. ScopeTestHelper#format()

Project: esper
Source File: ScopeTestHelper.java
View license
private static String format(String message, Object expected, Object actual, boolean isSame) {
    StringWriter buf = new StringWriter();
    if (message != null && !message.isEmpty()) {
        buf.append(message);
        buf.append(' ');
    }
    buf.append("expected");
    if (isSame) {
        buf.append(" same");
    }
    buf.append(":<");
    buf.append(expected == null ? "null" : expected.toString());
    buf.append("> but was:<");
    buf.append(actual == null ? "null" : actual.toString());
    buf.append(">");
    return buf.toString();
}

8. SupportHelper#format()

Project: StreamCQL
Source File: SupportHelper.java
View license
private static String format(String message, Object expected, Object actual, boolean isSame) {
    StringWriter buf = new StringWriter();
    if (message != null && !message.isEmpty()) {
        buf.append(message);
        buf.append(' ');
    }
    buf.append("expected");
    if (isSame) {
        buf.append(" same");
    }
    buf.append(":<");
    buf.append(expected == null ? "null" : expected.toString());
    buf.append("> but was:<");
    buf.append(actual == null ? "null" : actual.toString());
    buf.append(">");
    return buf.toString();
}

9. PdbPairsMessage#toString()

Project: biojava
Source File: PdbPairsMessage.java
View license
@Override
public String toString() {
    StringWriter w = new StringWriter();
    w.append("PdbPairsMessage: ");
    w.append("algorithm: ");
    w.append(method);
    w.append(" pairs: ");
    w.append(pairs.toString());
    return w.toString();
}

10. RemoveAppendTest#insert()

Project: exist
Source File: RemoveAppendTest.java
View license
protected void insert(final XUpdateQueryService service, final int id) throws IOException, XMLDBException {
    StringWriter out = new StringWriter();
    out.write("<xu:modifications xmlns:xu=\"http://www.xmldb.org/xupdate\" version=\"1.0\">");
    out.write("<xu:insert-before select=\"/test/item[@id='");
    out.write(Integer.toString(id));
    out.write("']\">");
    createItem(5, out);
    out.write("</xu:insert-before>");
    out.write("</xu:modifications>");
    long mods = service.update(out.toString());
    assertEquals(mods, 1);
}

11. OldAndroidStringWriterTest#testStringWriter()

View license
public void testStringWriter() throws Exception {
    String str = "AbCdEfGhIjKlMnOpQrStUvWxYz";
    StringWriter a = new StringWriter(10);
    a.write(str, 0, 26);
    a.write('X');
    assertEquals("AbCdEfGhIjKlMnOpQrStUvWxYzX", a.toString());
    a.write("alphabravodelta", 5, 5);
    a.append('X');
    assertEquals("AbCdEfGhIjKlMnOpQrStUvWxYzXbravoX", a.toString());
    a.append("omega");
    assertEquals("AbCdEfGhIjKlMnOpQrStUvWxYzXbravoXomega", a.toString());
}

12. RemoteController#createKeyDataPayload()

View license
private String createKeyDataPayload(KeyCode key) throws IOException {
    /* @formatter:off
		 *
		 * Payload:
		 *
		 * offset value and description
		 * ------ ---------------------
		 * 0x18   three 0x00 bytes
		 * 0x1b   0x000c - key code size (little endian)
		 * 0x1d   key code encoded as base64 string
		 *
		 * @formatter:on
		 */
    StringWriter writer = new StringWriter();
    writer.append((char) 0x00);
    writer.append((char) 0x00);
    writer.append((char) 0x00);
    writeBase64String(writer, key.getValue());
    writer.flush();
    return writer.toString();
}

13. BasicMood#toString()

Project: BotLibre
Source File: BasicMood.java
View license
/**
	 * Print a useful string representation of the mood.  
	 */
@Override
public String toString() {
    StringWriter writer = new StringWriter();
    writer.write(getClass().getSimpleName());
    writer.write("(");
    boolean first = true;
    for (Emotion emotion : getEmotions().values()) {
        if (!first) {
            writer.write(", ");
        } else {
            first = false;
        }
        writer.write(emotion.toString());
    }
    writer.write(")");
    return writer.toString();
}

14. BrowseConfig#toXML()

Project: BotLibre
Source File: BrowseConfig.java
View license
public String toXML() {
    StringWriter writer = new StringWriter();
    writer.write("<browse");
    writeCredentials(writer);
    writer.write(" type=\"" + this.type + "\"");
    if (this.typeFilter != null) {
        writer.write(" typeFilter=\"" + this.typeFilter + "\"");
    }
    if (this.sort != null) {
        writer.write(" sort=\"" + this.sort + "\"");
    }
    if ((this.category != null) && !this.category.equals("")) {
        writer.write(" category=\"" + this.category + "\"");
    }
    if ((this.tag != null) && !this.tag.equals("")) {
        writer.write(" tag=\"" + this.tag + "\"");
    }
    if ((this.filter != null) && !this.filter.equals("")) {
        writer.write(" filter=\"" + this.filter + "\"");
    }
    writer.write("/>");
    return writer.toString();
}

15. TrainingConfig#toXML()

Project: BotLibre
Source File: TrainingConfig.java
View license
public String toXML() {
    StringWriter writer = new StringWriter();
    writer.write("<training");
    writeCredentials(writer);
    if (this.operation != null) {
        writer.write(" operation=\"" + this.operation + "\"");
    }
    writer.write(">");
    if (this.question != null) {
        writer.write("<question>");
        writer.write(Utils.escapeHTML(this.question));
        writer.write("</question>");
    }
    if (this.response != null) {
        writer.write("<response>");
        writer.write(Utils.escapeHTML(this.response));
        writer.write("</response>");
    }
    writer.write("</training>");
    return writer.toString();
}

16. BrowseConfig#toXML()

Project: BotLibre
Source File: BrowseConfig.java
View license
public String toXML() {
    StringWriter writer = new StringWriter();
    writer.write("<browse");
    writeCredentials(writer);
    writer.write(" type=\"" + this.type + "\"");
    if (this.typeFilter != null) {
        writer.write(" typeFilter=\"" + this.typeFilter + "\"");
    }
    if (this.sort != null) {
        writer.write(" sort=\"" + this.sort + "\"");
    }
    if ((this.category != null) && !this.category.equals("")) {
        writer.write(" category=\"" + this.category + "\"");
    }
    if ((this.tag != null) && !this.tag.equals("")) {
        writer.write(" tag=\"" + this.tag + "\"");
    }
    if ((this.filter != null) && !this.filter.equals("")) {
        writer.write(" filter=\"" + this.filter + "\"");
    }
    writer.write("/>");
    return writer.toString();
}

17. TrainingConfig#toXML()

Project: BotLibre
Source File: TrainingConfig.java
View license
public String toXML() {
    StringWriter writer = new StringWriter();
    writer.write("<training");
    writeCredentials(writer);
    if (this.operation != null) {
        writer.write(" operation=\"" + this.operation + "\"");
    }
    writer.write(">");
    if (this.question != null) {
        writer.write("<question>");
        writer.write(Utils.escapeHTML(this.question));
        writer.write("</question>");
    }
    if (this.response != null) {
        writer.write("<response>");
        writer.write(Utils.escapeHTML(this.response));
        writer.write("</response>");
    }
    writer.write("</training>");
    return writer.toString();
}

18. EvalAuditStateNode#toStringEvaluateFalse()

Project: esper
Source File: EvalAuditStateNode.java
View license
private String toStringEvaluateFalse(EvalAuditStateNode current, String patternExpression, EvalStateNode fromNode) {
    StringWriter writer = new StringWriter();
    writePatternExpr(current, patternExpression, writer);
    writer.write(" evaluate-false {");
    writer.write(" from ");
    JavaClassHelper.writeInstance(writer, fromNode, false);
    writer.write("}");
    return writer.toString();
}

19. NTypePrinter#printStruct()

Project: jdk7u-jdk
Source File: NTypePrinter.java
View license
protected String printStruct(NStruct nt, char open, char close) {
    StringWriter sw = new StringWriter();
    sw.append(open);
    sw.append(nt.name);
    if (nt.fields.size() > 0) {
        sw.append('=');
        for (NField f : nt.fields) {
            if (f.name != null && f.name.length() > 0)
                sw.append("\"" + f.name + "\"");
            sw.append(print(f.type));
        }
    }
    sw.append(close);
    return sw.toString();
}

20. JSONArrayTest#testByteArrayToString()

Project: json-simple
Source File: JSONArrayTest.java
View license
public void testByteArrayToString() throws IOException {
    assertEquals("null", JSONArray.toJSONString((byte[]) null));
    assertEquals("[]", JSONArray.toJSONString(new byte[0]));
    assertEquals("[12]", JSONArray.toJSONString(new byte[] { 12 }));
    assertEquals("[-7,22,86,-99]", JSONArray.toJSONString(new byte[] { -7, 22, 86, -99 }));
    StringWriter writer;
    writer = new StringWriter();
    JSONArray.writeJSONString((byte[]) null, writer);
    assertEquals("null", writer.toString());
    writer = new StringWriter();
    JSONArray.writeJSONString(new byte[0], writer);
    assertEquals("[]", writer.toString());
    writer = new StringWriter();
    JSONArray.writeJSONString(new byte[] { 12 }, writer);
    assertEquals("[12]", writer.toString());
    writer = new StringWriter();
    JSONArray.writeJSONString(new byte[] { -7, 22, 86, -99 }, writer);
    assertEquals("[-7,22,86,-99]", writer.toString());
}

21. JSONArrayTest#testShortArrayToString()

Project: json-simple
Source File: JSONArrayTest.java
View license
public void testShortArrayToString() throws IOException {
    assertEquals("null", JSONArray.toJSONString((short[]) null));
    assertEquals("[]", JSONArray.toJSONString(new short[0]));
    assertEquals("[12]", JSONArray.toJSONString(new short[] { 12 }));
    assertEquals("[-7,22,86,-99]", JSONArray.toJSONString(new short[] { -7, 22, 86, -99 }));
    StringWriter writer;
    writer = new StringWriter();
    JSONArray.writeJSONString((short[]) null, writer);
    assertEquals("null", writer.toString());
    writer = new StringWriter();
    JSONArray.writeJSONString(new short[0], writer);
    assertEquals("[]", writer.toString());
    writer = new StringWriter();
    JSONArray.writeJSONString(new short[] { 12 }, writer);
    assertEquals("[12]", writer.toString());
    writer = new StringWriter();
    JSONArray.writeJSONString(new short[] { -7, 22, 86, -99 }, writer);
    assertEquals("[-7,22,86,-99]", writer.toString());
}

22. JSONArrayTest#testIntArrayToString()

Project: json-simple
Source File: JSONArrayTest.java
View license
public void testIntArrayToString() throws IOException {
    assertEquals("null", JSONArray.toJSONString((int[]) null));
    assertEquals("[]", JSONArray.toJSONString(new int[0]));
    assertEquals("[12]", JSONArray.toJSONString(new int[] { 12 }));
    assertEquals("[-7,22,86,-99]", JSONArray.toJSONString(new int[] { -7, 22, 86, -99 }));
    StringWriter writer;
    writer = new StringWriter();
    JSONArray.writeJSONString((int[]) null, writer);
    assertEquals("null", writer.toString());
    writer = new StringWriter();
    JSONArray.writeJSONString(new int[0], writer);
    assertEquals("[]", writer.toString());
    writer = new StringWriter();
    JSONArray.writeJSONString(new int[] { 12 }, writer);
    assertEquals("[12]", writer.toString());
    writer = new StringWriter();
    JSONArray.writeJSONString(new int[] { -7, 22, 86, -99 }, writer);
    assertEquals("[-7,22,86,-99]", writer.toString());
}

23. JSONArrayTest#testLongArrayToString()

Project: json-simple
Source File: JSONArrayTest.java
View license
public void testLongArrayToString() throws IOException {
    assertEquals("null", JSONArray.toJSONString((long[]) null));
    assertEquals("[]", JSONArray.toJSONString(new long[0]));
    assertEquals("[12]", JSONArray.toJSONString(new long[] { 12 }));
    assertEquals("[-7,22,9223372036854775807,-99]", JSONArray.toJSONString(new long[] { -7, 22, 9223372036854775807L, -99 }));
    StringWriter writer;
    writer = new StringWriter();
    JSONArray.writeJSONString((long[]) null, writer);
    assertEquals("null", writer.toString());
    writer = new StringWriter();
    JSONArray.writeJSONString(new long[0], writer);
    assertEquals("[]", writer.toString());
    writer = new StringWriter();
    JSONArray.writeJSONString(new long[] { 12 }, writer);
    assertEquals("[12]", writer.toString());
    writer = new StringWriter();
    JSONArray.writeJSONString(new long[] { -7, 22, 86, -99 }, writer);
    assertEquals("[-7,22,86,-99]", writer.toString());
}

24. JSONArrayTest#testFloatArrayToString()

Project: json-simple
Source File: JSONArrayTest.java
View license
public void testFloatArrayToString() throws IOException {
    assertEquals("null", JSONArray.toJSONString((float[]) null));
    assertEquals("[]", JSONArray.toJSONString(new float[0]));
    assertEquals("[12.8]", JSONArray.toJSONString(new float[] { 12.8f }));
    assertEquals("[-7.1,22.234,86.7,-99.02]", JSONArray.toJSONString(new float[] { -7.1f, 22.234f, 86.7f, -99.02f }));
    StringWriter writer;
    writer = new StringWriter();
    JSONArray.writeJSONString((float[]) null, writer);
    assertEquals("null", writer.toString());
    writer = new StringWriter();
    JSONArray.writeJSONString(new float[0], writer);
    assertEquals("[]", writer.toString());
    writer = new StringWriter();
    JSONArray.writeJSONString(new float[] { 12.8f }, writer);
    assertEquals("[12.8]", writer.toString());
    writer = new StringWriter();
    JSONArray.writeJSONString(new float[] { -7.1f, 22.234f, 86.7f, -99.02f }, writer);
    assertEquals("[-7.1,22.234,86.7,-99.02]", writer.toString());
}

25. JSONArrayTest#testDoubleArrayToString()

Project: json-simple
Source File: JSONArrayTest.java
View license
public void testDoubleArrayToString() throws IOException {
    assertEquals("null", JSONArray.toJSONString((double[]) null));
    assertEquals("[]", JSONArray.toJSONString(new double[0]));
    assertEquals("[12.8]", JSONArray.toJSONString(new double[] { 12.8 }));
    assertEquals("[-7.1,22.234,86.7,-99.02]", JSONArray.toJSONString(new double[] { -7.1, 22.234, 86.7, -99.02 }));
    StringWriter writer;
    writer = new StringWriter();
    JSONArray.writeJSONString((double[]) null, writer);
    assertEquals("null", writer.toString());
    writer = new StringWriter();
    JSONArray.writeJSONString(new double[0], writer);
    assertEquals("[]", writer.toString());
    writer = new StringWriter();
    JSONArray.writeJSONString(new double[] { 12.8 }, writer);
    assertEquals("[12.8]", writer.toString());
    writer = new StringWriter();
    JSONArray.writeJSONString(new double[] { -7.1, 22.234, 86.7, -99.02 }, writer);
    assertEquals("[-7.1,22.234,86.7,-99.02]", writer.toString());
}

26. JSONArrayTest#testBooleanArrayToString()

Project: json-simple
Source File: JSONArrayTest.java
View license
public void testBooleanArrayToString() throws IOException {
    assertEquals("null", JSONArray.toJSONString((boolean[]) null));
    assertEquals("[]", JSONArray.toJSONString(new boolean[0]));
    assertEquals("[true]", JSONArray.toJSONString(new boolean[] { true }));
    assertEquals("[true,false,true]", JSONArray.toJSONString(new boolean[] { true, false, true }));
    StringWriter writer;
    writer = new StringWriter();
    JSONArray.writeJSONString((boolean[]) null, writer);
    assertEquals("null", writer.toString());
    writer = new StringWriter();
    JSONArray.writeJSONString(new boolean[0], writer);
    assertEquals("[]", writer.toString());
    writer = new StringWriter();
    JSONArray.writeJSONString(new boolean[] { true }, writer);
    assertEquals("[true]", writer.toString());
    writer = new StringWriter();
    JSONArray.writeJSONString(new boolean[] { true, false, true }, writer);
    assertEquals("[true,false,true]", writer.toString());
}

27. JSONArrayTest#testCharArrayToString()

Project: json-simple
Source File: JSONArrayTest.java
View license
public void testCharArrayToString() throws IOException {
    assertEquals("null", JSONArray.toJSONString((char[]) null));
    assertEquals("[]", JSONArray.toJSONString(new char[0]));
    assertEquals("[\"a\"]", JSONArray.toJSONString(new char[] { 'a' }));
    assertEquals("[\"a\",\"b\",\"c\"]", JSONArray.toJSONString(new char[] { 'a', 'b', 'c' }));
    StringWriter writer;
    writer = new StringWriter();
    JSONArray.writeJSONString((char[]) null, writer);
    assertEquals("null", writer.toString());
    writer = new StringWriter();
    JSONArray.writeJSONString(new char[0], writer);
    assertEquals("[]", writer.toString());
    writer = new StringWriter();
    JSONArray.writeJSONString(new char[] { 'a' }, writer);
    assertEquals("[\"a\"]", writer.toString());
    writer = new StringWriter();
    JSONArray.writeJSONString(new char[] { 'a', 'b', 'c' }, writer);
    assertEquals("[\"a\",\"b\",\"c\"]", writer.toString());
}

28. JSONArrayTest#testObjectArrayToString()

Project: json-simple
Source File: JSONArrayTest.java
View license
public void testObjectArrayToString() throws IOException {
    assertEquals("null", JSONArray.toJSONString((Object[]) null));
    assertEquals("[]", JSONArray.toJSONString(new Object[0]));
    assertEquals("[\"Hello\"]", JSONArray.toJSONString(new Object[] { "Hello" }));
    assertEquals("[\"Hello\",12,[1,2,3]]", JSONArray.toJSONString(new Object[] { "Hello", new Integer(12), new int[] { 1, 2, 3 } }));
    StringWriter writer;
    writer = new StringWriter();
    JSONArray.writeJSONString((Object[]) null, writer);
    assertEquals("null", writer.toString());
    writer = new StringWriter();
    JSONArray.writeJSONString(new Object[0], writer);
    assertEquals("[]", writer.toString());
    writer = new StringWriter();
    JSONArray.writeJSONString(new Object[] { "Hello" }, writer);
    assertEquals("[\"Hello\"]", writer.toString());
    writer = new StringWriter();
    JSONArray.writeJSONString(new Object[] { "Hello", new Integer(12), new int[] { 1, 2, 3 } }, writer);
    assertEquals("[\"Hello\",12,[1,2,3]]", writer.toString());
}

29. JSONValueTest#testByteArrayToString()

Project: json-simple
Source File: JSONValueTest.java
View license
public void testByteArrayToString() throws IOException {
    assertEquals("null", JSONValue.toJSONString((byte[]) null));
    assertEquals("[]", JSONValue.toJSONString(new byte[0]));
    assertEquals("[12]", JSONValue.toJSONString(new byte[] { 12 }));
    assertEquals("[-7,22,86,-99]", JSONValue.toJSONString(new byte[] { -7, 22, 86, -99 }));
    StringWriter writer;
    writer = new StringWriter();
    JSONValue.writeJSONString((byte[]) null, writer);
    assertEquals("null", writer.toString());
    writer = new StringWriter();
    JSONValue.writeJSONString(new byte[0], writer);
    assertEquals("[]", writer.toString());
    writer = new StringWriter();
    JSONValue.writeJSONString(new byte[] { 12 }, writer);
    assertEquals("[12]", writer.toString());
    writer = new StringWriter();
    JSONValue.writeJSONString(new byte[] { -7, 22, 86, -99 }, writer);
    assertEquals("[-7,22,86,-99]", writer.toString());
}

30. JSONValueTest#testShortArrayToString()

Project: json-simple
Source File: JSONValueTest.java
View license
public void testShortArrayToString() throws IOException {
    assertEquals("null", JSONValue.toJSONString((short[]) null));
    assertEquals("[]", JSONValue.toJSONString(new short[0]));
    assertEquals("[12]", JSONValue.toJSONString(new short[] { 12 }));
    assertEquals("[-7,22,86,-99]", JSONValue.toJSONString(new short[] { -7, 22, 86, -99 }));
    StringWriter writer;
    writer = new StringWriter();
    JSONValue.writeJSONString((short[]) null, writer);
    assertEquals("null", writer.toString());
    writer = new StringWriter();
    JSONValue.writeJSONString(new short[0], writer);
    assertEquals("[]", writer.toString());
    writer = new StringWriter();
    JSONValue.writeJSONString(new short[] { 12 }, writer);
    assertEquals("[12]", writer.toString());
    writer = new StringWriter();
    JSONValue.writeJSONString(new short[] { -7, 22, 86, -99 }, writer);
    assertEquals("[-7,22,86,-99]", writer.toString());
}

31. JSONValueTest#testIntArrayToString()

Project: json-simple
Source File: JSONValueTest.java
View license
public void testIntArrayToString() throws IOException {
    assertEquals("null", JSONValue.toJSONString((int[]) null));
    assertEquals("[]", JSONValue.toJSONString(new int[0]));
    assertEquals("[12]", JSONValue.toJSONString(new int[] { 12 }));
    assertEquals("[-7,22,86,-99]", JSONValue.toJSONString(new int[] { -7, 22, 86, -99 }));
    StringWriter writer;
    writer = new StringWriter();
    JSONValue.writeJSONString((int[]) null, writer);
    assertEquals("null", writer.toString());
    writer = new StringWriter();
    JSONValue.writeJSONString(new int[0], writer);
    assertEquals("[]", writer.toString());
    writer = new StringWriter();
    JSONValue.writeJSONString(new int[] { 12 }, writer);
    assertEquals("[12]", writer.toString());
    writer = new StringWriter();
    JSONValue.writeJSONString(new int[] { -7, 22, 86, -99 }, writer);
    assertEquals("[-7,22,86,-99]", writer.toString());
}

32. JSONValueTest#testLongArrayToString()

Project: json-simple
Source File: JSONValueTest.java
View license
public void testLongArrayToString() throws IOException {
    assertEquals("null", JSONValue.toJSONString((long[]) null));
    assertEquals("[]", JSONValue.toJSONString(new long[0]));
    assertEquals("[12]", JSONValue.toJSONString(new long[] { 12 }));
    assertEquals("[-7,22,9223372036854775807,-99]", JSONValue.toJSONString(new long[] { -7, 22, 9223372036854775807L, -99 }));
    StringWriter writer;
    writer = new StringWriter();
    JSONValue.writeJSONString((long[]) null, writer);
    assertEquals("null", writer.toString());
    writer = new StringWriter();
    JSONValue.writeJSONString(new long[0], writer);
    assertEquals("[]", writer.toString());
    writer = new StringWriter();
    JSONValue.writeJSONString(new long[] { 12 }, writer);
    assertEquals("[12]", writer.toString());
    writer = new StringWriter();
    JSONValue.writeJSONString(new long[] { -7, 22, 86, -99 }, writer);
    assertEquals("[-7,22,86,-99]", writer.toString());
}

33. JSONValueTest#testFloatArrayToString()

Project: json-simple
Source File: JSONValueTest.java
View license
public void testFloatArrayToString() throws IOException {
    assertEquals("null", JSONValue.toJSONString((float[]) null));
    assertEquals("[]", JSONValue.toJSONString(new float[0]));
    assertEquals("[12.8]", JSONValue.toJSONString(new float[] { 12.8f }));
    assertEquals("[-7.1,22.234,86.7,-99.02]", JSONValue.toJSONString(new float[] { -7.1f, 22.234f, 86.7f, -99.02f }));
    StringWriter writer;
    writer = new StringWriter();
    JSONValue.writeJSONString((float[]) null, writer);
    assertEquals("null", writer.toString());
    writer = new StringWriter();
    JSONValue.writeJSONString(new float[0], writer);
    assertEquals("[]", writer.toString());
    writer = new StringWriter();
    JSONValue.writeJSONString(new float[] { 12.8f }, writer);
    assertEquals("[12.8]", writer.toString());
    writer = new StringWriter();
    JSONValue.writeJSONString(new float[] { -7.1f, 22.234f, 86.7f, -99.02f }, writer);
    assertEquals("[-7.1,22.234,86.7,-99.02]", writer.toString());
}

34. JSONValueTest#testDoubleArrayToString()

Project: json-simple
Source File: JSONValueTest.java
View license
public void testDoubleArrayToString() throws IOException {
    assertEquals("null", JSONValue.toJSONString((double[]) null));
    assertEquals("[]", JSONValue.toJSONString(new double[0]));
    assertEquals("[12.8]", JSONValue.toJSONString(new double[] { 12.8 }));
    assertEquals("[-7.1,22.234,86.7,-99.02]", JSONValue.toJSONString(new double[] { -7.1, 22.234, 86.7, -99.02 }));
    StringWriter writer;
    writer = new StringWriter();
    JSONValue.writeJSONString((double[]) null, writer);
    assertEquals("null", writer.toString());
    writer = new StringWriter();
    JSONValue.writeJSONString(new double[0], writer);
    assertEquals("[]", writer.toString());
    writer = new StringWriter();
    JSONValue.writeJSONString(new double[] { 12.8 }, writer);
    assertEquals("[12.8]", writer.toString());
    writer = new StringWriter();
    JSONValue.writeJSONString(new double[] { -7.1, 22.234, 86.7, -99.02 }, writer);
    assertEquals("[-7.1,22.234,86.7,-99.02]", writer.toString());
}

35. JSONValueTest#testBooleanArrayToString()

Project: json-simple
Source File: JSONValueTest.java
View license
public void testBooleanArrayToString() throws IOException {
    assertEquals("null", JSONValue.toJSONString((boolean[]) null));
    assertEquals("[]", JSONValue.toJSONString(new boolean[0]));
    assertEquals("[true]", JSONValue.toJSONString(new boolean[] { true }));
    assertEquals("[true,false,true]", JSONValue.toJSONString(new boolean[] { true, false, true }));
    StringWriter writer;
    writer = new StringWriter();
    JSONValue.writeJSONString((boolean[]) null, writer);
    assertEquals("null", writer.toString());
    writer = new StringWriter();
    JSONValue.writeJSONString(new boolean[0], writer);
    assertEquals("[]", writer.toString());
    writer = new StringWriter();
    JSONValue.writeJSONString(new boolean[] { true }, writer);
    assertEquals("[true]", writer.toString());
    writer = new StringWriter();
    JSONValue.writeJSONString(new boolean[] { true, false, true }, writer);
    assertEquals("[true,false,true]", writer.toString());
}

36. JSONValueTest#testCharArrayToString()

Project: json-simple
Source File: JSONValueTest.java
View license
public void testCharArrayToString() throws IOException {
    assertEquals("null", JSONValue.toJSONString((char[]) null));
    assertEquals("[]", JSONValue.toJSONString(new char[0]));
    assertEquals("[\"a\"]", JSONValue.toJSONString(new char[] { 'a' }));
    assertEquals("[\"a\",\"b\",\"c\"]", JSONValue.toJSONString(new char[] { 'a', 'b', 'c' }));
    StringWriter writer;
    writer = new StringWriter();
    JSONValue.writeJSONString((char[]) null, writer);
    assertEquals("null", writer.toString());
    writer = new StringWriter();
    JSONValue.writeJSONString(new char[0], writer);
    assertEquals("[]", writer.toString());
    writer = new StringWriter();
    JSONValue.writeJSONString(new char[] { 'a' }, writer);
    assertEquals("[\"a\"]", writer.toString());
    writer = new StringWriter();
    JSONValue.writeJSONString(new char[] { 'a', 'b', 'c' }, writer);
    assertEquals("[\"a\",\"b\",\"c\"]", writer.toString());
}

37. JSONValueTest#testObjectArrayToString()

Project: json-simple
Source File: JSONValueTest.java
View license
public void testObjectArrayToString() throws IOException {
    assertEquals("null", JSONValue.toJSONString((Object[]) null));
    assertEquals("[]", JSONValue.toJSONString(new Object[0]));
    assertEquals("[\"Hello\"]", JSONValue.toJSONString(new Object[] { "Hello" }));
    assertEquals("[\"Hello\",12,[1,2,3]]", JSONValue.toJSONString(new Object[] { "Hello", new Integer(12), new int[] { 1, 2, 3 } }));
    StringWriter writer;
    writer = new StringWriter();
    JSONValue.writeJSONString((Object[]) null, writer);
    assertEquals("null", writer.toString());
    writer = new StringWriter();
    JSONValue.writeJSONString(new Object[0], writer);
    assertEquals("[]", writer.toString());
    writer = new StringWriter();
    JSONValue.writeJSONString(new Object[] { "Hello" }, writer);
    assertEquals("[\"Hello\"]", writer.toString());
    writer = new StringWriter();
    JSONValue.writeJSONString(new Object[] { "Hello", new Integer(12), new int[] { 1, 2, 3 } }, writer);
    assertEquals("[\"Hello\",12,[1,2,3]]", writer.toString());
}

38. ProfileSerializer#toXML()

Project: oodt
Source File: ProfileSerializer.java
View license
/**
   * Function to serialize a list of [email protected] Profile}s to XML.
   * 
   * @param profiles
   * @return
   * @throws TransformerException
   */
public static String toXML(final List<Profile> profiles) throws TransformerException {
    final StringWriter writer = new StringWriter();
    writer.append("<?xml version='1.0' encoding='UTF-8'?>");
    writer.append("<!DOCTYPE profiles PUBLIC '" + Profile.PROFILES_DTD_FPI + "' '").append(Profile.PROFILES_DTD_URL).append("'>");
    writer.append("<profiles>");
    final Transformer transformer = createTransformer();
    final Document doc = Profile.createProfileDocument();
    for (final Profile profile : profiles) {
        Node profileNode = profile.toXML(doc);
        DOMSource source = new DOMSource(profileNode);
        StreamResult result = new StreamResult(writer);
        transformer.transform(source, result);
    }
    writer.append("</profiles>");
    return writer.toString();
}

39. LauncherMain#logMasking()

Project: oozie
Source File: LauncherMain.java
View license
/**
     * Write to STDOUT (the task log) the Configuration/Properties values. All properties that contain
     * any of the strings in the maskSet will be masked when writting it to STDOUT.
     *
     * @param header message for the beginning of the Configuration/Properties dump.
     * @param maskSet set with substrings of property names to mask.
     * @param conf Configuration/Properties object to dump to STDOUT
     * @throws IOException thrown if an IO error ocurred.
     */
@SuppressWarnings("unchecked")
protected static void logMasking(String header, Collection<String> maskSet, Iterable conf) throws IOException {
    StringWriter writer = new StringWriter();
    writer.write(header + "\n");
    writer.write("--------------------\n");
    for (Map.Entry entry : (Iterable<Map.Entry>) conf) {
        String name = (String) entry.getKey();
        String value = (String) entry.getValue();
        for (String mask : maskSet) {
            if (name.contains(mask)) {
                value = "*MASKED*";
            }
        }
        writer.write(" " + name + " : " + value + "\n");
    }
    writer.write("--------------------\n");
    writer.close();
    System.out.println(writer.toString());
    System.out.flush();
}

40. RemoteController#createRegistrationPayload()

View license
private String createRegistrationPayload(String ip) throws IOException {
    /*
         * Payload starts with 2 bytes: 0x64 and 0x00, then comes 3 strings
         * encoded with base64 algorithm. Every string is preceded by 2-bytes
         * field containing encoded string length.
         * 
         * These three strings are as follow:
         * 
         * remote control device IP, unique ID  value to distinguish
         * controllers, name  it will be displayed as controller name.
         */
    StringWriter w = new StringWriter();
    w.append((char) 0x64);
    w.append((char) 0x00);
    writeBase64String(w, ip);
    writeBase64String(w, uniqueId);
    writeBase64String(w, appName);
    w.flush();
    return w.toString();
}

41. OAtomicOperationsManager#dumpActiveAtomicOperations()

View license
@Override
public String dumpActiveAtomicOperations() {
    if (!trackAtomicOperations)
        activeAtomicOperations.clear();
    final StringWriter writer = new StringWriter();
    writer.append("List of active atomic operations: \r\n");
    writer.append("------------------------------------------------------------------------------------------------\r\n");
    for (Map.Entry<OOperationUnitId, OPair<String, StackTraceElement[]>> entry : activeAtomicOperations.entrySet()) {
        writer.append("Operation unit id :").append(entry.getKey().toString()).append("\r\n");
        writer.append("Started at thread : ").append(entry.getValue().getKey()).append("\r\n");
        writer.append("Stack trace of method which started this operation : \r\n");
        StackTraceElement[] stackTraceElements = entry.getValue().getValue();
        for (int i = 1; i < stackTraceElements.length; i++) {
            writer.append("\tat ").append(stackTraceElements[i].toString()).append("\r\n");
        }
        writer.append("\r\n\r\n");
    }
    writer.append("-------------------------------------------------------------------------------------------------\r\n");
    return writer.toString();
}

42. FatCatParameters#toString()

Project: biojava
Source File: FatCatParameters.java
View license
@Override
public String toString() {
    StringWriter writer = new StringWriter();
    writer.append("[");
    if (maxTra == 0)
        writer.append("Mode: rigid, ");
    else
        writer.append("Mode: flexible, ");
    List<String> params = getUserConfigParameters();
    for (String s : params) {
        writer.append(s);
        writer.append(": ");
        Object val = getValue(s);
        writer.append(val.toString());
        writer.append(", ");
    }
    writer.append("]");
    return writer.toString();
}

43. SelfExecutionException#getMessage()

View license
public String getMessage() {
    StringWriter writer = new StringWriter();
    writer.write(super.getMessage());
    if (this.line != null) {
        writer.write("\n");
        writer.write("Line: \"" + String.valueOf(this.line) + "\"");
    }
    if (this.lineNumber != null) {
        writer.write("\n");
        writer.write("Line number: " + String.valueOf(this.lineNumber));
    }
    writer.flush();
    return writer.toString();
}

44. SelfParseException#getMessage()

Project: BotLibre
Source File: SelfParseException.java
View license
public String getMessage() {
    StringWriter writer = new StringWriter();
    writer.write(super.getMessage());
    if (this.line != null) {
        writer.write("\n");
        writer.write("Line: \"" + this.line + "\"");
    }
    if (this.lineNumber > 0) {
        writer.write("\n");
        writer.write("Line number: " + this.lineNumber);
    }
    if (this.columnNumber > 0) {
        writer.write("\n");
        writer.write("Line column: " + this.columnNumber);
    }
    writer.flush();
    return writer.toString();
}

45. BotModeConfig#toXML()

Project: BotLibre
Source File: BotModeConfig.java
View license
public String toXML() {
    StringWriter writer = new StringWriter();
    writer.write("<bot-mode");
    writeCredentials(writer);
    if (this.mode != null) {
        writer.write(" mode=\"" + this.mode + "\"");
    }
    if (this.bot != null) {
        writer.write(" bot=\"" + this.bot + "\"");
    }
    writer.write("/>");
    return writer.toString();
}

46. ContentConfig#toXML()

Project: BotLibre
Source File: ContentConfig.java
View license
public String toXML() {
    StringWriter writer = new StringWriter();
    writer.write("<content");
    writeCredentials(writer);
    if (this.type != null) {
        writer.write(" type=\"" + this.type + "\"");
    }
    writer.write("/>");
    return writer.toString();
}

47. ForumConfig#toXML()

Project: BotLibre
Source File: ForumConfig.java
View license
public String toXML() {
    StringWriter writer = new StringWriter();
    writer.write("<forum");
    if (this.replyAccessMode != null && !this.replyAccessMode.equals("")) {
        writer.write(" replyAccessMode=\"" + this.replyAccessMode + "\"");
    }
    if (this.postAccessMode != null && !this.postAccessMode.equals("")) {
        writer.write(" postAccessMode=\"" + this.postAccessMode + "\"");
    }
    writeXML(writer);
    writer.write("</forum>");
    return writer.toString();
}

48. InstanceConfig#toXML()

Project: BotLibre
Source File: InstanceConfig.java
View license
public String toXML() {
    StringWriter writer = new StringWriter();
    writer.write("<instance");
    if (this.allowForking) {
        writer.write(" allowForking=\"true\"");
    }
    writeXML(writer);
    if (this.template != null) {
        writer.write("<template>");
        writer.write(this.template);
        writer.write("</template>");
    }
    writer.write("</instance>");
    return writer.toString();
}

49. MediaConfig#toXML()

Project: BotLibre
Source File: MediaConfig.java
View license
public String toXML() {
    StringWriter writer = new StringWriter();
    writer.write("<media");
    writeCredentials(writer);
    if (this.id != 0) {
        writer.write(" id=\"" + this.id + "\"");
    }
    if (this.name != null) {
        writer.write(" name=\"" + this.name + "\"");
    }
    if (this.type != null) {
        writer.write(" type=\"" + this.type + "\"");
    }
    if (this.file != null) {
        writer.write(" file=\"" + this.file + "\"");
    }
    if (this.key != null) {
        writer.write(" key=\"" + this.key + "\"");
    }
    writer.write("/>");
    return writer.toString();
}

50. UserAdminConfig#toXML()

Project: BotLibre
Source File: UserAdminConfig.java
View license
public String toXML() {
    StringWriter writer = new StringWriter();
    writer.write("<user-admin");
    writeCredentials(writer);
    if (this.operation != null) {
        writer.write(" operation=\"" + this.operation + "\"");
    }
    if (this.operationUser != null) {
        writer.write(" operationUser=\"" + this.operationUser + "\"");
    }
    writer.write("/>");
    return writer.toString();
}

51. VoiceConfig#toXML()

Project: BotLibre
Source File: VoiceConfig.java
View license
public String toXML() {
    StringWriter writer = new StringWriter();
    writer.write("<voice");
    writeCredentials(writer);
    if (this.language != null) {
        writer.write(" language=\"" + this.language + "\"");
    }
    if (this.pitch != null) {
        writer.write(" pitch=\"" + this.pitch + "\"");
    }
    if (this.speechRate != null) {
        writer.write(" speechRate=\"" + this.speechRate + "\"");
    }
    writer.write("/>");
    return writer.toString();
}

52. BotModeConfig#toXML()

Project: BotLibre
Source File: BotModeConfig.java
View license
public String toXML() {
    StringWriter writer = new StringWriter();
    writer.write("<bot-mode");
    writeCredentials(writer);
    if (this.mode != null) {
        writer.write(" mode=\"" + this.mode + "\"");
    }
    if (this.bot != null) {
        writer.write(" bot=\"" + this.bot + "\"");
    }
    writer.write("/>");
    return writer.toString();
}

53. ContentConfig#toXML()

Project: BotLibre
Source File: ContentConfig.java
View license
public String toXML() {
    StringWriter writer = new StringWriter();
    writer.write("<content");
    writeCredentials(writer);
    if (this.type != null) {
        writer.write(" type=\"" + this.type + "\"");
    }
    writer.write("/>");
    return writer.toString();
}

54. ForumConfig#toXML()

Project: BotLibre
Source File: ForumConfig.java
View license
public String toXML() {
    StringWriter writer = new StringWriter();
    writer.write("<forum");
    if (this.replyAccessMode != null && !this.replyAccessMode.equals("")) {
        writer.write(" replyAccessMode=\"" + this.replyAccessMode + "\"");
    }
    if (this.postAccessMode != null && !this.postAccessMode.equals("")) {
        writer.write(" postAccessMode=\"" + this.postAccessMode + "\"");
    }
    writeXML(writer);
    writer.write("</forum>");
    return writer.toString();
}

55. InstanceConfig#toXML()

Project: BotLibre
Source File: InstanceConfig.java
View license
public String toXML() {
    StringWriter writer = new StringWriter();
    writer.write("<instance");
    if (this.allowForking) {
        writer.write(" allowForking=\"true\"");
    }
    writeXML(writer);
    if (this.template != null) {
        writer.write("<template>");
        writer.write(this.template);
        writer.write("</template>");
    }
    writer.write("</instance>");
    return writer.toString();
}

56. MediaConfig#toXML()

Project: BotLibre
Source File: MediaConfig.java
View license
public String toXML() {
    StringWriter writer = new StringWriter();
    writer.write("<media");
    writeCredentials(writer);
    if (this.id != 0) {
        writer.write(" id=\"" + this.id + "\"");
    }
    if (this.name != null) {
        writer.write(" name=\"" + this.name + "\"");
    }
    if (this.type != null) {
        writer.write(" type=\"" + this.type + "\"");
    }
    if (this.file != null) {
        writer.write(" file=\"" + this.file + "\"");
    }
    if (this.key != null) {
        writer.write(" key=\"" + this.key + "\"");
    }
    writer.write("/>");
    return writer.toString();
}

57. UserAdminConfig#toXML()

Project: BotLibre
Source File: UserAdminConfig.java
View license
public String toXML() {
    StringWriter writer = new StringWriter();
    writer.write("<user-admin");
    writeCredentials(writer);
    if (this.operation != null) {
        writer.write(" operation=\"" + this.operation + "\"");
    }
    if (this.operationUser != null) {
        writer.write(" operationUser=\"" + this.operationUser + "\"");
    }
    writer.write("/>");
    return writer.toString();
}

58. VoiceConfig#toXML()

Project: BotLibre
Source File: VoiceConfig.java
View license
public String toXML() {
    StringWriter writer = new StringWriter();
    writer.write("<voice");
    writeCredentials(writer);
    if (this.language != null) {
        writer.write(" language=\"" + this.language + "\"");
    }
    if (this.pitch != null) {
        writer.write(" pitch=\"" + this.pitch + "\"");
    }
    if (this.speechRate != null) {
        writer.write(" speechRate=\"" + this.speechRate + "\"");
    }
    writer.write("/>");
    return writer.toString();
}

59. ExceptionUtilsTest#testPrintRootCauseStackTrace_ThrowableWriter()

View license
@Test
public void testPrintRootCauseStackTrace_ThrowableWriter() throws Exception {
    StringWriter writer = new StringWriter(1024);
    ExceptionUtils.printRootCauseStackTrace(null, (PrintWriter) null);
    ExceptionUtils.printRootCauseStackTrace(null, new PrintWriter(writer));
    assertEquals(0, writer.getBuffer().length());
    writer = new StringWriter(1024);
    try {
        ExceptionUtils.printRootCauseStackTrace(withCause, (PrintWriter) null);
        fail();
    } catch (final IllegalArgumentException ex) {
    }
    writer = new StringWriter(1024);
    final Throwable cause = createExceptionWithCause();
    ExceptionUtils.printRootCauseStackTrace(cause, new PrintWriter(writer));
    String stackTrace = writer.toString();
    assertTrue(stackTrace.indexOf(ExceptionUtils.WRAPPED_MARKER) != -1);
    writer = new StringWriter(1024);
    ExceptionUtils.printRootCauseStackTrace(withoutCause, new PrintWriter(writer));
    stackTrace = writer.toString();
    assertTrue(stackTrace.indexOf(ExceptionUtils.WRAPPED_MARKER) == -1);
}

60. TriviaMain#printMapWithTime()

Project: esper
Source File: TriviaMain.java
View license
private static String printMapWithTime(Map<String, Object> map) {
    StringWriter writer = new StringWriter();
    String delimiter = "";
    writer.write("{");
    for (Map.Entry<String, Object> entry : map.entrySet()) {
        writer.write(delimiter);
        writer.write(entry.getKey());
        writer.write("=");
        if (entry.getKey().toLowerCase().contains("time")) {
            writer.write(TriviaHelper.print(entry.getValue()));
        } else {
            writer.write(entry.getValue().toString());
        }
        delimiter = ", ";
    }
    writer.write("}");
    return writer.toString();
}

61. FunctionGenerator#createLocalNew()

Project: jdk7u-jdk
Source File: FunctionGenerator.java
View license
private static String createLocalNew(final Class<? extends Invoke> type, final Function fxn) {
    final String identifier = makeInstanceName(fxn);
    StringWriter out = new StringWriter();
    out.append(String.format("%3$s[] argCoders = new %3$s[%1$d + %2$s.length];\n", fxn.args.size(), VARARGS_NAME, Coder.class.getCanonicalName()));
    for (int i = 0; i < fxn.args.size(); i++) out.append(String.format("argCoders[%1$d] = %2$s;\n", i, fxn.args.get(0).type.getJType().getCoderDescriptor().getCoderInstanceName()));
    if (fxn.variadic) {
        out.append(String.format("for(int i = %1$d; i < (%1$d + %2$s.length); i++)\n", fxn.args.size(), VARARGS_NAME));
        out.append(String.format("\targCoders[i] = %1$s.getCoderAtRuntime(%2$s[i - %3$s]);\n", Coder.class.getCanonicalName(), VARARGS_NAME, fxn.args.size()));
    }
    out.append("final " + type.getCanonicalName() + " " + identifier + " = new " + type.getCanonicalName() + "(" + firstArg(fxn) + ", \"" + fxn.name + "\", " + fxn.returnValue.type.getJType().getCoderDescriptor().getCoderInstanceName() + ", argCoders);");
    return out.toString();
}

62. JOOXTest#testWrite()

Project: jOOX
Source File: JOOXTest.java
View license
@Test
public void testWrite() throws Exception {
    StringWriter writer = new StringWriter();
    $.write(writer);
    assertEquals($.toString(), writer.toString());
    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    $.write(stream);
    assertEquals($.toString(), stream.toString());
    writer = new StringWriter();
    stream = new ByteArrayOutputStream();
    assertEquals($, $.write(writer).write(stream));
    assertEquals($.toString(), writer.toString());
    assertEquals($.toString(), stream.toString());
    writer = new StringWriter();
    $.find("abc").write(writer);
    assertEquals("", writer.toString());
    writer = new StringWriter();
    $.find("author").slice(0, 2).write(writer);
    assertEquals("<author>George Orwell</author><author>George Orwell</author>", writer.toString());
}

63. XMLSecEventTest#testWriteAttributeEncoded()

Project: santuario-java
Source File: XMLSecEventTest.java
View license
@Test
public void testWriteAttributeEncoded() throws Exception {
    StringWriter stringWriter = new StringWriter();
    XMLSecAttribute xmlSecAttribute = new XMLSecAttributeImpl(new QName("test", "test", "test"), "test");
    xmlSecAttribute.writeAsEncodedUnicode(stringWriter);
    Assert.assertEquals("test:test=\"test\"", stringWriter.toString());
    stringWriter = new StringWriter();
    xmlSecAttribute = new XMLSecAttributeImpl(new QName("test"), "\"");
    xmlSecAttribute.writeAsEncodedUnicode(stringWriter);
    Assert.assertEquals("test=\""\"", stringWriter.toString());
    stringWriter = new StringWriter();
    xmlSecAttribute = new XMLSecAttributeImpl(new QName("test"), "&");
    xmlSecAttribute.writeAsEncodedUnicode(stringWriter);
    Assert.assertEquals("test=\"&\"", stringWriter.toString());
    stringWriter = new StringWriter();
    xmlSecAttribute = new XMLSecAttributeImpl(new QName("test"), " & \" > < ");
    xmlSecAttribute.writeAsEncodedUnicode(stringWriter);
    Assert.assertEquals("test=\" & " > < \"", stringWriter.toString());
}

64. XMLSecEventTest#testWriteNamespaceEncoded()

Project: santuario-java
Source File: XMLSecEventTest.java
View license
@Test
public void testWriteNamespaceEncoded() throws Exception {
    StringWriter stringWriter = new StringWriter();
    XMLSecNamespace xmlSecNamespace = XMLSecNamespaceImpl.getInstance("test", "test");
    xmlSecNamespace.writeAsEncodedUnicode(stringWriter);
    Assert.assertEquals("xmlns:test=\"test\"", stringWriter.toString());
    stringWriter = new StringWriter();
    xmlSecNamespace = XMLSecNamespaceImpl.getInstance("", "\"");
    xmlSecNamespace.writeAsEncodedUnicode(stringWriter);
    Assert.assertEquals("xmlns=\""\"", stringWriter.toString());
    stringWriter = new StringWriter();
    xmlSecNamespace = XMLSecNamespaceImpl.getInstance("test", "&");
    xmlSecNamespace.writeAsEncodedUnicode(stringWriter);
    Assert.assertEquals("xmlns:test=\"&\"", stringWriter.toString());
    stringWriter = new StringWriter();
    xmlSecNamespace = XMLSecNamespaceImpl.getInstance("test", " & \" > < ");
    xmlSecNamespace.writeAsEncodedUnicode(stringWriter);
    Assert.assertEquals("xmlns:test=\" & " > < \"", stringWriter.toString());
}

65. BasicTilesContainerTest#testAttributeCredentials()

Project: tiles
Source File: BasicTilesContainerTest.java
View license
/**
     * Tests is attributes are rendered correctly according to users roles.
     *
     * @throws IOException If a problem arises during rendering or writing in the writer.
     */
public void testAttributeCredentials() throws IOException {
    Request request = EasyMock.createMock(Request.class);
    EasyMock.expect(request.isUserInRole("myrole")).andReturn(Boolean.TRUE);
    StringWriter writer = new StringWriter();
    EasyMock.expect(request.getWriter()).andReturn(writer);
    EasyMock.replay(request);
    Attribute attribute = new Attribute("This is the value", "myrole");
    attribute.setRenderer("string");
    container.render(attribute, request);
    writer.close();
    assertEquals("The attribute should have been rendered", "This is the value", writer.toString());
    EasyMock.reset(request);
    request = EasyMock.createMock(Request.class);
    EasyMock.expect(request.isUserInRole("myrole")).andReturn(Boolean.FALSE);
    EasyMock.replay(request);
    writer = new StringWriter();
    container.render(attribute, request);
    writer.close();
    assertNotSame("The attribute should have not been rendered", "This is the value", writer);
}

66. TestSearch#testSearch()

Project: lucene-solr
Source File: TestSearch.java
View license
/** This test performs a number of searches. It also compares output
     *  of searches using multi-file index segments with single-file
     *  index segments.
     *
     *  TODO: someone should check that the results of the searches are
     *        still correct by adding assert statements. Right now, the test
     *        passes if the results are the same between multi-file and
     *        single-file formats, even if the results are wrong.
     */
public void testSearch() throws Exception {
    StringWriter sw = new StringWriter();
    PrintWriter pw = new PrintWriter(sw, true);
    doTestSearch(random(), pw, false);
    pw.close();
    sw.close();
    String multiFileOutput = sw.toString();
    //System.out.println(multiFileOutput);
    sw = new StringWriter();
    pw = new PrintWriter(sw, true);
    doTestSearch(random(), pw, true);
    pw.close();
    sw.close();
    String singleFileOutput = sw.toString();
    assertEquals(multiFileOutput, singleFileOutput);
}

67. TestSearchForDuplicates#testRun()

View license
/** This test compares search results when using and not using compound
   *  files.
   *
   *  TODO: There is rudimentary search result validation as well, but it is
   *        simply based on asserting the output observed in the old test case,
   *        without really knowing if the output is correct. Someone needs to
   *        validate this output and make any changes to the checkHits method.
   */
public void testRun() throws Exception {
    StringWriter sw = new StringWriter();
    PrintWriter pw = new PrintWriter(sw, true);
    final int MAX_DOCS = atLeast(225);
    doTest(random(), pw, false, MAX_DOCS);
    pw.close();
    sw.close();
    String multiFileOutput = sw.toString();
    //System.out.println(multiFileOutput);
    sw = new StringWriter();
    pw = new PrintWriter(sw, true);
    doTest(random(), pw, true, MAX_DOCS);
    pw.close();
    sw.close();
    String singleFileOutput = sw.toString();
    assertEquals(multiFileOutput, singleFileOutput);
}

68. DocumentAnalysisRequest#getXML()

View license
//================================================ Helper Methods ==================================================
/**
   * Returns the xml be be set as the request body.
   *
   * @return The xml be be set as the request body.
   *
   * @throws IOException When constructing the xml fails
   */
String getXML() throws IOException {
    StringWriter writer = new StringWriter();
    writer.write("<docs>");
    for (SolrInputDocument document : documents) {
        ClientUtils.writeXML(document, writer);
    }
    writer.write("</docs>");
    writer.flush();
    String xml = writer.toString();
    return (xml.length() > 0) ? xml : null;
}

69. StaticFormatter#format()

Project: airlift
Source File: StaticFormatter.java
View license
@Override
public String format(LogRecord record) {
    ZonedDateTime timestamp = ZonedDateTime.ofInstant(Instant.ofEpochMilli(record.getMillis()), SYSTEM_ZONE);
    StringWriter stringWriter = new StringWriter().append(TIMESTAMP_FORMATTER.format(timestamp)).append('\t').append(Level.fromJulLevel(record.getLevel()).name()).append('\t').append(Thread.currentThread().getName()).append('\t').append(record.getLoggerName()).append('\t').append(record.getMessage());
    if (record.getThrown() != null) {
        stringWriter.append('\n');
        record.getThrown().printStackTrace(new PrintWriter(stringWriter));
        stringWriter.append('\n');
    }
    stringWriter.append('\n');
    return stringWriter.toString();
}

70. LatinEntityResolutionReaderTest#toStringFromReader()

View license
/**
     * A method to obtain the content of a reader as a String,
     * while allowing for specifing the buffer size of the operation.
     * <p/>
     * This method is only really useful for testing a Reader implementation.
     *
     * @param input   the reader to get the input from.
     * @param bufsize the buffer size to use.
     * @return the contents of the reader as a String.
     * @throws IOException if there was an I/O error.
     */
private String toStringFromReader(Reader input, int bufsize) throws IOException {
    StringWriter output = new StringWriter();
    final char[] buffer = new char[bufsize];
    int n = 0;
    while (-1 != (n = input.read(buffer))) {
        output.write(buffer, 0, n);
    }
    output.flush();
    return output.toString();
}

71. ResidueNumber#toString()

Project: biojava
Source File: ResidueNumber.java
View license
/**
	 * @return The residue number and insertion code as a string, eg "74A"
	 * @see java.lang.Object#toString()
	 */
@Override
public String toString() {
    StringWriter writer = new StringWriter();
    //	   if ( chainName != null){
    //		   writer.append(chainName);
    //		   writer.append(":");
    //	   }
    writer.append(String.valueOf(seqNum));
    if (insCode != null && (insCode != ' '))
        writer.append(insCode);
    return writer.toString();
}

72. BasicRelationship#toString()

Project: BotLibre
Source File: BasicRelationship.java
View license
public String toString() {
    StringWriter stringWriter = new StringWriter();
    PrintWriter writer = new PrintWriter(stringWriter);
    BasicVertex.writeHeader(getType(), writer);
    writer.print(" [");
    writer.print(getIndex());
    writer.print("] ");
    writer.print(" (");
    writer.print(((int) (getCorrectness() * 100)) / 100f);
    writer.print(")-> ");
    BasicVertex.writeHeader(getTarget(), writer);
    writer.flush();
    stringWriter.flush();
    return stringWriter.toString();
}

73. BasicVertex#displayString()

Project: BotLibre
Source File: BasicVertex.java
View license
public String displayString() {
    StringWriter writer = new StringWriter();
    writer.write(String.valueOf(this.id));
    if (hasName()) {
        writer.write(" : {");
        writer.write(getName());
        writer.write("}");
    }
    if (hasData()) {
        writer.write(" : ");
        if (isPrimitive()) {
            writer.write("#");
        }
        if (this.data instanceof String) {
            writer.write("\"");
        }
        writer.write(getDataValue());
        if (this.data instanceof String) {
            writer.write("\"");
        }
    }
    return writer.toString();
}

74. JXLTTest#testTemplate0()

Project: commons-jexl
Source File: JXLTTest.java
View license
@Test
public void testTemplate0() throws Exception {
    String source = "   $$ if(x) {\nx is ${x}\n   $$ } else {\n${'no x'}\n$$ }\n";
    StringWriter strw;
    String output;
    JxltEngine.Template t = JXLT.createTemplate(source);
    context.set("x", 42);
    strw = new StringWriter();
    t.evaluate(context, strw);
    output = strw.toString();
    Assert.assertEquals("x is 42\n", output);
    strw = new StringWriter();
    context.set("x", "");
    t.evaluate(context, strw);
    output = strw.toString();
    Assert.assertEquals("no x\n", output);
    String dstr = t.toString();
    Assert.assertNotNull(dstr);
}

75. JXLTTest#testTemplate1()

Project: commons-jexl
Source File: JXLTTest.java
View license
@Test
public void testTemplate1() throws Exception {
    String source = "$$ if(x) {\nx is ${x}\n$$ } else {\n${'no x'}\n$$ }\n";
    StringWriter strw;
    String output;
    JxltEngine.Template t = JXLT.createTemplate("$$", new StringReader(source), "x");
    String dstr = t.asString();
    Assert.assertNotNull(dstr);
    strw = new StringWriter();
    t.evaluate(context, strw, 42);
    output = strw.toString();
    Assert.assertEquals("x is 42\n", output);
    strw = new StringWriter();
    t.evaluate(context, strw, "");
    output = strw.toString();
    Assert.assertEquals("no x\n", output);
}

76. NNTPClient#listHelp()

Project: commons-net
Source File: NNTPClient.java
View license
/***
     * List the command help from the server.
     * <p>
     * @return The sever help information.
     * @throws NNTPConnectionClosedException
     *      If the NNTP server prematurely closes the connection as a result
     *      of the client being idle or some other reason causing the server
     *      to send NNTP reply code 400.  This exception may be caught either
     *      as an IOException or independently as itself.
     * @throws IOException  If an I/O error occurs while either sending a
     *      command to the server or receiving a reply from the server.
     ***/
public String listHelp() throws IOException {
    if (!NNTPReply.isInformational(help())) {
        return null;
    }
    StringWriter help = new StringWriter();
    BufferedReader reader = new DotTerminatedMessageReader(_reader_);
    Util.copyReader(reader, help);
    reader.close();
    help.close();
    return help.toString();
}

77. AddDep#cheapWordToString()

Project: CoreNLP
Source File: AddDep.java
View license
// Simple mapping of all the stuff we care about (until IndexedFeatureLabel --> CoreLabel map pain is fixed)
/**
   * This converts the node into a simple string based representation.
   * NOTE: this is extremely brittle, and presumes values do not contain delimiters
   */
public static String cheapWordToString(IndexedWord node) {
    StringWriter buf = new StringWriter();
    buf.write("{");
    buf.write(WORD_KEY);
    buf.write(TUPLE_DELIMITER);
    buf.write(nullShield(node.word()));
    buf.write(ATOM_DELIMITER);
    buf.write(LEMMA_KEY);
    buf.write(TUPLE_DELIMITER);
    buf.write(nullShield(node.lemma()));
    buf.write(ATOM_DELIMITER);
    buf.write(POS_KEY);
    buf.write(TUPLE_DELIMITER);
    buf.write(nullShield(node.tag()));
    buf.write(ATOM_DELIMITER);
    buf.write(VALUE_KEY);
    buf.write(TUPLE_DELIMITER);
    buf.write(nullShield(node.value()));
    buf.write(ATOM_DELIMITER);
    buf.write(CURRENT_KEY);
    buf.write(TUPLE_DELIMITER);
    buf.write(nullShield(node.originalText()));
    buf.write("}");
    return buf.toString();
}

78. JsonUtils#toJsonString()

Project: databus
Source File: JsonUtils.java
View license
/**
   * Serializes a bean as JSON
   * @param <T>     the bean type
   * @param bean    the bean to serialize
   * @param pretty  a flag if the output is to be pretty printed
   * @return        the JSON string
   */
public static <T> String toJsonString(T bean, boolean pretty) throws JsonGenerationException, JsonMappingException, IOException {
    JsonFactory jsonFactory = new JsonFactory(new ObjectMapper());
    StringWriter out = new StringWriter(1000);
    JsonGenerator jsonGenerator = jsonFactory.createJsonGenerator(out);
    if (pretty)
        jsonGenerator.useDefaultPrettyPrinter();
    jsonGenerator.writeObject(bean);
    out.flush();
    return out.toString();
}

79. QueryGraphValue#toString()

Project: esper
Source File: QueryGraphValue.java
View license
public String toString() {
    StringWriter writer = new StringWriter();
    writer.append("QueryGraphValue ");
    String delimiter = "";
    for (QueryGraphValueDesc desc : items) {
        writer.append(delimiter);
        writer.append(ExprNodeUtility.toExpressionStringMinPrecedence(desc.getIndexExprs()));
        writer.append(": ");
        writer.append(desc.getEntry().toString());
        delimiter = ", ";
    }
    return writer.toString();
}

80. SchemaUtil#serialize()

Project: esper
Source File: SchemaUtil.java
View license
/**
     * Serialize the given node.
     * @param doc node to serialize
     * @return serialized node string
     */
public static String serialize(Node doc) {
    StringWriter writer = new StringWriter();
    try {
        serializeNode(doc, "", writer);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    writer.flush();
    return writer.toString();
}

81. TestSingleRowFunctionPlugIn#runVarargAssertion()

View license
private void runVarargAssertion(UniformPair<String>... pairs) {
    StringWriter buf = new StringWriter();
    buf.append("@name('test') select ");
    int count = 0;
    for (UniformPair<String> pair : pairs) {
        buf.append(pair.getFirst());
        buf.append(" as c");
        buf.append(Integer.toString(count));
        count++;
        buf.append(",");
    }
    buf.append("intPrimitive from SupportBean");
    epService.getEPAdministrator().createEPL(buf.toString()).addListener(listener);
    epService.getEPRuntime().sendEvent(new SupportBean());
    EventBean out = listener.assertOneGetNewAndReset();
    count = 0;
    for (UniformPair<String> pair : pairs) {
        assertEquals("failed for '" + pair.getFirst() + "'", pair.getSecond(), out.get("c" + count));
        count++;
    }
    epService.getEPAdministrator().getStatement("test").destroy();
}

82. FilterSpec#toString()

Project: ferret
Source File: FilterSpec.java
View license
@Override
public String toString() {
    StringWriter sw = new StringWriter();
    sw.append("{ minDist: " + minDist + ", maxDist: " + maxDist + ", limit: " + limit + ", maxSubSequenceSize: " + maxSubSequenceSize + ", minSubSequenceSize: " + minSubSequenceSize + ", attributeKey: " + attributeKey + ", operator: " + operator + ", value: " + value + ", value2: " + value2 + " }");
    return sw.toString();
}

83. XMLWriterTest#temp()

Project: grobid
Source File: XMLWriterTest.java
View license
@Test
public void temp() throws TransformerException {
    StringWriter sw = new StringWriter();
    sw.write("<test>some test</test>");
    TransformerFactory factory = TransformerFactory.newInstance();
    Transformer transformer = factory.newTransformer();
    transformer.setOutputProperty(OutputKeys.INDENT, "yes");
    transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");
    StringWriter formattedStringWriter = new StringWriter();
    transformer.transform(new StreamSource(new StringReader(sw.toString())), new StreamResult(formattedStringWriter));
    System.out.println(formattedStringWriter);
    System.out.println(XMLWriter.formatXML("<test>some test</test>"));
}

84. StringConverter#inputStreamToString()

Project: h-store
Source File: StringConverter.java
View license
public static String inputStreamToString(InputStream x, String encoding) throws IOException {
    InputStreamReader in = new InputStreamReader(x, encoding);
    StringWriter writer = new StringWriter();
    int blocksize = 8 * 1024;
    char[] buffer = new char[blocksize];
    for (; ; ) {
        int read = in.read(buffer);
        if (read == -1) {
            break;
        }
        writer.write(buffer, 0, read);
    }
    writer.close();
    return writer.toString();
}

85. MoreoverClient#getArticles()

View license
private String getArticles(URL url) throws IOException {
    HttpURLConnection cn = (HttpURLConnection) url.openConnection();
    cn.setRequestMethod("GET");
    cn.addRequestProperty("Content-Type", "text/xml;charset=UTF-8");
    cn.setDoInput(true);
    cn.setDoOutput(false);
    StringWriter writer = new StringWriter();
    IOUtils.copy(new InputStreamReader(cn.getInputStream(), Charset.forName("UTF-8")), writer);
    writer.flush();
    pullTime = new Date().getTime();
    // added after seeing java.net.SocketException: Too many open files
    cn.disconnect();
    return writer.toString();
}

86. JSONValueTest#testArraysOfArrays()

Project: json-simple
Source File: JSONValueTest.java
View license
public void testArraysOfArrays() throws IOException {
    StringWriter writer;
    final int[][][] nestedIntArray = new int[][][] { { { 1 }, { 5 } }, { { 2 }, { 6 } } };
    final String expectedNestedIntString = "[[[1],[5]],[[2],[6]]]";
    assertEquals(expectedNestedIntString, JSONValue.toJSONString(nestedIntArray));
    writer = new StringWriter();
    JSONValue.writeJSONString(nestedIntArray, writer);
    assertEquals(expectedNestedIntString, writer.toString());
    final String[][] nestedStringArray = new String[][] { { "a", "b" }, { "c", "d" } };
    final String expectedNestedStringString = "[[\"a\",\"b\"],[\"c\",\"d\"]]";
    assertEquals(expectedNestedStringString, JSONValue.toJSONString(nestedStringArray));
    writer = new StringWriter();
    JSONValue.writeJSONString(nestedStringArray, writer);
    assertEquals(expectedNestedStringString, writer.toString());
}

87. DoapUtilTest#testWriteElement()

Project: maven-plugins
Source File: DoapUtilTest.java
View license
/**
     * Test method for [email protected] DoapUtil#writeElement(XMLWriter, String, String, String)}.
     *
     * @throws Exception if any
     */
public void testWriteElement() throws Exception {
    StringWriter w = new StringWriter();
    XMLWriter writer = new PrettyPrintXMLWriter(w);
    DoapUtil.writeElement(writer, null, "name", "value");
    w.close();
    assertEquals(w.toString(), "<name>value</name>");
    w = new StringWriter();
    writer = new PrettyPrintXMLWriter(w);
    try {
        DoapUtil.writeElement(writer, null, null, null);
        assertTrue("Null not catched", false);
    } catch (IllegalArgumentException e) {
        assertTrue("IllegalArgumentException catched", true);
    } finally {
        w.close();
    }
}

88. DoapUtilTest#testWriteRdfResourceElement()

Project: maven-plugins
Source File: DoapUtilTest.java
View license
/**
     * Test method for [email protected] DoapUtil#writeRdfResourceElement(XMLWriter, String, String)}.
     *
     * @throws Exception if any
     */
public void testWriteRdfResourceElement() throws Exception {
    StringWriter w = new StringWriter();
    XMLWriter writer = new PrettyPrintXMLWriter(w);
    DoapUtil.writeRdfResourceElement(writer, null, "name", "value");
    w.close();
    assertEquals(w.toString(), "<name " + DoapUtil.RDF_RESOURCE + "=\"value\"/>");
    w = new StringWriter();
    writer = new PrettyPrintXMLWriter(w);
    try {
        DoapUtil.writeRdfResourceElement(writer, null, null, null);
        assertTrue("Null not catched", false);
    } catch (IllegalArgumentException e) {
        assertTrue("IllegalArgumentException catched", true);
    } finally {
        w.close();
    }
}

89. AbstractUtilities#writeEntitySet()

View license
public InputStream writeEntitySet(final Accept accept, final ResWrap<EntityCollection> container) throws ODataSerializerException, IOException {
    final StringWriter writer = new StringWriter();
    if (accept == Accept.ATOM || accept == Accept.XML) {
        atomSerializer.write(writer, container);
    } else {
        jsonSerializer.write(writer, container);
    }
    writer.flush();
    writer.close();
    return IOUtils.toInputStream(writer.toString(), Constants.ENCODING);
}

90. XMLParseUtil#getStringFromElement()

Project: socialauth
Source File: XMLParseUtil.java
View license
public static String getStringFromElement(Element doc) throws TransformerException {
    DOMSource domSource = new DOMSource(doc);
    StringWriter writer = new StringWriter();
    StreamResult result = new StreamResult(writer);
    TransformerFactory tf = TransformerFactory.newInstance();
    Transformer transformer = tf.newTransformer();
    // transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
    // transformer.setOutputProperty(OutputKeys.INDENT, "yes");
    transformer.transform(domSource, result);
    writer.flush();
    return writer.toString();
}

91. MoreoverClient#getArticles()

Project: streams
Source File: MoreoverClient.java
View license
private String getArticles(URL url) throws IOException {
    HttpURLConnection cn = (HttpURLConnection) url.openConnection();
    cn.setRequestMethod("GET");
    cn.addRequestProperty("Content-Type", "text/xml;charset=UTF-8");
    cn.setDoInput(true);
    cn.setDoOutput(false);
    StringWriter writer = new StringWriter();
    IOUtils.copy(new InputStreamReader(cn.getInputStream(), Charset.forName("UTF-8")), writer);
    writer.flush();
    pullTime = new Date().getTime();
    return writer.toString();
}

92. PublisherRendererTest#testWrite()

View license
/**
     * Tests
     * [email protected] PublisherRenderer#render(String, Request)}.
     *
     * @throws IOException If something goes wrong during rendition.
     */
@Test
public void testWrite() throws IOException {
    StringWriter writer = new StringWriter();
    Request requestContext = createMock(Request.class);
    RendererListener listener = createMock(RendererListener.class);
    listener.start("Result", requestContext);
    expect(requestContext.getWriter()).andReturn(writer);
    listener.end("Result", requestContext);
    replay(requestContext);
    renderer.addListener(listener);
    renderer.render("Result", requestContext);
    writer.close();
    writer.toString();
    verify(requestContext);
}

93. ChainedUberspectorsTestCase#testChaining()

View license
public void testChaining() throws Exception {
    VelocityContext context = new VelocityContext();
    context.put("foo", new Foo());
    StringWriter writer = new StringWriter();
    Velocity.evaluate(context, writer, "test", "$foo.zeMethod()");
    assertEquals(writer.toString(), "ok");
    Velocity.evaluate(context, writer, "test", "#set($foo.foo = 'someValue')");
    writer = new StringWriter();
    Velocity.evaluate(context, writer, "test", "$foo.bar");
    assertEquals(writer.toString(), "someValue");
    writer = new StringWriter();
    Velocity.evaluate(context, writer, "test", "$foo.foo");
    assertEquals(writer.toString(), "someValue");
}

94. UberspectImplTestCase#testPrivateIterator()

View license
public void testPrivateIterator() throws Exception {
    VelocityContext context = new VelocityContext();
    context.put("privateClass", new PrivateClass());
    context.put("privateMethod", new PrivateMethod());
    context.put("publicMethod", new PublicMethod());
    StringWriter writer = new StringWriter();
    Velocity.evaluate(context, writer, "test", "#foreach($i in $privateClass)$i#end");
    assertEquals(writer.toString(), "");
    writer = new StringWriter();
    Velocity.evaluate(context, writer, "test", "#foreach($i in $privateMethod)$i#end");
    assertEquals(writer.toString(), "");
    writer = new StringWriter();
    Velocity.evaluate(context, writer, "test", "#foreach($i in $publicMethod)$i#end");
    assertEquals(writer.toString(), "123");
}

95. RebalancerState#toJsonString()

Project: voldemort
Source File: RebalancerState.java
View license
public String toJsonString() {
    List<Map<String, Object>> maps = Lists.newLinkedList();
    for (RebalanceTaskInfo rebalanceTaskInfo : stealInfoMap.values()) maps.add(rebalanceTaskInfo.asMap());
    StringWriter stringWriter = new StringWriter();
    new JsonWriter(stringWriter).write(maps);
    stringWriter.flush();
    return stringWriter.toString();
}

96. StringConverter#inputStreamToString()

Project: voltdb
Source File: StringConverter.java
View license
public static String inputStreamToString(InputStream x, String encoding) throws IOException {
    InputStreamReader in = new InputStreamReader(x, encoding);
    StringWriter writer = new StringWriter();
    int blocksize = 8 * 1024;
    char[] buffer = new char[blocksize];
    for (; ; ) {
        int read = in.read(buffer);
        if (read == -1) {
            break;
        }
        writer.write(buffer, 0, read);
    }
    writer.close();
    return writer.toString();
}

97. JsonSerializationFramework#serializeAsJson()

View license
public <T> String serializeAsJson(String type, T object, boolean pretty) {
    StringWriter writer = new StringWriter();
    JsonWriteGenericRecord record = new JsonWriteGenericRecord(writer, pretty);
    record.open();
    getSerializer(type).serialize(object, record);
    record.close();
    writer.flush();
    return writer.toString();
}

98. JsonSerializationFramework#serializeJsonMap()

View license
public <K, V> String serializeJsonMap(String keyType, String valueType, Map<K, V> map, boolean pretty) {
    NFTypeSerializer<K> keySerializer = getSerializer(keyType);
    NFTypeSerializer<V> valueSerializer = getSerializer(valueType);
    MapSerializer<K, V> mapSerializer = new MapSerializer<K, V>(keySerializer, valueSerializer);
    mapSerializer.setSerializationFramework(this);
    StringWriter writer = new StringWriter();
    JsonWriteGenericRecord record = new JsonWriteGenericRecord(writer, pretty);
    record.open();
    mapSerializer.serialize(map, record);
    record.close();
    writer.flush();
    return writer.toString();
}

99. JSONWriterTest#testTypes()

Project: lucene-solr
Source File: JSONWriterTest.java
View license
@Test
public void testTypes() throws IOException {
    SolrQueryRequest req = req("dummy");
    SolrQueryResponse rsp = new SolrQueryResponse();
    QueryResponseWriter w = new PythonResponseWriter();
    StringWriter buf = new StringWriter();
    rsp.add("data1", Float.NaN);
    rsp.add("data2", Double.NEGATIVE_INFINITY);
    rsp.add("data3", Float.POSITIVE_INFINITY);
    w.write(buf, req, rsp);
    jsonEq(buf.toString(), "{'data1':float('NaN'),'data2':-float('Inf'),'data3':float('Inf')}");
    w = new RubyResponseWriter();
    buf = new StringWriter();
    w.write(buf, req, rsp);
    jsonEq(buf.toString(), "{'data1'=>(0.0/0.0),'data2'=>-(1.0/0.0),'data3'=>(1.0/0.0)}");
    w = new JSONResponseWriter();
    buf = new StringWriter();
    w.write(buf, req, rsp);
    jsonEq(buf.toString(), "{\"data1\":\"NaN\",\"data2\":\"-Infinity\",\"data3\":\"Infinity\"}");
    req.close();
}

100. ConfigurationImpl#debugConnectors()

View license
@Override
public String debugConnectors() {
    StringWriter stringWriter = new StringWriter();
    PrintWriter writer = new PrintWriter(stringWriter);
    for (Map.Entry<String, TransportConfiguration> connector : getConnectorConfigurations().entrySet()) {
        writer.println("Connector::" + connector.getKey() + " value = " + connector.getValue());
    }
    writer.close();
    return stringWriter.toString();
}