当前位置: 首页>>代码示例>>Java>>正文


Java SerializeWriter.writeTo方法代码示例

本文整理汇总了Java中com.alibaba.fastjson.serializer.SerializeWriter.writeTo方法的典型用法代码示例。如果您正苦于以下问题:Java SerializeWriter.writeTo方法的具体用法?Java SerializeWriter.writeTo怎么用?Java SerializeWriter.writeTo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.alibaba.fastjson.serializer.SerializeWriter的用法示例。


在下文中一共展示了SerializeWriter.writeTo方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: jsonSerialize

import com.alibaba.fastjson.serializer.SerializeWriter; //导入方法依赖的package包/类
private <T> void jsonSerialize(T t) throws IOException {
    // String text = JSON.toJSONString(t, SerializerFeature.WriteClassName, SerializerFeature.PrettyFormat);
    // System.out.println(text);

    ByteArrayOutputStream os = new ByteArrayOutputStream();
    SerializeWriter out = new SerializeWriter(SerializerFeature.WriteClassName);
    // SerializeWriter out = new SerializeWriter();
    JSONSerializer serializer = new JSONSerializer(out);
    serializer.write(t);
    out.writeTo(os, "UTF-8");
    os.toByteArray();
    //System.out.println(JSON.toJSONString(t, SerializerFeature.WriteClassName, SerializerFeature.PrettyFormat));
    //System.out.println("json " + os.toByteArray().length);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:15,代码来源:TestFastJson.java

示例2: test_erro_0

import com.alibaba.fastjson.serializer.SerializeWriter; //导入方法依赖的package包/类
public void test_erro_0() throws Exception {
    SerializeWriter out = new SerializeWriter();
    out.write(true);
    ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
    out.writeTo(byteOut, "UTF-8");
    Assert.assertEquals("true", new String(byteOut.toByteArray()));
    out.close();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:9,代码来源:SerializeWriterTest_11.java

示例3: test_0

import com.alibaba.fastjson.serializer.SerializeWriter; //导入方法依赖的package包/类
public void test_0() throws Exception {
    SerializeWriter out = new SerializeWriter(1);
    out.write('a');
    out.write('b');
    out.write('c');
    Assert.assertEquals("abc", out.toString());

    StringWriter writer = new StringWriter();
    out.writeTo(writer);
    Assert.assertEquals("abc", writer.toString());
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:12,代码来源:SerializeWriterTest.java

示例4: test_1

import com.alibaba.fastjson.serializer.SerializeWriter; //导入方法依赖的package包/类
public void test_1() throws Exception {
    SerializeWriter out = new SerializeWriter(1);
    out.write((int) 'a');
    out.write((int) 'b');
    out.write((int) 'c');
    out.write(new char[0], 0, 0);
    Assert.assertEquals("abc", out.toString());

    StringWriter writer = new StringWriter();
    out.writeTo(writer);
    Assert.assertEquals("abc", writer.toString());

    out.expandCapacity(128);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:15,代码来源:SerializeWriterTest.java

示例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();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:12,代码来源:SerializeWriterTest_9.java

示例6: test_error_2

import com.alibaba.fastjson.serializer.SerializeWriter; //导入方法依赖的package包/类
public void test_error_2() throws Exception {
    SerializeWriter writer = new SerializeWriter(new StringWriter());
    Exception error = null;
    try {
        writer.writeTo(new ByteArrayOutputStream(), Charset.forName("UTF-8"));
    } catch (Exception ex) {
        error = ex;
    }
    Assert.assertNotNull(error);
    writer.close();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:12,代码来源:SerializeWriterTest_9.java

示例7: test_error_3

import com.alibaba.fastjson.serializer.SerializeWriter; //导入方法依赖的package包/类
public void test_error_3() throws Exception {
    SerializeWriter writer = new SerializeWriter(new StringWriter());
    Exception error = null;
    try {
        writer.writeTo(new ByteArrayOutputStream(), "UTF-8");
    } catch (Exception ex) {
        error = ex;
    }
    Assert.assertNotNull(error);
    writer.close();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:12,代码来源:SerializeWriterTest_9.java

示例8: test_1

import com.alibaba.fastjson.serializer.SerializeWriter; //导入方法依赖的package包/类
public void test_1 () throws Exception {
    SerializeWriter out = new SerializeWriter(SerializerFeature.UseSingleQuotes);
    out.writeString("abc中文");
    
    ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
    out.writeTo(byteOut, "UTF-8");
    Assert.assertEquals("'abc中文'", new String(byteOut.toByteArray(), "UTF-8"));
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:9,代码来源:SerializeWriterTest_1.java

示例9: writeObject

import com.alibaba.fastjson.serializer.SerializeWriter; //导入方法依赖的package包/类
public void writeObject(Object obj) throws IOException {
    SerializeWriter out = new SerializeWriter();
    JSONSerializer serializer = new JSONSerializer(out);
    serializer.config(SerializerFeature.WriteEnumUsingToString, true);
    serializer.write(obj);
    out.writeTo(writer);
    writer.println();
    writer.flush();
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:10,代码来源:FastJsonObjectOutput.java


注:本文中的com.alibaba.fastjson.serializer.SerializeWriter.writeTo方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。