com.badlogic.gdx.utils.SerializationException Java Examples

The following examples show how to use com.badlogic.gdx.utils.SerializationException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BehaviorTreeReader.java    From gdx-ai with Apache License 2.0 6 votes vote down vote up
/** Parses the given reader.
 * @param reader the reader
 * @throws SerializationException if the reader cannot be successfully parsed. */
public void parse (Reader reader) {
	try {
		char[] data = new char[1024];
		int offset = 0;
		while (true) {
			int length = reader.read(data, offset, data.length - offset);
			if (length == -1) break;
			if (length == 0) {
				char[] newData = new char[data.length * 2];
				System.arraycopy(data, 0, newData, 0, data.length);
				data = newData;
			} else
				offset += length;
		}
		parse(data, 0, offset);
	} catch (IOException ex) {
		throw new SerializationException(ex);
	} finally {
		StreamUtils.closeQuietly(reader);
	}
}
 
Example #2
Source File: PracticeConfiguration.java    From beatoraja with GNU General Public License v3.0 5 votes vote down vote up
public void create(BMSModel model) {
	property.judgerank = model.getJudgerank();
	property.endtime = model.getLastTime() + 1000;
	Path p = Paths.get("practice/" + model.getSHA256() + ".json");
	if (Files.exists(p)) {
		Json json = new Json();
		try {
			property = json.fromJson(PracticeProperty.class, new FileReader(p.toFile()));
		} catch (FileNotFoundException | SerializationException e) {
			e.printStackTrace();
		}
	}

	if(property.gaugecategory == null) {
		property.gaugecategory = BMSPlayerRule.getBMSPlayerRule(model.getMode()).gauge;
	}
	this.model = model;
	if(property.total == 0) {
		property.total = model.getTotal();
	}
	FreeTypeFontGenerator generator = new FreeTypeFontGenerator(
			Gdx.files.internal("skin/default/VL-Gothic-Regular.ttf"));
	FreeTypeFontParameter parameter = new FreeTypeFontParameter();
	parameter.size = 18;
	titlefont = generator.generateFont(parameter);
	
	for(int i = 0; i < graph.length; i++) {
		graph[i].setDestination(0, 0, 0, 0, 0, 0, 255, 255, 255, 255, 0, 0, 0, 0, 0, 0, new int[0]);
	}
}
 
Example #3
Source File: Project.java    From bladecoder-adventure-engine with Apache License 2.0 5 votes vote down vote up
public void loadChapter(String selChapter) throws IOException {
	undoStack.clear();

	setSelectedScene(null);

	try {
		chapter.load(selChapter);
		firePropertyChange(NOTIFY_CHAPTER_LOADED);
		getEditorConfig().setProperty(LAST_PROJECT_PROP, projectFile.getAbsolutePath());
		getEditorConfig().setProperty("project.selectedChapter", selChapter);
	} catch (SerializationException ex) {
		// check for not compiled custom actions
		if (ex.getCause() != null && ex.getCause() instanceof ClassNotFoundException) {
			EditorLogger.msg("Custom action class not found. Trying to compile...");
			if (RunProccess.runGradle(getProjectDir(), "desktop:compileJava")) {
				((FolderClassLoader) ActionFactory.getActionClassLoader()).reload();
				chapter.load(selChapter);
			} else {
				throw new IOException("Failed to run Gradle.");
			}
		} else {
			throw ex;
		}
	}

	i18n.load(selChapter);
}
 
Example #4
Source File: BehaviorTreeReader.java    From gdx-ai with Apache License 2.0 5 votes vote down vote up
/** Parses the given input stream.
 * @param input the input stream
 * @throws SerializationException if the input stream cannot be successfully parsed. */
public void parse (InputStream input) {
	try {
		parse(new InputStreamReader(input, "UTF-8"));
	} catch (IOException ex) {
		throw new SerializationException(ex);
	} finally {
		StreamUtils.closeQuietly(input);
	}
}
 
Example #5
Source File: BehaviorTreeReader.java    From gdx-ai with Apache License 2.0 5 votes vote down vote up
/** Parses the given file.
 * @param file the file
 * @throws SerializationException if the file cannot be successfully parsed. */
public void parse (FileHandle file) {
	try {
		parse(file.reader("UTF-8"));
	} catch (Exception ex) {
		throw new SerializationException("Error parsing file: " + file, ex);
	}
}
 
