Package de.ailis.xadrian.support

Examples of de.ailis.xadrian.support.DynaByteOutputStream


    {
        try
        {
            final ByteArrayOutputStream arrayStream =
                new ByteArrayOutputStream();
            final OutputStream stream = new DynaByteOutputStream(arrayStream);

            // Write the template settings bit mask.
            int settings = this.sector == null ? 0 : 1;
            settings |= this.game.getNid() << 1;
            stream.write(settings);

            // Write the sector coordinates
            if (this.sector != null)
            {
                stream.write(this.sector.getX());
                stream.write(this.sector.getY());
            }

            // Or else write the sun power
            else
            {
                stream.write(this.suns.getPercent());
            }

            // Write the factories
            for (final ComplexFactory complexFactory: getAllFactories())
            {
                if (complexFactory.isDisabled()) continue;
                final Factory factory = complexFactory.getFactory();
                stream.write(factory.getNid());
                if (factory.isMine())
                {
                    for (final int yield: complexFactory.getYields())
                        stream.write(yield + 1);
                    stream.write(0);
                }
                else
                    stream.write(complexFactory.getQuantity());
            }

            // Write end marker
            stream.write(0);
            stream.close();

            // Get byte array from stream
            final byte[] data = arrayStream.toByteArray();

            // Return base 64 encoded bytes
View Full Code Here


     */
    @Test
    public void testRead() throws IOException
    {
        ByteArrayOutputStream arrayStream = new ByteArrayOutputStream();
        OutputStream stream = new DynaByteOutputStream(arrayStream);
        try
        {
            stream.write(0);
            stream.write(126);
            stream.write(127);
            stream.write(16256);
            stream.write(0);
            stream.write(2113665);
            byte[] data = arrayStream.toByteArray();
            assertEquals(10, data.length);
            assertEquals(0, data[0]);
            assertEquals(126, data[1]);
            assertEquals(127, data[2]);
            assertEquals((byte) 128, data[3]);
            assertEquals(127, data[4]);
            assertEquals(0, data[5]);
            assertEquals((byte) 129, data[6]);
            assertEquals((byte) 129, data[7]);
            assertEquals((byte) 129, data[8]);
            assertEquals(1, data[9]);
        }
        finally
        {
            stream.close();
        }
    }
View Full Code Here

TOP

Related Classes of de.ailis.xadrian.support.DynaByteOutputStream

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.