List of usage examples for com.badlogic.gdx.files FileHandle read
public BufferedInputStream read(int bufferSize)
From source file:com.company.minery.utils.spine.SkeletonBinary.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(); DataInput input = new DataInput(file.read(512)); try {// ww w. j av a 2 s . c o m skeletonData.hash = input.readString(); if (skeletonData.hash.isEmpty()) skeletonData.hash = null; skeletonData.version = input.readString(); if (skeletonData.version.isEmpty()) skeletonData.version = null; skeletonData.width = input.readFloat(); skeletonData.height = input.readFloat(); boolean nonessential = input.readBoolean(); if (nonessential) { skeletonData.imagesPath = input.readString(); if (skeletonData.imagesPath.isEmpty()) skeletonData.imagesPath = null; } // Bones. for (int i = 0, n = input.readInt(true); i < n; i++) { String name = input.readString(); BoneData parent = null; int parentIndex = input.readInt(true) - 1; if (parentIndex != -1) parent = skeletonData.bones.get(parentIndex); BoneData boneData = new BoneData(name, parent); boneData.x = input.readFloat() * scale; boneData.y = input.readFloat() * scale; boneData.scaleX = input.readFloat(); boneData.scaleY = input.readFloat(); boneData.rotation = input.readFloat(); boneData.length = input.readFloat() * scale; boneData.flipX = input.readBoolean(); boneData.flipY = input.readBoolean(); boneData.inheritScale = input.readBoolean(); boneData.inheritRotation = input.readBoolean(); if (nonessential) Color.rgba8888ToColor(boneData.color, input.readInt()); skeletonData.bones.add(boneData); } // IK constraints. for (int i = 0, n = input.readInt(true); i < n; i++) { IkConstraintData ikConstraintData = new IkConstraintData(input.readString()); for (int ii = 0, nn = input.readInt(true); ii < nn; ii++) ikConstraintData.bones.add(skeletonData.bones.get(input.readInt(true))); ikConstraintData.target = skeletonData.bones.get(input.readInt(true)); ikConstraintData.mix = input.readFloat(); ikConstraintData.bendDirection = input.readByte(); skeletonData.ikConstraints.add(ikConstraintData); } // Slots. for (int i = 0, n = input.readInt(true); i < n; i++) { String slotName = input.readString(); BoneData boneData = skeletonData.bones.get(input.readInt(true)); SlotData slotData = new SlotData(slotName, boneData); Color.rgba8888ToColor(slotData.color, input.readInt()); slotData.attachmentName = input.readString(); slotData.additiveBlending = input.readBoolean(); skeletonData.slots.add(slotData); } // Default skin. Skin defaultSkin = readSkin(input, "default", nonessential); if (defaultSkin != null) { skeletonData.defaultSkin = defaultSkin; skeletonData.skins.add(defaultSkin); } // Skins. for (int i = 0, n = input.readInt(true); i < n; i++) skeletonData.skins.add(readSkin(input, input.readString(), nonessential)); // Events. for (int i = 0, n = input.readInt(true); i < n; i++) { EventData eventData = new EventData(input.readString()); eventData.intValue = input.readInt(false); eventData.floatValue = input.readFloat(); eventData.stringValue = input.readString(); skeletonData.events.add(eventData); } // Animations. for (int i = 0, n = input.readInt(true); i < n; i++) readAnimation(input.readString(), input, skeletonData); } catch (IOException ex) { throw new SerializationException("Error reading skeleton file.", ex); } finally { try { input.close(); } catch (IOException ignored) { } } skeletonData.bones.shrink(); skeletonData.slots.shrink(); skeletonData.skins.shrink(); return skeletonData; }
From source file:com.ridiculousRPG.util.Zipper.java
License:Apache License
/** * Packs all files from the specified directory into one zip-file * /*from www . j av a2 s. c o m*/ * @param fromDirectory * @param toFile * @throws IOException */ public static void zip(FileHandle fromDirectory, FileHandle toFile) throws IOException { byte data[] = new byte[BUFFER]; ZipOutputStream out = new ZipOutputStream(toFile.write(false)); for (FileHandle file : fromDirectory.list()) { out.putNextEntry(new ZipEntry(file.name())); InputStream in = file.read(BUFFER); int count; while ((count = in.read(data, 0, BUFFER)) != -1) { out.write(data, 0, count); } in.close(); } out.close(); }
From source file:spine.SkeletonBinary.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(); DataInput input = new DataInput(file.read(512)); try {/*from w w w . ja v a 2 s . c om*/ skeletonData.hash = input.readString(); if (skeletonData.hash.isEmpty()) skeletonData.hash = null; skeletonData.version = input.readString(); if (skeletonData.version.isEmpty()) skeletonData.version = null; skeletonData.width = input.readFloat(); skeletonData.height = input.readFloat(); boolean nonessential = input.readBoolean(); if (nonessential) { skeletonData.imagesPath = input.readString(); if (skeletonData.imagesPath.isEmpty()) skeletonData.imagesPath = null; } // Bones. for (int i = 0, n = input.readInt(true); i < n; i++) { String name = input.readString(); BoneData parent = null; int parentIndex = input.readInt(true) - 1; if (parentIndex != -1) parent = skeletonData.bones.get(parentIndex); BoneData boneData = new BoneData(name, parent); boneData.x = input.readFloat() * scale; boneData.y = input.readFloat() * scale; boneData.scaleX = input.readFloat(); boneData.scaleY = input.readFloat(); boneData.rotation = input.readFloat(); boneData.length = input.readFloat() * scale; boneData.inheritScale = input.readBoolean(); boneData.inheritRotation = input.readBoolean(); if (nonessential) Color.rgba8888ToColor(boneData.color, input.readInt()); skeletonData.bones.add(boneData); } // IK constraints. for (int i = 0, n = input.readInt(true); i < n; i++) { IkConstraintData ikConstraintData = new IkConstraintData(input.readString()); for (int ii = 0, nn = input.readInt(true); ii < nn; ii++) ikConstraintData.bones.add(skeletonData.bones.get(input.readInt(true))); ikConstraintData.target = skeletonData.bones.get(input.readInt(true)); ikConstraintData.mix = input.readFloat(); ikConstraintData.bendDirection = input.readByte(); skeletonData.ikConstraints.add(ikConstraintData); } // Slots. for (int i = 0, n = input.readInt(true); i < n; i++) { String slotName = input.readString(); BoneData boneData = skeletonData.bones.get(input.readInt(true)); SlotData slotData = new SlotData(slotName, boneData); Color.rgba8888ToColor(slotData.color, input.readInt()); slotData.attachmentName = input.readString(); slotData.blendMode = BlendMode.values[input.readInt(true)]; skeletonData.slots.add(slotData); } // Default skin. Skin defaultSkin = readSkin(input, "default", nonessential); if (defaultSkin != null) { skeletonData.defaultSkin = defaultSkin; skeletonData.skins.add(defaultSkin); } // Skins. for (int i = 0, n = input.readInt(true); i < n; i++) skeletonData.skins.add(readSkin(input, input.readString(), nonessential)); // Events. for (int i = 0, n = input.readInt(true); i < n; i++) { EventData eventData = new EventData(input.readString()); eventData.intValue = input.readInt(false); eventData.floatValue = input.readFloat(); eventData.stringValue = input.readString(); skeletonData.events.add(eventData); } // Animations. for (int i = 0, n = input.readInt(true); i < n; i++) readAnimation(input.readString(), input, skeletonData); } catch (IOException ex) { throw new SerializationException("Error reading skeleton file.", ex); } finally { try { input.close(); } catch (IOException ignored) { } } skeletonData.bones.shrink(); skeletonData.slots.shrink(); skeletonData.skins.shrink(); skeletonData.events.shrink(); skeletonData.animations.shrink(); skeletonData.ikConstraints.shrink(); return skeletonData; }