Example #6
Source File: Skin.java    From gdx-skineditor with Apache License 2.0 5 votes vote down vote up
/** Adds all resources in the specified skin JSON file. */
public void load(FileHandle skinFile) {
	try {
		getJsonLoader(skinFile).fromJson(Skin.class, skinFile);
	} catch (SerializationException ex) {
		throw new SerializationException("Error reading file: " + skinFile, ex);
	}
}
 
Example #7
Source File: JsonResultUnitTests.java    From gdx-facebook with Apache License 2.0 4 votes vote down vote up
@Test(expected = SerializationException.class)
public void setJsonStringThrows() {
    fixture.setJsonString("INVALID_JSON_STRING{}");
}
 
Example #8
Source File: JsonResultUnitTests.java    From gdx-facebook with Apache License 2.0 4 votes vote down vote up
@Test(expected = SerializationException.class)
public void jsonStringConstructorThrows() {
    new JsonResult("INVALID_JSON_STRING{}");
}
 
Example #9
Source File: Project.java    From bladecoder-adventure-engine with Apache License 2.0 4 votes vote down vote up
public void loadProject(File projectToLoad) throws IOException {

		projectToLoad = checkProjectStructure(projectToLoad);

		if (projectToLoad != null) {
			// dispose the current project
			closeProject();

			this.projectFile = projectToLoad;

			// Use FolderClassLoader for loading CUSTOM actions.
			// TODO Add 'core/bin' and '/core/out' folders???
			FolderClassLoader folderClassLoader = null;

			if (new File(projectFile, "/assets").exists()) {
				folderClassLoader = new FolderClassLoader(
						projectFile.getAbsolutePath() + "/core/build/classes/java/main");
			} else {
				folderClassLoader = new FolderClassLoader(projectFile.getAbsolutePath() + "/core/build/classes/main");
			}

			ActionFactory.setActionClassLoader(folderClassLoader);
			EngineAssetManager.createEditInstance(getAssetPath());

			try {
				// Clear last project to avoid reloading if the project fails.
				getEditorConfig().remove(LAST_PROJECT_PROP);
				saveConfig();

				world.loadWorldDesc();
			} catch (SerializationException ex) {
				// check for not compiled custom actions
				if (ex.getCause() != null && ex.getCause() instanceof ClassNotFoundException) {
					EditorLogger.msg("Custom action class not found. Trying to compile...");
					if (RunProccess.runGradle(getProjectDir(), "desktop:compileJava")) {
						folderClassLoader.reload();
						world.loadWorldDesc();
					} else {
						this.projectFile = null;
						throw new IOException("Failed to run Gradle.");
					}
				} else {
					this.projectFile = null;
					throw ex;
				}
			}

			chapter = new Chapter(getAssetPath() + Project.MODEL_PATH);
			i18n = new I18NHandler(getAssetPath() + Project.MODEL_PATH);

			// No need to load the chapter. It's loaded by the chapter combo.
			// loadChapter(world.getInitChapter());

			projectConfig = new OrderedPropertiesBuilder().withSuppressDateInComment(true).withOrderingCaseSensitive().build();
			projectConfig.load(new FileInputStream(getAssetPath() + "/" + Config.PROPERTIES_FILENAME));
			modified = false;

			Display.setTitle("Adventure Editor v" + Versions.getVersion() + " - " + projectFile.getAbsolutePath());

			firePropertyChange(NOTIFY_PROJECT_LOADED);
		} else {
			closeProject();
			throw new IOException("Project not found.");
		}
	}
 
Example #10
Source File: BehaviorTreeReader.java    From gdx-ai with Apache License 2.0 4 votes vote down vote up
private static String unescape (String value) {
	int length = value.length();
	StringBuilder buffer = new StringBuilder(length + 16);
	for (int i = 0; i < length;) {
		char c = value.charAt(i++);
		if (c != '\\') {
			buffer.append(c);
			continue;
		}
		if (i == length) break;
		c = value.charAt(i++);
		if (c == 'u') {
			buffer.append(Character.toChars(Integer.parseInt(value.substring(i, i + 4), 16)));
			i += 4;
			continue;
		}
		switch (c) {
		case '"':
		case '\\':
		case '/':
			break;
		case 'b':
			c = '\b';
			break;
		case 'f':
			c = '\f';
			break;
		case 'n':
			c = '\n';
			break;
		case 'r':
			c = '\r';
			break;
		case 't':
			c = '\t';
			break;
		default:
			throw new SerializationException("Illegal escaped character: \\" + c);
		}
		buffer.append(c);
	}
	return buffer.toString();
}