Example usage for java.io DataInputStream readUnsignedByte

List of usage examples for java.io DataInputStream readUnsignedByte

Introduction

In this page you can find the example usage for java.io DataInputStream readUnsignedByte.

Prototype

public final int readUnsignedByte() throws IOException 

Source Link

Document

See the general contract of the readUnsignedByte method of DataInput.

Usage

From source file:VASSAL.tools.imports.adc2.MapBoard.java

/**
 * Hex lines are like spokes of the hex and are typically used for things like roads or other elements that
 * traverse from hex to hex.  The direction of each spoke is encoded as bit flags, and while ADC2 could encode
 * each hex with only one record, modules typically have a separate record for every spoke resulting in
 * data inflation./*from w  w w.  j  ava 2 s. c  om*/
 */
protected void readHexLineBlock(DataInputStream in) throws IOException {
    ADC2Utils.readBlockHeader(in, "Hex Line");

    int nHexLines = ADC2Utils.readBase250Word(in);
    for (int i = 0; i < nHexLines; ++i) {
        int index = ADC2Utils.readBase250Word(in);
        int line = in.readUnsignedByte();
        int direction = in.readUnsignedShort();
        if (isOnMapBoard(index))
            hexLines.add(new HexLine(index, line, direction));
    }
}

From source file:VASSAL.tools.imports.adc2.MapBoard.java

/**
 * Information about hex sides which are used for things like rivers, etc. is read in.
 *///from  w w w. j a va2s.co m
protected void readHexSideBlock(DataInputStream in) throws IOException {
    ADC2Utils.readBlockHeader(in, "Hex Side");

    int nHexSides = ADC2Utils.readBase250Word(in);
    for (int i = 0; i < nHexSides; ++i) {
        int index = ADC2Utils.readBase250Word(in);
        int line = in.readUnsignedByte();
        int side = in.readUnsignedByte();
        if (isOnMapBoard(index))
            hexSides.add(new HexSide(index, line, side));
    }
}

From source file:VASSAL.tools.imports.adc2.MapBoard.java

/**
 * Information about the width, colour and style of hex sides and hex lines is read in.
 */// w ww.j  av  a  2s  .  c o m
protected void readLineDefinitionBlock(DataInputStream in) throws IOException {
    ADC2Utils.readBlockHeader(in, "Line Definition");

    int nLineDefinitions = in.readUnsignedByte();
    lineDefinitions = new LineDefinition[nLineDefinitions];
    for (int i = 0; i < nLineDefinitions; ++i) {
        int colorIndex = in.readUnsignedByte();
        Color color = ADC2Utils.getColorFromIndex(colorIndex);
        int size = 0;
        for (int j = 0; j < 3; ++j) {
            int s = in.readByte();
            if (j == zoomLevel)
                size = s;
        }
        // only used when editing ADC2 maps within ADC2.
        /* String name = */ readNullTerminatedString(in, 25);
        int styleByte = in.readUnsignedByte();
        LineStyle style;
        switch (styleByte) {
        case 2:
            style = LineStyle.DOTTED;
            break;
        case 3:
            style = LineStyle.DASH_DOT;
            break;
        case 4:
            style = LineStyle.DASHED;
            break;
        case 5:
            style = LineStyle.DASH_DOT_DOT;
            break;
        default:
            style = LineStyle.SOLID;
        }

        if (size > 0)
            lineDefinitions[i] = new LineDefinition(color, size, style);
        else
            lineDefinitions[i] = null;
    }
}

From source file:VASSAL.tools.imports.adc2.MapBoard.java

/**
 * Read what order to draw the lines in.
 *///from   www.  j  a va2 s  .c om
protected void readLineDrawPriorityBlock(DataInputStream in) throws IOException {
    ADC2Utils.readBlockHeader(in, "Line Draw Priority");

    in.readByte(); // unused.

    // there can only be 10 line definitions. however drawning priorities for hex sides and hex lines
    // are completely independent
    for (int i = 1; i <= 10; ++i) {
        int index = in.readUnsignedByte();
        if (index < lineDefinitions.length && lineDefinitions[index] != null)
            lineDefinitions[index].setHexLineDrawPriority(i);
    }

    for (int i = 1; i <= 10; ++i) {
        int index = in.readUnsignedByte();
        if (index < lineDefinitions.length && lineDefinitions[index] != null)
            lineDefinitions[index].setHexSideDrawPriority(i);
    }
}

From source file:VASSAL.tools.imports.adc2.MapBoard.java

/**
 * Read information on hex numbering.//from w w  w.  jav a 2s  . co  m
 */
protected void readMapSheetBlock(DataInputStream in) throws IOException {
    ADC2Utils.readBlockHeader(in, "Map Sheet");

    int nMapSheets = ADC2Utils.readBase250Word(in);
    for (int i = 0; i < nMapSheets; ++i) {
        int x1 = ADC2Utils.readBase250Word(in);
        int y1 = ADC2Utils.readBase250Word(in);
        int x2 = ADC2Utils.readBase250Word(in);
        int y2 = ADC2Utils.readBase250Word(in);
        Rectangle r = new Rectangle(x1, y1, x2 - x1 + 1, y2 - y1 + 1);
        // must be exactly 9 bytes or 10 if there's a terminating null at the end
        String name = readNullTerminatedString(in, 10);
        if (name.length() < 9)
            in.readFully(new byte[9 - name.length()]);
        int style = in.readUnsignedByte();
        in.readFully(new byte[2]);
        int nColChars = in.readUnsignedByte();
        int nRowChars = in.readUnsignedByte();
        if (i < nMapSheets - 1) // the last one is always ignored.
            mapSheets.add(new MapSheet(name, r, style, nColChars, nRowChars));
    }
}

From source file:VASSAL.tools.imports.adc2.MapBoard.java

/**
 * Read in information on hex sheets which define the hex numbering systems. This represents supplemental
 * information--some map sheet info occurs earlier in the file.  Only the coordinates of the top-left corner
 * are read in here./*www. j av a  2s.  c om*/
 */
protected void readHexNumberingBlock(DataInputStream in) throws IOException {
    ADC2Utils.readBlockHeader(in, "Hex Numbering");

    for (int i = 0; i < mapSheets.size() + 1; ++i) {
        // rare case when integers are not base-250. However, they are big-endian despite being a
        // Windows application.
        int col = 0;
        for (int j = 0; j < 4; ++j) {
            col <<= 8;
            col += in.readUnsignedByte();
        }
        int row = 0;
        for (int j = 0; j < 4; ++j) {
            row <<= 8;
            row += in.readUnsignedByte();
        }
        if (i < mapSheets.size()) {
            MapSheet ms = mapSheets.get(i);
            ms.setTopLeftCol(col);
            ms.setTopLeftRow(row);
        }
    }
}

From source file:VASSAL.tools.imports.adc2.MapBoard.java

/**
 * The colour to fill before any elements are drawn. The fast-scroll flag is also read.
 *///from  ww w . j  a  v  a2s . c  o m
protected void readTableColorBlock(DataInputStream in) throws IOException {
    ADC2Utils.readBlockHeader(in, "Table Color");

    /* int fastScrollFlag = */ in.readByte();
    tableColor = ADC2Utils.getColorFromIndex(in.readUnsignedByte());
}

From source file:VASSAL.tools.imports.adc2.MapBoard.java

/**
 * Optional labels that can be added to hexes.  Can also include a symbol that can be added with the label.
 *//*from  w w  w  .j  a  v  a2 s  .c  om*/
protected void readPlaceNameBlock(DataInputStream in) throws IOException {
    ADC2Utils.readBlockHeader(in, "Place Name");

    int nNames = ADC2Utils.readBase250Word(in);
    for (int i = 0; i < nNames; ++i) {
        int index = ADC2Utils.readBase250Word(in);
        // extra hex symbol
        SymbolSet.SymbolData symbol = getSet().getMapBoardSymbol(ADC2Utils.readBase250Word(in));
        if (symbol != null && isOnMapBoard(index))
            placeSymbols.add(new HexData(index, symbol));
        String text = readNullTerminatedString(in, 25);
        Color color = ADC2Utils.getColorFromIndex(in.readUnsignedByte());

        int size = 0;
        for (int z = 0; z < 3; ++z) {
            int b = in.readUnsignedByte();
            if (z == zoomLevel)
                size = b;
        }

        PlaceNameOrientation orientation = null;
        for (int z = 0; z < 3; ++z) {
            int o = in.readByte();
            if (z == zoomLevel) {
                switch (o) {
                case 1:
                    orientation = PlaceNameOrientation.LOWER_CENTER;
                    break;
                case 2:
                    orientation = PlaceNameOrientation.UPPER_CENTER;
                    break;
                case 3:
                    orientation = PlaceNameOrientation.LOWER_RIGHT;
                    break;
                case 4:
                    orientation = PlaceNameOrientation.UPPER_RIGHT;
                    break;
                case 5:
                    orientation = PlaceNameOrientation.UPPER_LEFT;
                    break;
                case 6:
                    orientation = PlaceNameOrientation.LOWER_LEFT;
                    break;
                case 7:
                    orientation = PlaceNameOrientation.CENTER_LEFT;
                    break;
                case 8:
                    orientation = PlaceNameOrientation.CENTER_RIGHT;
                    break;
                case 9:
                    orientation = PlaceNameOrientation.HEX_CENTER;
                    break;
                }
            }
        }

        int font = in.readUnsignedByte();

        if (!isOnMapBoard(index) || text.length() == 0 || orientation == null)
            continue;

        placeNames.add(new PlaceName(index, text, color, orientation, size, font));
    }
}