Package de.ailis.xadrian.support

Examples of de.ailis.xadrian.support.DynaByteInputStream


        {
            // Decode base 64
            final byte[] data =
                DatatypeConverter.parseBase64Binary(templateCode.trim());

            final InputStream stream = new DynaByteInputStream(
                new ByteArrayInputStream(data));
            try
            {
                // Read complex settings
                final int settings = stream.read();
                final boolean hasSector = (settings & 1) == 1;
                final int gameNid = (settings >> 1) & 7;
   
                final Game game;
                try
                {
                    game = GameFactory.getInstance().getGame(gameNid);
                }
                catch (final GameNotFoundException e)
                {
                    return false;
                }
   
                // Read sector coordinates or sun power
                if (hasSector)
                {
                    final int x = stream.read();
                    final int y = stream.read();
                    if (game.getSectorFactory().getSector(x, y) == null) return false;
                }
                else
                {
                    final int percent = stream.read();
                    try
                    {
                        game.getSunFactory().getSun(percent);
                    }
                    catch (final DataException e)
                    {
                        return false;
                    }
                }
   
                int factoryId;
                while ((factoryId = stream.read()) != 0)
                {
                    final Factory factory =
                        game.getFactoryFactory().getFactory(factoryId);
                    if (factory == null) return false;
                    if (factory.isMine())
                    {
                        int yield;
                        while ((yield = stream.read()) != 0)
                            if (yield > 256) return false;
                    }
                    else
                    {
                        stream.read();
                    }
                }
   
                return true;
            }
            finally
            {
                stream.close();
            }
        }
        catch (final Exception e)
        {
            return false;
View Full Code Here


        {
            // Decode base 64
            final byte[] data =
                DatatypeConverter.parseBase64Binary(templateCode.trim());

            final InputStream stream = new DynaByteInputStream(
                new ByteArrayInputStream(data));
            try
            {
                // Read complex settings
                final int settings = stream.read();
                final boolean hasSector = (settings & 1) == 1;
                final int gameNid = (settings >> 1) & 7;
   
                final Game game = GameFactory.getInstance().getGame(gameNid);
                final Complex complex = new Complex(game);
   
                // Read sector coordinates or sun power
                if (hasSector)
                {
                    final int x = stream.read();
                    final int y = stream.read();
                    complex.setSector(game.getSectorFactory().getSector(x, y));
                }
                else
                {
                    final int percent = stream.read();
                    complex.setSuns(game.getSunFactory().getSun(percent));
                }
   
                int factoryId;
                while ((factoryId = stream.read()) != 0)
                {
                    final Factory factory =
                        game.getFactoryFactory().getFactory(factoryId);
                    if (factory.isMine())
                    {
                        final List<Integer> yields = new ArrayList<Integer>();
                        int yield;
                        while ((yield = stream.read()) != 0)
                            yields.add(yield - 1);
                        complex
                            .addFactory(new ComplexFactory(game, factory, yields));
                    }
                    else
                    {
                        final int quantity = stream.read();
                        complex.addFactory(new ComplexFactory(game, factory,
                            quantity, 0));
                    }
                }
   
                return complex;
            }
            finally
            {
                stream.close();
            }
        }
        catch (final IOException e)
        {
            throw new TemplateCodeException(e.toString(), e);
View Full Code Here

    {
        byte[] data =
            { 0, 126, 127, (byte) 128, 127, (byte) 128, 0, (byte) 129,
                (byte) 129, (byte) 129, 1 };

        InputStream stream = new DynaByteInputStream(
            new ByteArrayInputStream(data));
        try
        {
            assertEquals(0, stream.read());
            assertEquals(126, stream.read());
            assertEquals(127, stream.read());
            assertEquals(16256, stream.read());
            assertEquals(0, stream.read());
            assertEquals(2113665, stream.read());
            assertEquals(-1, stream.read());
        }
        finally
        {
            stream.close();
        }
    }
View Full Code Here

TOP

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

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.