}
stream.write(bufh.byte2buffer(flvh.getFlvHeaderBytes()));
stream.write(bufh.byte2buffer(ender));
stream.setInputStream(inStream);
for (Iterator<TagStore> iterator = tags.iterator(); iterator.hasNext();) {
TagStore ts = iterator.next();
type = bh.getUintBytes(ts.getType(), 1);
dsize = bh.getUintBytes(ts.getDataSize(), 3);
tstamp = bh.getUintBytes(ts.getTimestamp(), 3);
if (prevTagSize != null) {
buf = new byte[type.length + dsize.length + tstamp.length + ender.length + prevTagSize.length];
System.arraycopy(prevTagSize, 0, buf, 0, prevTagSize.length);
fpos += prevTagSize.length;
} else {
buf = new byte[type.length + dsize.length + tstamp.length + ender.length];
}
System.arraycopy(type, 0, buf, fpos, type.length);
fpos += type.length;
System.arraycopy(dsize, 0, buf, fpos, dsize.length);
fpos += dsize.length;
System.arraycopy(tstamp, 0, buf, fpos, tstamp.length);
fpos += tstamp.length;
System.arraycopy(ender, 0, buf, fpos, ender.length);
prevTagSize = null;
type = null;
dsize = null;
tstamp = null;
stream.write(bufh.byte2buffer(buf));
if (ts.getType() == 18 && ts.isNew()) {
stream.write(((MetaTag) ts.getTag()).getDataAsBuffer());
prevTagSize = bh.getUintBytes(((MetaTag) ts.getTag()).getDataSizeFromBuffer() - 4, 4);
} else {
tmpFlvt = (FlvTag) ts.getTag();
stream.writeDirect(tmpFlvt.getStartingOffset(), tmpFlvt.getDataSize() - 15);
prevTagSize = bh.getUintBytes(tmpFlvt.getDataSize() - 4, 4);
}
buf = null;
fpos = 0;