Example #1
0
  /**
   * Load a copy.
   *
   * @param file
   * @return
   * @throws IOException
   * @throws CuboidCopyException
   */
  public static CuboidCopy load(File file) throws IOException, CuboidCopyException {
    FileInputStream in = new FileInputStream(file);
    DataInputStream reader = new DataInputStream(in);

    int x, y, z;
    int width, height, length;
    byte[] blocks;
    byte[] data;

    try {
      @SuppressWarnings("unused")
      byte version = reader.readByte();
      x = reader.readInt();
      y = reader.readInt();
      z = reader.readInt();
      width = reader.readInt();
      height = reader.readInt();
      length = reader.readInt();
      int size = width * height * length;
      blocks = new byte[size];
      data = new byte[size];
      if (reader.read(blocks, 0, size) != size) {
        throw new CuboidCopyException("File error: Bad size");
      }
      data = new byte[size];
      if (reader.read(data, 0, size) != size) {
        throw new CuboidCopyException("File error: Bad size");
      }
    } finally {
      try {
        in.close();
      } catch (IOException e) {
      }
    }

    CuboidCopy copy = new CuboidCopy();
    copy.origin = new Vector(x, y, z);
    copy.width = width;
    copy.height = height;
    copy.length = length;
    copy.blocks = blocks;
    copy.data = data;
    copy.findTestOffset();

    return copy;
  }