本文整理汇总了Java中com.alibaba.fastjson.serializer.SerializeWriter.close方法的典型用法代码示例。如果您正苦于以下问题:Java SerializeWriter.close方法的具体用法?Java SerializeWriter.close怎么用?Java SerializeWriter.close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.alibaba.fastjson.serializer.SerializeWriter
的用法示例。
在下文中一共展示了SerializeWriter.close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: toJSONBytes
import com.alibaba.fastjson.serializer.SerializeWriter; //导入方法依赖的package包/类
public static final byte[] toJSONBytes(Object object, SerializeConfig config, SerializerFeature... features) {
SerializeWriter out = new SerializeWriter();
try {
JSONSerializer serializer = new JSONSerializer(out, config);
for (com.alibaba.fastjson.serializer.SerializerFeature feature : features) {
serializer.config(feature, true);
}
serializer.write(object);
return out.toBytes("UTF-8");
} finally {
out.close();
}
}
示例2: toJSONStringWithDateFormat
import com.alibaba.fastjson.serializer.SerializeWriter; //导入方法依赖的package包/类
public static final String toJSONStringWithDateFormat(Object object, String dateFormat, SerializerFeature... features) {
SerializeWriter out = new SerializeWriter();
try {
JSONSerializer serializer = new JSONSerializer(out);
for (SerializerFeature feature : features) {
serializer.config(feature, true);
}
serializer.config(SerializerFeature.WriteDateUseDateFormat, true);
if (dateFormat != null) {
serializer.setDateFormat(dateFormat);
}
serializer.write(object);
String serializeWriter = out.toString();
return serializeWriter;
} finally {
out.close();
}
}
示例3: test_erro_0
import com.alibaba.fastjson.serializer.SerializeWriter; //导入方法依赖的package包/类
public void test_erro_0() throws Exception {
SerializeWriter out = new SerializeWriter();
Exception error = null;
try {
out.write(new char[0], -1, 0);
} catch (Exception ex) {
error = ex;
}
Assert.assertNotNull(error);
out.close();
}
示例4: test_erro_0
import com.alibaba.fastjson.serializer.SerializeWriter; //导入方法依赖的package包/类
public void test_erro_0() throws Exception {
SerializeWriter out = new SerializeWriter(new ErrorWriter());
Exception error = null;
try {
out.flush();
} catch (Exception ex) {
error = ex;
}
Assert.assertNotNull(error);
out.close();
}
示例5: test_error
import com.alibaba.fastjson.serializer.SerializeWriter; //导入方法依赖的package包/类
public void test_error() throws Exception {
SerializeWriter writer = new SerializeWriter(new StringWriter());
Exception error = null;
try {
writer.writeTo(new StringWriter());
} catch (Exception ex) {
error = ex;
}
Assert.assertNotNull(error);
writer.close();
}
示例6: test_0
import com.alibaba.fastjson.serializer.SerializeWriter; //导入方法依赖的package包/类
public void test_0() throws Exception {
StringWriter out = new StringWriter();
SerializeWriter writer = new SerializeWriter(out, 10);
Assert.assertEquals(10, writer.getBufferLength());
writer.config(SerializerFeature.QuoteFieldNames, true);
writer.writeFieldValue(',', "abcde01245abcde", true);
writer.close();
String text = out.toString();
Assert.assertEquals(",\"abcde01245abcde\":true", text);
}
示例7: test_0
import com.alibaba.fastjson.serializer.SerializeWriter; //导入方法依赖的package包/类
public void test_0() throws Exception {
StringWriter out = new StringWriter();
SerializeWriter writer = new SerializeWriter(out, 10);
Assert.assertEquals(10, writer.getBufferLength());
writer.writeFieldValue(',', "abcde01245abcde", true);
writer.close();
String text = out.toString();
Assert.assertEquals(",abcde01245abcde:true", text);
}
示例8: test_0
import com.alibaba.fastjson.serializer.SerializeWriter; //导入方法依赖的package包/类
public void test_0() throws Exception {
StringWriter out = new StringWriter();
SerializeWriter writer = new SerializeWriter(out, 10);
Assert.assertEquals(10, writer.getBufferLength());
writer.write("abcde");
writer.writeInt(12345678);
writer.close();
String text = out.toString();
Assert.assertEquals("abcde12345678", text);
}
示例9: test_0
import com.alibaba.fastjson.serializer.SerializeWriter; //导入方法依赖的package包/类
public void test_0() throws Exception {
StringWriter out = new StringWriter();
SerializeWriter writer = new SerializeWriter(out, 10);
Assert.assertEquals(10, writer.getBufferLength());
writer.writeString("abcde12345678\"\\");
writer.close();
String text = out.toString();
Assert.assertEquals("\"abcde12345678\\\"\\\\\"", text);
}
示例10: toJSONStringZ
import com.alibaba.fastjson.serializer.SerializeWriter; //导入方法依赖的package包/类
public static final String toJSONStringZ(Object object, SerializeConfig mapping, SerializerFeature... features) {
SerializeWriter out = new SerializeWriter(features);
try {
new JSONSerializer(out, mapping).write(object);
String serializeWriter = out.toString();
return serializeWriter;
} finally {
out.close();
}
}
示例11: test_writer_1
import com.alibaba.fastjson.serializer.SerializeWriter; //导入方法依赖的package包/类
@SuppressWarnings("rawtypes")
public void test_writer_1() throws Exception {
StringWriter strOut = new StringWriter();
SerializeWriter out = new SerializeWriter(strOut, 1);
try {
JSONSerializer serializer = new JSONSerializer(out);
Map map = Collections.singletonMap("", "a");
serializer.write(map);
} finally {
out.close();
}
Assert.assertEquals("{\"\":\"a\"}", strOut.toString());
}
示例12: test_0
import com.alibaba.fastjson.serializer.SerializeWriter; //导入方法依赖的package包/类
public void test_0() throws Exception {
StringWriter out = new StringWriter();
byte[] bytes = "民主共和君主宪".getBytes("GB2312");
SerializeWriter writer = new SerializeWriter(out, 10);
Assert.assertEquals(10, writer.getBufferLength());
writer.writeByteArray(bytes);
writer.close();
String text = out.toString();
byte[] result = JSON.parseObject(text, byte[].class);
Assert.assertEquals("民主共和君主宪", new String(result, "GB2312"));
}
示例13: test_0
import com.alibaba.fastjson.serializer.SerializeWriter; //导入方法依赖的package包/类
public void test_0() throws Exception {
StringWriter out = new StringWriter();
SerializeWriter writer = new SerializeWriter(out, 10);
Assert.assertEquals(10, writer.getBufferLength());
writer.write("abcde");
writer.writeInt(12345678);
writer.write(',');
writer.close();
String text = out.toString();
Assert.assertEquals("abcde12345678,", text);
}
示例14: test_0
import com.alibaba.fastjson.serializer.SerializeWriter; //导入方法依赖的package包/类
public void test_0() throws Exception {
StringWriter out = new StringWriter();
SerializeWriter writer = new SerializeWriter(out, 10);
writer.config(SerializerFeature.QuoteFieldNames, true);
Assert.assertEquals(10, writer.getBufferLength());
writer.writeFieldValue(',', "abcde01245abcde", 123);
writer.close();
String text = out.toString();
Assert.assertEquals(",\"abcde01245abcde\":123", text);
}
示例15: test_0
import com.alibaba.fastjson.serializer.SerializeWriter; //导入方法依赖的package包/类
public void test_0() throws Exception {
StringWriter out = new StringWriter();
SerializeWriter writer = new SerializeWriter(out, 10);
writer.config(SerializerFeature.BrowserCompatible, true);
Assert.assertEquals(10, writer.getBufferLength());
writer.writeString("abcde12345678\t");
writer.close();
String text = out.toString();
Assert.assertEquals("\"abcde12345678\\t\"", text);
}