package org.forkalsrud.album.video;

import java.io.IOException;
import java.io.InputStream;

import junit.framework.TestCase;

import org.apache.commons.io.IOUtils;

public class FlvFilterTest extends TestCase {

    private int bodyLen = 0;

    public void testWrite() throws IOException {

        final StringBuilder buf = new StringBuilder();
        InputStream is = getClass().getResourceAsStream("/VideoAd.flv");
        FlvFilter.FlvReceiver receiver = new FlvFilter.FlvReceiver() {

            @Override
            public void writeHeader(byte[] data) {
                buf.append("HEADER[" + data.length + "]BODY[" + bodyLen + "]");
            }

            @Override
            public void writeBody(byte[] data) {
                bodyLen += data.length;
            }
        };
        FlvFilter os = new FlvFilter(receiver, new FlvMetadata());
        IOUtils.copy(is, os);
        os.generateHeaderChunk();
        assertEquals("HEADER[320]BODY[0]HEADER[800]BODY[911684]", buf.toString());
    }

    public void testFoo() {
        System.out.println(Double.longBitsToDouble(0x4062c00000000000L));
        System.out.println(Double.longBitsToDouble(0x4125c59a00000000L));
        System.out.println(Double.longBitsToDouble(0x411dcc0c00000000L));
        System.out.println(Long.toHexString(Double.doubleToLongBits(150d)));
    }

}
