All Downloads are FREE. Search and download functionalities are using the official Maven repository.

hprose.io.serialize.StringBufferSerializer Maven / Gradle / Ivy

/**********************************************************\
|                                                          |
|                          hprose                          |
|                                                          |
| Official WebSite: http://www.hprose.com/                 |
|                   http://www.hprose.org/                 |
|                                                          |
\**********************************************************/
/**********************************************************\
 *                                                        *
 * StringBufferSerializer.java                            *
 *                                                        *
 * StringBuffer serializer class for Java.                *
 *                                                        *
 * LastModified: Aug 6, 2016                              *
 * Author: Ma Bingyao                   *
 *                                                        *
\**********************************************************/

package hprose.io.serialize;

import static hprose.io.HproseTags.TagEmpty;
import static hprose.io.HproseTags.TagString;
import java.io.IOException;
import java.io.OutputStream;

public final class StringBufferSerializer extends ReferenceSerializer {

    public final static StringBufferSerializer instance = new StringBufferSerializer();

    @Override
    public final void serialize(Writer writer, StringBuffer s) throws IOException {
        super.serialize(writer, s);
        OutputStream stream = writer.stream;
        stream.write(TagString);
        ValueWriter.write(stream, s.toString());
    }

    @Override
    public final void write(Writer writer, StringBuffer obj) throws IOException {
        OutputStream stream = writer.stream;
        switch (obj.length()) {
            case 0:
                stream.write(TagEmpty);
                break;
            case 1:
                ValueWriter.write(stream, obj.charAt(0));
                break;
            default:
                super.write(writer, obj);
                break;
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy