コード例 #1
0
ファイル: Unknown.java プロジェクト: kayahr/wlandsuite
  /**
   * Creates a new unknown block by reading the specified number of bytes from the specified stream.
   *
   * @param stream The input stream
   * @param size The number of bytes to read
   * @return The unknown block
   * @throws IOException When file operation fails.
   */
  public static Unknown read(final InputStream stream, final int size) throws IOException {
    Unknown unknown;

    unknown = new Unknown();
    unknown.bytes = new byte[size];
    stream.read(unknown.bytes);
    return unknown;
  }
コード例 #2
0
ファイル: Unknown.java プロジェクト: kayahr/wlandsuite
  /**
   * Creates and returns a new Unknown object by reading its data from XML.
   *
   * @param element The XML element
   * @param size The unknown block size.
   * @return The Unknown object
   */
  public static Unknown read(final Element element, final int size) {
    Unknown unknown;
    ByteArrayOutputStream byteStream;
    String data;

    unknown = new Unknown();
    data = element.getTextTrim();
    byteStream = new ByteArrayOutputStream();
    for (final String b : data.split("\\s")) {
      byteStream.write(Integer.parseInt(b, 16));
    }
    unknown.bytes = byteStream.toByteArray();
    if (unknown.bytes.length != size) {
      throw new GameException(
          "Invalid unknown block size: " + unknown.bytes.length + ". Should be: " + size);
    }

    return unknown;
  }