diff options
Diffstat (limited to 'trunk/ardor3d-savable')
12 files changed, 958 insertions, 0 deletions
diff --git a/trunk/ardor3d-savable/.classpath b/trunk/ardor3d-savable/.classpath new file mode 100644 index 0000000..ac138e7 --- /dev/null +++ b/trunk/ardor3d-savable/.classpath @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src/main/java"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/trunk/ardor3d-savable/.project b/trunk/ardor3d-savable/.project new file mode 100644 index 0000000..5a49ed8 --- /dev/null +++ b/trunk/ardor3d-savable/.project @@ -0,0 +1,17 @@ +<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>ardor3d-savable</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
diff --git a/trunk/ardor3d-savable/.settings/org.eclipse.jdt.core.prefs b/trunk/ardor3d-savable/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..54e493c --- /dev/null +++ b/trunk/ardor3d-savable/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,11 @@ +eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.6
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.6
diff --git a/trunk/ardor3d-savable/pom.xml b/trunk/ardor3d-savable/pom.xml new file mode 100644 index 0000000..0bfd022 --- /dev/null +++ b/trunk/ardor3d-savable/pom.xml @@ -0,0 +1,33 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>com.ardor3d</groupId> + <artifactId>ardor3d</artifactId> + <version>0.8-SNAPSHOT</version> + <relativePath>../</relativePath> + </parent> + + <artifactId>ardor3d-savable</artifactId> + <packaging>bundle</packaging> + <name>Ardor 3D Savable</name> + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + <version>2.3.2</version> + <configuration> + <source>1.6</source> + <target>1.6</target> + <encoding>${project.build.sourceEncoding}</encoding> + </configuration> + </plugin> + </plugins> + </build> + <dependencies> + </dependencies> + <properties> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + </properties> +</project> + diff --git a/trunk/ardor3d-savable/src/main/java/com/ardor3d/util/export/Ardor3dExporter.java b/trunk/ardor3d-savable/src/main/java/com/ardor3d/util/export/Ardor3dExporter.java new file mode 100644 index 0000000..495bf6f --- /dev/null +++ b/trunk/ardor3d-savable/src/main/java/com/ardor3d/util/export/Ardor3dExporter.java @@ -0,0 +1,36 @@ +/** + * Copyright (c) 2008-2012 Ardor Labs, Inc. + * + * This file is part of Ardor3D. + * + * Ardor3D is free software: you can redistribute it and/or modify it + * under the terms of its license which may be found in the accompanying + * LICENSE file or at <http://www.ardor3d.com/LICENSE>. + */ + +package com.ardor3d.util.export; + +import java.io.File; +import java.io.IOException; +import java.io.OutputStream; + +public interface Ardor3dExporter { + + /** + * Save a Savable object to the given stream. + * + * @param savable + * @param os + * @throws IOException + */ + void save(Savable savable, OutputStream os) throws IOException; + + /** + * Save a Savable object to the given file. + * + * @param savable + * @param file + * @throws IOException + */ + void save(Savable savable, File file) throws IOException; +} diff --git a/trunk/ardor3d-savable/src/main/java/com/ardor3d/util/export/Ardor3dImporter.java b/trunk/ardor3d-savable/src/main/java/com/ardor3d/util/export/Ardor3dImporter.java new file mode 100644 index 0000000..12a4277 --- /dev/null +++ b/trunk/ardor3d-savable/src/main/java/com/ardor3d/util/export/Ardor3dImporter.java @@ -0,0 +1,55 @@ +/** + * Copyright (c) 2008-2012 Ardor Labs, Inc. + * + * This file is part of Ardor3D. + * + * Ardor3D is free software: you can redistribute it and/or modify it + * under the terms of its license which may be found in the accompanying + * LICENSE file or at <http://www.ardor3d.com/LICENSE>. + */ + +package com.ardor3d.util.export; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; + +public interface Ardor3dImporter { + + /** + * Load a Savable object from the given stream. + * + * @param is + * @return the savable object. + * @throws IOException + */ + Savable load(InputStream is) throws IOException; + + /** + * Load a Savable object from the given URL. + * + * @param url + * @return the savable object. + * @throws IOException + */ + Savable load(URL url) throws IOException; + + /** + * Load a Savable object from the given file. + * + * @param file + * @return the savable object. + * @throws IOException + */ + Savable load(File file) throws IOException; + + /** + * Load a Savable object from the given byte array, starting at the first index. + * + * @param data + * @return the savable object. + * @throws IOException + */ + Savable load(byte[] data) throws IOException; +} diff --git a/trunk/ardor3d-savable/src/main/java/com/ardor3d/util/export/ByteUtils.java b/trunk/ardor3d-savable/src/main/java/com/ardor3d/util/export/ByteUtils.java new file mode 100644 index 0000000..1c32f12 --- /dev/null +++ b/trunk/ardor3d-savable/src/main/java/com/ardor3d/util/export/ByteUtils.java @@ -0,0 +1,419 @@ +/** + * Copyright (c) 2008-2012 Ardor Labs, Inc. + * + * This file is part of Ardor3D. + * + * Ardor3D is free software: you can redistribute it and/or modify it + * under the terms of its license which may be found in the accompanying + * LICENSE file or at <http://www.ardor3d.com/LICENSE>. + */ + +package com.ardor3d.util.export; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; + +/** + * <code>ByteUtils</code> is a helper class for converting numeric primitives to and from byte representations. + */ +public abstract class ByteUtils { + + /** + * Takes an InputStream and returns the complete byte content of it + * + * @param inputStream + * The input stream to read from + * @return The byte array containing the data from the input stream + * @throws java.io.IOException + * thrown if there is a problem reading from the input stream provided + */ + public static byte[] getByteContent(final InputStream inputStream) throws IOException { + final ByteArrayOutputStream outputStream = new ByteArrayOutputStream(16 * 1024); + final byte[] buffer = new byte[1024]; + int byteCount = -1; + byte[] data = null; + + // Read the byte content into the output stream first + while ((byteCount = inputStream.read(buffer)) > 0) { + outputStream.write(buffer, 0, byteCount); + } + + // Set data with byte content from stream + data = outputStream.toByteArray(); + + // Release resources + outputStream.close(); + + return data; + } + + // ********** byte <> short METHODS ********** + + /** + * Writes a short out to an OutputStream. + * + * @param outputStream + * The OutputStream the short will be written to + * @param value + * The short to write + * @throws IOException + * Thrown if there is a problem writing to the OutputStream + */ + public static void writeShort(final OutputStream outputStream, final short value) throws IOException { + final byte[] byteArray = convertToBytes(value); + + outputStream.write(byteArray); + + return; + } + + public static byte[] convertToBytes(final short value) { + final byte[] byteArray = new byte[2]; + + byteArray[0] = (byte) (value >> 8); + byteArray[1] = (byte) value; + return byteArray; + } + + /** + * Read in a short from an InputStream + * + * @param inputStream + * The InputStream used to read the short + * @return A short, which is the next 2 bytes converted from the InputStream + * @throws IOException + * Thrown if there is a problem reading from the InputStream + */ + public static short readShort(final InputStream inputStream) throws IOException { + final byte[] byteArray = new byte[2]; + + // Read in the next 2 bytes + inputStream.read(byteArray); + + final short number = convertShortFromBytes(byteArray); + + return number; + } + + public static short convertShortFromBytes(final byte[] byteArray) { + return convertShortFromBytes(byteArray, 0); + } + + public static short convertShortFromBytes(final byte[] byteArray, final int offset) { + // Convert it to a short + final short number = (short) ((byteArray[offset + 1] & 0xFF) + ((byteArray[offset + 0] & 0xFF) << 8)); + return number; + } + + // ********** byte <> int METHODS ********** + + /** + * Writes an integer out to an OutputStream. + * + * @param outputStream + * The OutputStream the integer will be written to + * @param integer + * The integer to write + * @throws IOException + * Thrown if there is a problem writing to the OutputStream + */ + public static void writeInt(final OutputStream outputStream, final int integer) throws IOException { + final byte[] byteArray = convertToBytes(integer); + + outputStream.write(byteArray); + + return; + } + + public static byte[] convertToBytes(final int integer) { + final byte[] byteArray = new byte[4]; + + byteArray[0] = (byte) (integer >> 24); + byteArray[1] = (byte) (integer >> 16); + byteArray[2] = (byte) (integer >> 8); + byteArray[3] = (byte) integer; + return byteArray; + } + + /** + * Read in an integer from an InputStream + * + * @param inputStream + * The InputStream used to read the integer + * @return An int, which is the next 4 bytes converted from the InputStream + * @throws IOException + * Thrown if there is a problem reading from the InputStream + */ + public static int readInt(final InputStream inputStream) throws IOException { + final byte[] byteArray = new byte[4]; + + // Read in the next 4 bytes + inputStream.read(byteArray); + + final int number = convertIntFromBytes(byteArray); + + return number; + } + + public static int convertIntFromBytes(final byte[] byteArray) { + return convertIntFromBytes(byteArray, 0); + } + + public static int convertIntFromBytes(final byte[] byteArray, final int offset) { + // Convert it to an int + final int number = ((byteArray[offset] & 0xFF) << 24) + ((byteArray[offset + 1] & 0xFF) << 16) + + ((byteArray[offset + 2] & 0xFF) << 8) + (byteArray[offset + 3] & 0xFF); + return number; + } + + // ********** byte <> long METHODS ********** + + /** + * Writes a long out to an OutputStream. + * + * @param outputStream + * The OutputStream the long will be written to + * @param value + * The long to write + * @throws IOException + * Thrown if there is a problem writing to the OutputStream + */ + public static void writeLong(final OutputStream outputStream, final long value) throws IOException { + final byte[] byteArray = convertToBytes(value); + + outputStream.write(byteArray); + + return; + } + + public static byte[] convertToBytes(long n) { + final byte[] bytes = new byte[8]; + + bytes[7] = (byte) (n); + n >>>= 8; + bytes[6] = (byte) (n); + n >>>= 8; + bytes[5] = (byte) (n); + n >>>= 8; + bytes[4] = (byte) (n); + n >>>= 8; + bytes[3] = (byte) (n); + n >>>= 8; + bytes[2] = (byte) (n); + n >>>= 8; + bytes[1] = (byte) (n); + n >>>= 8; + bytes[0] = (byte) (n); + + return bytes; + } + + /** + * Read in a long from an InputStream + * + * @param inputStream + * The InputStream used to read the long + * @return A long, which is the next 8 bytes converted from the InputStream + * @throws IOException + * Thrown if there is a problem reading from the InputStream + */ + public static long readLong(final InputStream inputStream) throws IOException { + final byte[] byteArray = new byte[8]; + + // Read in the next 8 bytes + inputStream.read(byteArray); + + final long number = convertLongFromBytes(byteArray); + + return number; + } + + public static long convertLongFromBytes(final byte[] bytes) { + return convertLongFromBytes(bytes, 0); + } + + public static long convertLongFromBytes(final byte[] bytes, final int offset) { + // Convert it to an long + return ((((long) bytes[offset + 7]) & 0xFF) + ((((long) bytes[offset + 6]) & 0xFF) << 8) + + ((((long) bytes[offset + 5]) & 0xFF) << 16) + ((((long) bytes[offset + 4]) & 0xFF) << 24) + + ((((long) bytes[offset + 3]) & 0xFF) << 32) + ((((long) bytes[offset + 2]) & 0xFF) << 40) + + ((((long) bytes[offset + 1]) & 0xFF) << 48) + ((((long) bytes[offset + 0]) & 0xFF) << 56)); + } + + // ********** byte <> double METHODS ********** + + /** + * Writes a double out to an OutputStream. + * + * @param outputStream + * The OutputStream the double will be written to + * @param value + * The double to write + * @throws IOException + * Thrown if there is a problem writing to the OutputStream + */ + public static void writeDouble(final OutputStream outputStream, final double value) throws IOException { + final byte[] byteArray = convertToBytes(value); + + outputStream.write(byteArray); + + return; + } + + public static byte[] convertToBytes(final double n) { + final long bits = Double.doubleToLongBits(n); + return convertToBytes(bits); + } + + /** + * Read in a double from an InputStream + * + * @param inputStream + * The InputStream used to read the double + * @return A double, which is the next 8 bytes converted from the InputStream + * @throws IOException + * Thrown if there is a problem reading from the InputStream + */ + public static double readDouble(final InputStream inputStream) throws IOException { + final byte[] byteArray = new byte[8]; + + // Read in the next 8 bytes + inputStream.read(byteArray); + + final double number = convertDoubleFromBytes(byteArray); + + return number; + } + + public static double convertDoubleFromBytes(final byte[] bytes) { + return convertDoubleFromBytes(bytes, 0); + } + + public static double convertDoubleFromBytes(final byte[] bytes, final int offset) { + // Convert it to a double + final long bits = convertLongFromBytes(bytes, offset); + return Double.longBitsToDouble(bits); + } + + // ********** byte <> float METHODS ********** + + /** + * Writes an float out to an OutputStream. + * + * @param outputStream + * The OutputStream the float will be written to + * @param fVal + * The float to write + * @throws IOException + * Thrown if there is a problem writing to the OutputStream + */ + public static void writeFloat(final OutputStream outputStream, final float fVal) throws IOException { + final byte[] byteArray = convertToBytes(fVal); + + outputStream.write(byteArray); + + return; + } + + public static byte[] convertToBytes(final float f) { + final int temp = Float.floatToIntBits(f); + return convertToBytes(temp); + } + + /** + * Read in a float from an InputStream + * + * @param inputStream + * The InputStream used to read the float + * @return A float, which is the next 4 bytes converted from the InputStream + * @throws IOException + * Thrown if there is a problem reading from the InputStream + */ + public static float readFloat(final InputStream inputStream) throws IOException { + final byte[] byteArray = new byte[4]; + + // Read in the next 4 bytes + inputStream.read(byteArray); + + final float number = convertFloatFromBytes(byteArray); + + return number; + } + + public static float convertFloatFromBytes(final byte[] byteArray) { + return convertFloatFromBytes(byteArray, 0); + } + + public static float convertFloatFromBytes(final byte[] byteArray, final int offset) { + // Convert it to an int + final int number = convertIntFromBytes(byteArray, offset); + return Float.intBitsToFloat(number); + } + + // ********** byte <> boolean METHODS ********** + + /** + * Writes a boolean out to an OutputStream. + * + * @param outputStream + * The OutputStream the boolean will be written to + * @param bVal + * The boolean to write + * @throws IOException + * Thrown if there is a problem writing to the OutputStream + */ + public static void writeBoolean(final OutputStream outputStream, final boolean bVal) throws IOException { + final byte[] byteArray = convertToBytes(bVal); + + outputStream.write(byteArray); + + return; + } + + public static byte[] convertToBytes(final boolean b) { + final byte[] rVal = new byte[1]; + rVal[0] = b ? (byte) 1 : (byte) 0; + return rVal; + } + + /** + * Read in a boolean from an InputStream + * + * @param inputStream + * The InputStream used to read the boolean + * @return A boolean, which is the next byte converted from the InputStream (iow, byte != 0) + * @throws IOException + * Thrown if there is a problem reading from the InputStream + */ + public static boolean readBoolean(final InputStream inputStream) throws IOException { + final byte[] byteArray = new byte[1]; + + // Read in the next byte + inputStream.read(byteArray); + + return convertBooleanFromBytes(byteArray); + } + + public static boolean convertBooleanFromBytes(final byte[] byteArray) { + return convertBooleanFromBytes(byteArray, 0); + } + + public static boolean convertBooleanFromBytes(final byte[] byteArray, final int offset) { + return byteArray[offset] != 0; + } + + public static byte[] rightAlignBytes(final byte[] bytes, final int width) { + if (bytes.length != width) { + final byte[] rVal = new byte[width]; + for (int x = width - bytes.length; x < width; x++) { + rVal[x] = bytes[x - (width - bytes.length)]; + } + return rVal; + } + + return bytes; + } + +} diff --git a/trunk/ardor3d-savable/src/main/java/com/ardor3d/util/export/CapsuleUtils.java b/trunk/ardor3d-savable/src/main/java/com/ardor3d/util/export/CapsuleUtils.java new file mode 100644 index 0000000..1d3cc35 --- /dev/null +++ b/trunk/ardor3d-savable/src/main/java/com/ardor3d/util/export/CapsuleUtils.java @@ -0,0 +1,54 @@ +/** + * Copyright (c) 2008-2012 Ardor Labs, Inc. + * + * This file is part of Ardor3D. + * + * Ardor3D is free software: you can redistribute it and/or modify it + * under the terms of its license which may be found in the accompanying + * LICENSE file or at <http://www.ardor3d.com/LICENSE>. + */ + +package com.ardor3d.util.export; + +import java.lang.reflect.Array; + +public final class CapsuleUtils { + + private CapsuleUtils() {} + + /** + * Convert an object array to a Savable array for easier use during export. + * + * @param values + * our object array, should be of a class type that implements Savable. + * @return the array as Savable. + */ + public static Savable[] asSavableArray(final Object[] values) { + final Savable[] rVal = new Savable[values.length]; + for (int i = 0; i < values.length; i++) { + rVal[i] = (Savable) values[i]; + } + return rVal; + } + + /** + * Converts from a Savable array to a particular class type for import operations. + * + * @param <T> + * The class type to convert to. + * @param array + * our Savable array to convert. + * @param clazz + * the class type value. + * @return + */ + @SuppressWarnings("unchecked") + public static <T> T[] asArray(final Savable[] array, final Class<T> clazz) { + final T[] values = (T[]) Array.newInstance(clazz, array.length); + for (int i = 0; i < array.length; i++) { + values[i] = (T) array[i]; + } + return values; + } + +} diff --git a/trunk/ardor3d-savable/src/main/java/com/ardor3d/util/export/InputCapsule.java b/trunk/ardor3d-savable/src/main/java/com/ardor3d/util/export/InputCapsule.java new file mode 100644 index 0000000..8dd51b1 --- /dev/null +++ b/trunk/ardor3d-savable/src/main/java/com/ardor3d/util/export/InputCapsule.java @@ -0,0 +1,144 @@ +/** + * Copyright (c) 2008-2012 Ardor Labs, Inc. + * + * This file is part of Ardor3D. + * + * Ardor3D is free software: you can redistribute it and/or modify it + * under the terms of its license which may be found in the accompanying + * LICENSE file or at <http://www.ardor3d.com/LICENSE>. + */ + +package com.ardor3d.util.export; + +import java.io.IOException; +import java.nio.ByteBuffer; +import java.nio.FloatBuffer; +import java.nio.IntBuffer; +import java.nio.ShortBuffer; +import java.util.BitSet; +import java.util.List; +import java.util.Map; + +public interface InputCapsule { + + // byte primitive + + public byte readByte(String name, byte defVal) throws IOException; + + public byte[] readByteArray(String name, byte[] defVal) throws IOException; + + public byte[][] readByteArray2D(String name, byte[][] defVal) throws IOException; + + // int primitive + + public int readInt(String name, int defVal) throws IOException; + + public int[] readIntArray(String name, int[] defVal) throws IOException; + + public int[][] readIntArray2D(String name, int[][] defVal) throws IOException; + + // float primitive + + public float readFloat(String name, float defVal) throws IOException; + + public float[] readFloatArray(String name, float[] defVal) throws IOException; + + public float[][] readFloatArray2D(String name, float[][] defVal) throws IOException; + + // double primitive + + public double readDouble(String name, double defVal) throws IOException; + + public double[] readDoubleArray(String name, double[] defVal) throws IOException; + + public double[][] readDoubleArray2D(String name, double[][] defVal) throws IOException; + + // long primitive + + public long readLong(String name, long defVal) throws IOException; + + public long[] readLongArray(String name, long[] defVal) throws IOException; + + public long[][] readLongArray2D(String name, long[][] defVal) throws IOException; + + // short primitive + + public short readShort(String name, short defVal) throws IOException; + + public short[] readShortArray(String name, short[] defVal) throws IOException; + + public short[][] readShortArray2D(String name, short[][] defVal) throws IOException; + + // boolean primitive + + public boolean readBoolean(String name, boolean defVal) throws IOException; + + public boolean[] readBooleanArray(String name, boolean[] defVal) throws IOException; + + public boolean[][] readBooleanArray2D(String name, boolean[][] defVal) throws IOException; + + // String + + public String readString(String name, String defVal) throws IOException; + + public String[] readStringArray(String name, String[] defVal) throws IOException; + + public String[][] readStringArray2D(String name, String[][] defVal) throws IOException; + + // BitSet + + public BitSet readBitSet(String name, BitSet defVal) throws IOException; + + // BinarySavable + + public Savable readSavable(String name, Savable defVal) throws IOException; + + public Savable[] readSavableArray(String name, Savable[] defVal) throws IOException; + + public Savable[][] readSavableArray2D(String name, Savable[][] defVal) throws IOException; + + // Lists + + public <E extends Savable> List<E> readSavableList(String name, List<E> defVal) throws IOException; + + public <E extends Savable> List<E>[] readSavableListArray(String name, List<E>[] defVal) throws IOException; + + public <E extends Savable> List<E>[][] readSavableListArray2D(String name, List<E>[][] defVal) throws IOException; + + public List<FloatBuffer> readFloatBufferList(String name, List<FloatBuffer> defVal) throws IOException; + + public List<ByteBuffer> readByteBufferList(String name, List<ByteBuffer> defVal) throws IOException; + + // Maps + + public <K extends Savable, V extends Savable> Map<K, V> readSavableMap(String name, Map<K, V> defVal) + throws IOException; + + public <V extends Savable> Map<String, V> readStringSavableMap(String name, Map<String, V> defVal) + throws IOException; + + // NIO BUFFERS + // float buffer + + public FloatBuffer readFloatBuffer(String name, FloatBuffer defVal) throws IOException; + + // int buffer + + public IntBuffer readIntBuffer(String name, IntBuffer defVal) throws IOException; + + // byte buffer + + public ByteBuffer readByteBuffer(String name, ByteBuffer defVal) throws IOException; + + // short buffer + + public ShortBuffer readShortBuffer(String name, ShortBuffer defVal) throws IOException; + + // enums + + public <T extends Enum<T>> T readEnum(String name, Class<T> enumType, T defVal) throws IOException; + + public <T extends Enum<T>> T[] readEnumArray(final String name, final Class<T> enumType, final T[] defVal) + throws IOException; + +} diff --git a/trunk/ardor3d-savable/src/main/java/com/ardor3d/util/export/OutputCapsule.java b/trunk/ardor3d-savable/src/main/java/com/ardor3d/util/export/OutputCapsule.java new file mode 100644 index 0000000..226bc40 --- /dev/null +++ b/trunk/ardor3d-savable/src/main/java/com/ardor3d/util/export/OutputCapsule.java @@ -0,0 +1,145 @@ +/** + * Copyright (c) 2008-2012 Ardor Labs, Inc. + * + * This file is part of Ardor3D. + * + * Ardor3D is free software: you can redistribute it and/or modify it + * under the terms of its license which may be found in the accompanying + * LICENSE file or at <http://www.ardor3d.com/LICENSE>. + */ + +package com.ardor3d.util.export; + +import java.io.IOException; +import java.nio.ByteBuffer; +import java.nio.FloatBuffer; +import java.nio.IntBuffer; +import java.nio.ShortBuffer; +import java.util.BitSet; +import java.util.List; +import java.util.Map; + +public interface OutputCapsule { + + // byte primitive + + public void write(byte value, String name, byte defVal) throws IOException; + + public void write(byte[] value, String name, byte[] defVal) throws IOException; + + public void write(byte[][] value, String name, byte[][] defVal) throws IOException; + + // int primitive + + public void write(int value, String name, int defVal) throws IOException; + + public void write(int[] value, String name, int[] defVal) throws IOException; + + public void write(int[][] value, String name, int[][] defVal) throws IOException; + + // float primitive + + public void write(float value, String name, float defVal) throws IOException; + + public void write(float[] value, String name, float[] defVal) throws IOException; + + public void write(float[][] value, String name, float[][] defVal) throws IOException; + + // double primitive + + public void write(double value, String name, double defVal) throws IOException; + + public void write(double[] value, String name, double[] defVal) throws IOException; + + public void write(double[][] value, String name, double[][] defVal) throws IOException; + + // long primitive + + public void write(long value, String name, long defVal) throws IOException; + + public void write(long[] value, String name, long[] defVal) throws IOException; + + public void write(long[][] value, String name, long[][] defVal) throws IOException; + + // short primitive + + public void write(short value, String name, short defVal) throws IOException; + + public void write(short[] value, String name, short[] defVal) throws IOException; + + public void write(short[][] value, String name, short[][] defVal) throws IOException; + + // boolean primitive + + public void write(boolean value, String name, boolean defVal) throws IOException; + + public void write(boolean[] value, String name, boolean[] defVal) throws IOException; + + public void write(boolean[][] value, String name, boolean[][] defVal) throws IOException; + + // String + + public void write(String value, String name, String defVal) throws IOException; + + public void write(String[] value, String name, String[] defVal) throws IOException; + + public void write(String[][] value, String name, String[][] defVal) throws IOException; + + // BitSet + + public void write(BitSet value, String name, BitSet defVal) throws IOException; + + // BinarySavable + + public void write(Savable object, String name, Savable defVal) throws IOException; + + public void write(Savable[] objects, String name, Savable[] defVal) throws IOException; + + public void write(Savable[][] objects, String name, Savable[][] defVal) throws IOException; + + // Lists + + public void writeSavableList(List<? extends Savable> array, String name, List<? extends Savable> defVal) + throws IOException; + + public void writeSavableListArray(List<? extends Savable>[] array, String name, List<? extends Savable>[] defVal) + throws IOException; + + public void writeSavableListArray2D(List<? extends Savable>[][] array, String name, + List<? extends Savable>[][] defVal) throws IOException; + + public void writeFloatBufferList(List<FloatBuffer> array, String name, List<FloatBuffer> defVal) throws IOException; + + public void writeByteBufferList(List<ByteBuffer> array, String name, List<ByteBuffer> defVal) throws IOException; + + // Maps + + public void writeSavableMap(Map<? extends Savable, ? extends Savable> map, String name, + Map<? extends Savable, ? extends Savable> defVal) throws IOException; + + public void writeStringSavableMap(Map<String, ? extends Savable> map, String name, + Map<String, ? extends Savable> defVal) throws IOException; + + // NIO BUFFERS + // float buffer + + public void write(FloatBuffer value, String name, FloatBuffer defVal) throws IOException; + + // int buffer + + public void write(IntBuffer value, String name, IntBuffer defVal) throws IOException; + + // byte buffer + + public void write(ByteBuffer value, String name, ByteBuffer defVal) throws IOException; + + // short buffer + + public void write(ShortBuffer value, String name, ShortBuffer defVal) throws IOException; + + // enums + + public void write(Enum<?> value, String name, Enum<?> defVal) throws IOException; + + public void write(Enum<?>[] value, String name) throws IOException; +} diff --git a/trunk/ardor3d-savable/src/main/java/com/ardor3d/util/export/ReadListener.java b/trunk/ardor3d-savable/src/main/java/com/ardor3d/util/export/ReadListener.java new file mode 100644 index 0000000..ec9b724 --- /dev/null +++ b/trunk/ardor3d-savable/src/main/java/com/ardor3d/util/export/ReadListener.java @@ -0,0 +1,17 @@ +/** + * Copyright (c) 2008-2012 Ardor Labs, Inc. + * + * This file is part of Ardor3D. + * + * Ardor3D is free software: you can redistribute it and/or modify it + * under the terms of its license which may be found in the accompanying + * LICENSE file or at <http://www.ardor3d.com/LICENSE>. + */ + +package com.ardor3d.util.export; + +public interface ReadListener { + + public void readBytes(int bytes); + +} diff --git a/trunk/ardor3d-savable/src/main/java/com/ardor3d/util/export/Savable.java b/trunk/ardor3d-savable/src/main/java/com/ardor3d/util/export/Savable.java new file mode 100644 index 0000000..d021554 --- /dev/null +++ b/trunk/ardor3d-savable/src/main/java/com/ardor3d/util/export/Savable.java @@ -0,0 +1,21 @@ +/** + * Copyright (c) 2008-2012 Ardor Labs, Inc. + * + * This file is part of Ardor3D. + * + * Ardor3D is free software: you can redistribute it and/or modify it + * under the terms of its license which may be found in the accompanying + * LICENSE file or at <http://www.ardor3d.com/LICENSE>. + */ + +package com.ardor3d.util.export; + +import java.io.IOException; + +public interface Savable { + void write(OutputCapsule capsule) throws IOException; + + void read(InputCapsule capsule) throws IOException; + + Class<?> getClassTag(); +} |