/** * Read serialized file * * @param in * input stream * @return MapData * @throws IOException */ public static MapData deserialize(InputStream in) throws IOException { MapDataReceiver receiver = new MapDataReceiver(); FreshMapSerializer.deserialize(receiver, in); return receiver.data; }
/** * saves a static map to the given directory. * * @param header * The header to use. * @param data * The data to save. * @param out * This parameter is optional. If it is not null, the stream is used to save the map to this location. If it is null, the map is saved in the default location. * @throws IOException * If any IO error occurred. */ public synchronized void saveNewMap(jsettlers.logic.map.loading.newmap.MapFileHeader header, IMapData data, OutputStream out) throws IOException { try { if (out == null) { out = mapDirectories.iterator().next().getOutputStream(header); } header.writeTo(out); FreshMapSerializer.serialize(data, out); } finally { if (out != null) { out.close(); } } loadFileList(); }
int type = stream.readByte(); String string = stream.readUTF(); MapDataObject object = getObject(type, string); if (object != null) { data.setMapObject(x, y, object);
MapDataObject object = data.getMapObject(x, y); if (object instanceof MapTreeObject) { writeObject(stream, x, y, TYPE_TREE, ""); } else if (object instanceof StoneMapDataObject) { int capacity = ((StoneMapDataObject) object).getCapacity(); writeObject(stream, x, y, TYPE_STONE, Integer.toString(capacity)); } else if (object instanceof BuildingMapDataObject) { int player = ((BuildingMapDataObject) object).getPlayerId(); writeObject(stream, x, y, TYPE_BUILDING, ((BuildingMapDataObject) object).getType() + "," + player); } else if (object instanceof MovableObject) { int player = ((MovableObject) object).getPlayerId(); writeObject(stream, x, y, TYPE_MOVABLE, ((MovableObject) object).getType() + "," + player); } else if (object instanceof StackMapDataObject) { int capacity = ((StackMapDataObject) object).getCount(); writeObject(stream, x, y, TYPE_STACK, ((StackMapDataObject) object).getType() + "," + capacity);
@Override public IMapData getMapData() throws MapLoadException { if (data != null) { return data; } try (InputStream stream = super.getMapDataStream()) { data = new FreshMapData(); FreshMapSerializer.deserialize(data, stream); return data; } catch (IOException ex) { throw new MapLoadException(ex); } }