hprose.io.serialize.CollectionSerializer Maven / Gradle / Ivy
/**********************************************************\
| |
| hprose |
| |
| Official WebSite: http://www.hprose.com/ |
| http://www.hprose.org/ |
| |
\**********************************************************/
/**********************************************************\
* *
* CollectionSerializer.java *
* *
* Collection serializer class for Java. *
* *
* LastModified: Aug 6, 2016 *
* Author: Ma Bingyao *
* *
\**********************************************************/
package hprose.io.serialize;
import static hprose.io.HproseTags.TagClosebrace;
import static hprose.io.HproseTags.TagList;
import static hprose.io.HproseTags.TagOpenbrace;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Collection;
import java.util.Iterator;
public final class CollectionSerializer extends ReferenceSerializer> {
public final static CollectionSerializer instance = new CollectionSerializer();
@Override
public final void serialize(Writer writer, Collection collection) throws IOException {
super.serialize(writer, collection);
OutputStream stream = writer.stream;
stream.write(TagList);
int count = collection.size();
if (count > 0) {
ValueWriter.writeInt(stream, count);
}
stream.write(TagOpenbrace);
for (Iterator i = collection.iterator(); i.hasNext();) {
writer.serialize(i.next());
}
stream.write(TagClosebrace);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy