}
public void writeTags() {
BufferHelper bufh = new BufferHelper();
ByteHelper bh = new ByteHelper();
FlvTag tmpFlvt = null;
int fpos = 0;
byte buf[] = null;
byte type[] = null;
byte dsize[] = null;
byte tstamp[] = null;
byte prevTagSize[] = null;
byte ender[] = bh.getUintBytes(0, 4);
try {
stream.open();
} catch (Exception ex) {
System.out.println("Error - unable to open specified output file");
if (debug) ex.printStackTrace();
return;
}
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;
}
if (prevTagSize != null) stream.write(bufh.byte2buffer(prevTagSize));