Skip to content

Instantly share code, notes, and snippets.

@sugyan
Created December 26, 2014 12:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sugyan/8396d473ffae62b664e2 to your computer and use it in GitHub Desktop.
Save sugyan/8396d473ffae62b664e2 to your computer and use it in GitHub Desktop.
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.lang.reflect.Array;
import java.util.ArrayList;
public class Deserializer {
public static void main(String[] args) {
String filepath = args[0];
int count = 0;
try {
ArrayList<String> elems = new ArrayList<String>();
FileInputStream fis = new FileInputStream(filepath);
ObjectInputStream ois = new ObjectInputStream(fis);
while (ois.available() == 0) {
Object obj = ois.readObject();
Class c = obj.getClass();
String[] arr = new String[Array.getLength(obj)];
for (int i = 0; i < Array.getLength(obj); i++) {
if (c.getComponentType() == float.class) {
arr[i] = String.valueOf(Array.getFloat(obj, i));
}
if (c.getComponentType() == short.class) {
arr[i] = String.valueOf(Array.getShort(obj, i));
}
}
// 最初の頂点座標は (vx, vy, vz, tx, ty) になっているようなので分離
if (count == 0) {
ArrayList<String> vertices = new ArrayList<String>();
ArrayList<String> texcoord = new ArrayList<String>();
for (int i = 0; i < arr.length; i++) {
if (i % 5 < 3) {
vertices.add(arr[i]);
} else {
texcoord.add(arr[i]);
}
}
elems.add("[" + String.join(",", vertices) + "]");
elems.add("[" + String.join(",", texcoord) + "]");
} else {
elems.add("[" + String.join(",", arr) + "]");
}
count++;
}
fis.close();
ois.close();
System.out.print("[" + String.join(",", elems) + "]");
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment