List of usage examples for com.badlogic.gdx.utils SerializationException SerializationException
public SerializationException(Throwable cause)
From source file:com.austinerb.project0.engine.JsonReader.java
License:Apache License
public JsonValue parse(Reader reader) { try {// w w w . j a va 2 s. co m 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; } return parse(data, 0, offset); } catch (IOException ex) { throw new SerializationException(ex); } finally { //StreamUtils.closeQuietly(reader); } }
From source file:com.austinerb.project0.engine.JsonReader.java
License:Apache License
public JsonValue parse(InputStream input) { try {/*www. ja v a 2 s . c o m*/ return parse(new InputStreamReader(input, "UTF-8")); } catch (IOException ex) { throw new SerializationException(ex); } finally { //StreamUtils.closeQuietly(input); } }
From source file:com.austinerb.project0.engine.JsonReader.java
License:Apache License
private 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);// w w w . ja v a2 s . c o m 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(); }
From source file:com.company.minery.utils.spine.SkeletonJson.java
License:Open Source License
public SkeletonData readSkeletonData(FileHandle file) { if (file == null) throw new IllegalArgumentException("file cannot be null."); float scale = this.scale; SkeletonData skeletonData = new SkeletonData(); skeletonData.name = file.nameWithoutExtension(); JsonValue root = new JsonReader().parse(file); // Skeleton./*from w ww. ja va 2s . c om*/ JsonValue skeletonMap = root.get("skeleton"); if (skeletonMap != null) { skeletonData.hash = skeletonMap.getString("hash", null); skeletonData.version = skeletonMap.getString("spine", null); skeletonData.width = skeletonMap.getFloat("width", 0); skeletonData.height = skeletonMap.getFloat("height", 0); skeletonData.imagesPath = skeletonMap.getString("images", null); } // Bones. for (JsonValue boneMap = root.getChild("bones"); boneMap != null; boneMap = boneMap.next) { BoneData parent = null; String parentName = boneMap.getString("parent", null); if (parentName != null) { parent = skeletonData.findBone(parentName); if (parent == null) throw new SerializationException("Parent bone not found: " + parentName); } BoneData boneData = new BoneData(boneMap.getString("name"), parent); boneData.length = boneMap.getFloat("length", 0) * scale; boneData.x = boneMap.getFloat("x", 0) * scale; boneData.y = boneMap.getFloat("y", 0) * scale; boneData.rotation = boneMap.getFloat("rotation", 0); boneData.scaleX = boneMap.getFloat("scaleX", 1); boneData.scaleY = boneMap.getFloat("scaleY", 1); boneData.flipX = boneMap.getBoolean("flipX", false); boneData.flipY = boneMap.getBoolean("flipY", false); boneData.inheritScale = boneMap.getBoolean("inheritScale", true); boneData.inheritRotation = boneMap.getBoolean("inheritRotation", true); String color = boneMap.getString("color", null); if (color != null) boneData.getColor().set(Color.valueOf(color)); skeletonData.bones.add(boneData); } // IK constraints. for (JsonValue ikMap = root.getChild("ik"); ikMap != null; ikMap = ikMap.next) { IkConstraintData ikConstraintData = new IkConstraintData(ikMap.getString("name")); for (JsonValue boneMap = ikMap.getChild("bones"); boneMap != null; boneMap = boneMap.next) { String boneName = boneMap.asString(); BoneData bone = skeletonData.findBone(boneName); if (bone == null) throw new SerializationException("IK bone not found: " + boneName); ikConstraintData.bones.add(bone); } String targetName = ikMap.getString("target"); ikConstraintData.target = skeletonData.findBone(targetName); if (ikConstraintData.target == null) throw new SerializationException("Target bone not found: " + targetName); ikConstraintData.bendDirection = ikMap.getBoolean("bendPositive", true) ? 1 : -1; ikConstraintData.mix = ikMap.getFloat("mix", 1); skeletonData.ikConstraints.add(ikConstraintData); } // Slots. for (JsonValue slotMap = root.getChild("slots"); slotMap != null; slotMap = slotMap.next) { String slotName = slotMap.getString("name"); String boneName = slotMap.getString("bone"); BoneData boneData = skeletonData.findBone(boneName); if (boneData == null) throw new SerializationException("Slot bone not found: " + boneName); SlotData slotData = new SlotData(slotName, boneData); String color = slotMap.getString("color", null); if (color != null) slotData.getColor().set(Color.valueOf(color)); slotData.attachmentName = slotMap.getString("attachment", null); slotData.additiveBlending = slotMap.getBoolean("additive", false); skeletonData.slots.add(slotData); } // Skins. for (JsonValue skinMap = root.getChild("skins"); skinMap != null; skinMap = skinMap.next) { Skin skin = new Skin(skinMap.name); for (JsonValue slotEntry = skinMap.child; slotEntry != null; slotEntry = slotEntry.next) { int slotIndex = skeletonData.findSlotIndex(slotEntry.name); if (slotIndex == -1) throw new SerializationException("Slot not found: " + slotEntry.name); for (JsonValue entry = slotEntry.child; entry != null; entry = entry.next) { Attachment attachment = readAttachment(skin, entry.name, entry); if (attachment != null) skin.addAttachment(slotIndex, entry.name, attachment); } } skeletonData.skins.add(skin); if (skin.name.equals("default")) skeletonData.defaultSkin = skin; } // Events. for (JsonValue eventMap = root.getChild("events"); eventMap != null; eventMap = eventMap.next) { EventData eventData = new EventData(eventMap.name); eventData.intValue = eventMap.getInt("int", 0); eventData.floatValue = eventMap.getFloat("float", 0f); eventData.stringValue = eventMap.getString("string", null); skeletonData.events.add(eventData); } // Animations. for (JsonValue animationMap = root .getChild("animations"); animationMap != null; animationMap = animationMap.next) readAnimation(animationMap.name, animationMap, skeletonData); skeletonData.bones.shrink(); skeletonData.slots.shrink(); skeletonData.skins.shrink(); skeletonData.animations.shrink(); return skeletonData; }
From source file:com.company.minery.utils.spine.SkeletonJson.java
License:Open Source License
private void readAnimation(String name, JsonValue map, SkeletonData skeletonData) { float scale = this.scale; Array<Timeline> timelines = new Array(); float duration = 0; // Slot timelines. for (JsonValue slotMap = map.getChild("slots"); slotMap != null; slotMap = slotMap.next) { int slotIndex = skeletonData.findSlotIndex(slotMap.name); if (slotIndex == -1) throw new SerializationException("Slot not found: " + slotMap.name); for (JsonValue timelineMap = slotMap.child; timelineMap != null; timelineMap = timelineMap.next) { String timelineName = timelineMap.name; if (timelineName.equals("color")) { ColorTimeline timeline = new ColorTimeline(timelineMap.size); timeline.slotIndex = slotIndex; int frameIndex = 0; for (JsonValue valueMap = timelineMap.child; valueMap != null; valueMap = valueMap.next) { Color color = Color.valueOf(valueMap.getString("color")); timeline.setFrame(frameIndex, valueMap.getFloat("time"), color.r, color.g, color.b, color.a);//from w w w . j a v a 2s.c o m readCurve(timeline, frameIndex, valueMap); frameIndex++; } timelines.add(timeline); duration = Math.max(duration, timeline.getFrames()[timeline.getFrameCount() * 5 - 5]); } else if (timelineName.equals("attachment")) { AttachmentTimeline timeline = new AttachmentTimeline(timelineMap.size); timeline.slotIndex = slotIndex; int frameIndex = 0; for (JsonValue valueMap = timelineMap.child; valueMap != null; valueMap = valueMap.next) timeline.setFrame(frameIndex++, valueMap.getFloat("time"), valueMap.getString("name")); timelines.add(timeline); duration = Math.max(duration, timeline.getFrames()[timeline.getFrameCount() - 1]); } else throw new RuntimeException( "Invalid timeline type for a slot: " + timelineName + " (" + slotMap.name + ")"); } } // Bone timelines. for (JsonValue boneMap = map.getChild("bones"); boneMap != null; boneMap = boneMap.next) { int boneIndex = skeletonData.findBoneIndex(boneMap.name); if (boneIndex == -1) throw new SerializationException("Bone not found: " + boneMap.name); for (JsonValue timelineMap = boneMap.child; timelineMap != null; timelineMap = timelineMap.next) { String timelineName = timelineMap.name; if (timelineName.equals("rotate")) { RotateTimeline timeline = new RotateTimeline(timelineMap.size); timeline.boneIndex = boneIndex; int frameIndex = 0; for (JsonValue valueMap = timelineMap.child; valueMap != null; valueMap = valueMap.next) { timeline.setFrame(frameIndex, valueMap.getFloat("time"), valueMap.getFloat("angle")); readCurve(timeline, frameIndex, valueMap); frameIndex++; } timelines.add(timeline); duration = Math.max(duration, timeline.getFrames()[timeline.getFrameCount() * 2 - 2]); } else if (timelineName.equals("translate") || timelineName.equals("scale")) { TranslateTimeline timeline; float timelineScale = 1; if (timelineName.equals("scale")) timeline = new ScaleTimeline(timelineMap.size); else { timeline = new TranslateTimeline(timelineMap.size); timelineScale = scale; } timeline.boneIndex = boneIndex; int frameIndex = 0; for (JsonValue valueMap = timelineMap.child; valueMap != null; valueMap = valueMap.next) { float x = valueMap.getFloat("x", 0), y = valueMap.getFloat("y", 0); timeline.setFrame(frameIndex, valueMap.getFloat("time"), x * timelineScale, y * timelineScale); readCurve(timeline, frameIndex, valueMap); frameIndex++; } timelines.add(timeline); duration = Math.max(duration, timeline.getFrames()[timeline.getFrameCount() * 3 - 3]); } else if (timelineName.equals("flipX") || timelineName.equals("flipY")) { boolean x = timelineName.equals("flipX"); FlipXTimeline timeline = x ? new FlipXTimeline(timelineMap.size) : new FlipYTimeline(timelineMap.size); timeline.boneIndex = boneIndex; String field = x ? "x" : "y"; int frameIndex = 0; for (JsonValue valueMap = timelineMap.child; valueMap != null; valueMap = valueMap.next) { timeline.setFrame(frameIndex, valueMap.getFloat("time"), valueMap.getBoolean(field, false)); frameIndex++; } timelines.add(timeline); duration = Math.max(duration, timeline.getFrames()[timeline.getFrameCount() * 2 - 2]); } else throw new RuntimeException( "Invalid timeline type for a bone: " + timelineName + " (" + boneMap.name + ")"); } } // IK timelines. for (JsonValue ikMap = map.getChild("ik"); ikMap != null; ikMap = ikMap.next) { IkConstraintData ikConstraint = skeletonData.findIkConstraint(ikMap.name); IkConstraintTimeline timeline = new IkConstraintTimeline(ikMap.size); timeline.ikConstraintIndex = skeletonData.getIkConstraints().indexOf(ikConstraint, true); int frameIndex = 0; for (JsonValue valueMap = ikMap.child; valueMap != null; valueMap = valueMap.next) { timeline.setFrame(frameIndex, valueMap.getFloat("time"), valueMap.getFloat("mix"), valueMap.getBoolean("bendPositive") ? 1 : -1); readCurve(timeline, frameIndex, valueMap); frameIndex++; } timelines.add(timeline); duration = Math.max(duration, timeline.getFrames()[timeline.getFrameCount() * 3 - 3]); } // FFD timelines. for (JsonValue ffdMap = map.getChild("ffd"); ffdMap != null; ffdMap = ffdMap.next) { Skin skin = skeletonData.findSkin(ffdMap.name); if (skin == null) throw new SerializationException("Skin not found: " + ffdMap.name); for (JsonValue slotMap = ffdMap.child; slotMap != null; slotMap = slotMap.next) { int slotIndex = skeletonData.findSlotIndex(slotMap.name); if (slotIndex == -1) throw new SerializationException("Slot not found: " + slotMap.name); for (JsonValue meshMap = slotMap.child; meshMap != null; meshMap = meshMap.next) { FfdTimeline timeline = new FfdTimeline(meshMap.size); Attachment attachment = skin.getAttachment(slotIndex, meshMap.name); if (attachment == null) throw new SerializationException("FFD attachment not found: " + meshMap.name); timeline.slotIndex = slotIndex; timeline.attachment = attachment; int vertexCount; if (attachment instanceof MeshAttachment) vertexCount = ((MeshAttachment) attachment).getVertices().length; else vertexCount = ((SkinnedMeshAttachment) attachment).getWeights().length / 3 * 2; int frameIndex = 0; for (JsonValue valueMap = meshMap.child; valueMap != null; valueMap = valueMap.next) { float[] vertices; JsonValue verticesValue = valueMap.get("vertices"); if (verticesValue == null) { if (attachment instanceof MeshAttachment) vertices = ((MeshAttachment) attachment).getVertices(); else vertices = new float[vertexCount]; } else { vertices = new float[vertexCount]; int start = valueMap.getInt("offset", 0); System.arraycopy(verticesValue.asFloatArray(), 0, vertices, start, verticesValue.size); if (scale != 1) { for (int i = start, n = i + verticesValue.size; i < n; i++) vertices[i] *= scale; } if (attachment instanceof MeshAttachment) { float[] meshVertices = ((MeshAttachment) attachment).getVertices(); for (int i = 0; i < vertexCount; i++) vertices[i] += meshVertices[i]; } } timeline.setFrame(frameIndex, valueMap.getFloat("time"), vertices); readCurve(timeline, frameIndex, valueMap); frameIndex++; } timelines.add(timeline); duration = Math.max(duration, timeline.getFrames()[timeline.getFrameCount() - 1]); } } } // Draw order timeline. JsonValue drawOrdersMap = map.get("drawOrder"); if (drawOrdersMap == null) drawOrdersMap = map.get("draworder"); if (drawOrdersMap != null) { DrawOrderTimeline timeline = new DrawOrderTimeline(drawOrdersMap.size); int slotCount = skeletonData.slots.size; int frameIndex = 0; for (JsonValue drawOrderMap = drawOrdersMap.child; drawOrderMap != null; drawOrderMap = drawOrderMap.next) { int[] drawOrder = null; JsonValue offsets = drawOrderMap.get("offsets"); if (offsets != null) { drawOrder = new int[slotCount]; for (int i = slotCount - 1; i >= 0; i--) drawOrder[i] = -1; int[] unchanged = new int[slotCount - offsets.size]; int originalIndex = 0, unchangedIndex = 0; for (JsonValue offsetMap = offsets.child; offsetMap != null; offsetMap = offsetMap.next) { int slotIndex = skeletonData.findSlotIndex(offsetMap.getString("slot")); if (slotIndex == -1) throw new SerializationException("Slot not found: " + offsetMap.getString("slot")); // Collect unchanged items. while (originalIndex != slotIndex) unchanged[unchangedIndex++] = originalIndex++; // Set changed items. drawOrder[originalIndex + offsetMap.getInt("offset")] = originalIndex++; } // Collect remaining unchanged items. while (originalIndex < slotCount) unchanged[unchangedIndex++] = originalIndex++; // Fill in unchanged items. for (int i = slotCount - 1; i >= 0; i--) if (drawOrder[i] == -1) drawOrder[i] = unchanged[--unchangedIndex]; } timeline.setFrame(frameIndex++, drawOrderMap.getFloat("time"), drawOrder); } timelines.add(timeline); duration = Math.max(duration, timeline.getFrames()[timeline.getFrameCount() - 1]); } // Event timeline. JsonValue eventsMap = map.get("events"); if (eventsMap != null) { EventTimeline timeline = new EventTimeline(eventsMap.size); int frameIndex = 0; for (JsonValue eventMap = eventsMap.child; eventMap != null; eventMap = eventMap.next) { EventData eventData = skeletonData.findEvent(eventMap.getString("name")); if (eventData == null) throw new SerializationException("Event not found: " + eventMap.getString("name")); Event event = new Event(eventData); event.intValue = eventMap.getInt("int", eventData.getInt()); event.floatValue = eventMap.getFloat("float", eventData.getFloat()); event.stringValue = eventMap.getString("string", eventData.getString()); timeline.setFrame(frameIndex++, eventMap.getFloat("time"), event); } timelines.add(timeline); duration = Math.max(duration, timeline.getFrames()[timeline.getFrameCount() - 1]); } timelines.shrink(); skeletonData.animations.add(new Animation(name, timelines, duration)); }
From source file:com.esotericsoftware.spine.JsonReader.java
License:Apache License
public JsonValue parse(Reader reader) { try {/*from w ww.ja v a 2 s . c o m*/ 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; } return parse(data, 0, offset); } catch (IOException ex) { throw new SerializationException(ex); } finally { StreamUtils.closeQuietly(reader); } }
From source file:com.esotericsoftware.spine.JsonReader.java
License:Apache License
public JsonValue parse(InputStream input) { try {/*from www . j av a2s . c o m*/ return parse(new InputStreamReader(input, "UTF-8")); } catch (IOException ex) { throw new SerializationException(ex); } finally { StreamUtils.closeQuietly(input); } }
From source file:com.esotericsoftware.spine.JsonValue.java
License:Apache License
private void prettyPrint(JsonValue object, StringBuilder buffer, int indent, PrettyPrintSettings settings) { OutputType outputType = settings.outputType; if (object.isObject()) { if (object.child == null) { buffer.append("{}"); } else {//from w w w . ja va 2s .c o m boolean newLines = !isFlat(object); int start = buffer.length(); outer: while (true) { buffer.append(newLines ? "{\n" : "{ "); int i = 0; for (JsonValue child = object.child; child != null; child = child.next) { if (newLines) indent(indent, buffer); buffer.append(outputType.quoteName(child.name)); buffer.append(": "); prettyPrint(child, buffer, indent + 1, settings); if ((!newLines || outputType != OutputType.minimal) && child.next != null) buffer.append(','); buffer.append(newLines ? '\n' : ' '); if (!newLines && buffer.length() - start > settings.singleLineColumns) { buffer.setLength(start); newLines = true; continue outer; } } break; } if (newLines) indent(indent - 1, buffer); buffer.append('}'); } } else if (object.isArray()) { if (object.child == null) { buffer.append("[]"); } else { boolean newLines = !isFlat(object); boolean wrap = settings.wrapNumericArrays || !isNumeric(object); int start = buffer.length(); outer: while (true) { buffer.append(newLines ? "[\n" : "[ "); for (JsonValue child = object.child; child != null; child = child.next) { if (newLines) indent(indent, buffer); prettyPrint(child, buffer, indent + 1, settings); if ((!newLines || outputType != OutputType.minimal) && child.next != null) buffer.append(','); buffer.append(newLines ? '\n' : ' '); if (wrap && !newLines && buffer.length() - start > settings.singleLineColumns) { buffer.setLength(start); newLines = true; continue outer; } } break; } if (newLines) indent(indent - 1, buffer); buffer.append(']'); } } else if (object.isString()) { buffer.append(outputType.quoteValue(object.asString())); } else if (object.isDouble()) { double doubleValue = object.asDouble(); long longValue = object.asLong(); buffer.append(doubleValue == longValue ? longValue : doubleValue); } else if (object.isLong()) { buffer.append(object.asLong()); } else if (object.isBoolean()) { buffer.append(object.asBoolean()); } else if (object.isNull()) { buffer.append("null"); } else throw new SerializationException("Unknown object type: " + object); }
From source file:com.tussle.stream.JsonDistributingWriter.java
License:Open Source License
public void write(JsonValue jsonVal) { try {/*from w ww. j av a 2 s . c o m*/ for (JsonValue i : jsonVal) { //Not a typo, we're iterating over the jsonValue we were handed if (writers.containsKey(i.name())) { try { writers.get(i.name()) .write(i.prettyPrint(JsonWriter.OutputType.json, Integer.MAX_VALUE) + "\n"); } catch (IOException ex) { JsonValue value = Utility.exceptionToJson(ex); value.addChild("Invalid String", i); errorWriter.write(value.toString()); } } else { JsonValue value = new JsonValue(JsonValue.ValueType.object); value.addChild("Invalid String", i); errorWriter.write(value.toString()); } } } catch (IOException ex) { throw new SerializationException(ex); } }
From source file:mt.Json.java
License:Apache License
public Class getClass(String tag) { Class type = tagToClass.get(tag); if (type != null) return type; try {//ww w .j a v a 2s. c om return ClassReflection.forName(tag); } catch (ReflectionException ex) { throw new SerializationException(ex); } }