BinaryImporter imp = BinaryImporter.getInstance(); if (manager != null) { imp.setAssetManager(manager); sav = imp.load(is); Logger.getLogger(SaveGame.class.getName()).log(Level.FINE, "Loading data from: {0}", file.getAbsolutePath()); } catch (IOException ex) {
/** * Saves the object into memory then loads it from memory. * * Used by tests to check if the persistence system is working. * * @param <T> The type of savable. * @param assetManager AssetManager to load assets from. * @param object The object to save and then load. * @return A new instance that has been saved and loaded from the * original object. */ public static <T extends Savable> T saveAndLoad(AssetManager assetManager, T object) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { BinaryExporter exporter = new BinaryExporter(); exporter.save(object, baos); BinaryImporter importer = new BinaryImporter(); importer.setAssetManager(assetManager); return (T) importer.load(baos.toByteArray()); } catch (IOException ex) { // Should never happen. throw new AssertionError(ex); } }
protected ByteBuffer readByteBuffer(byte[] content) throws IOException { int length = readInt(content); if (length == BinaryOutputCapsule.NULL_OBJECT) return null; if (BinaryImporter.canUseFastBuffers()){ ByteBuffer value = BufferUtils.createByteBuffer(length); value.put(content, index, length).rewind(); index += length; return value; }else{ ByteBuffer value = BufferUtils.createByteBuffer(length); for (int x = 0; x < length; x++) { value.put(readByteForBuffer(content)); } value.rewind(); return value; } }
@Override public Object load(final AssetInfo assetInfo) throws IOException { BinaryImporter importer = importers.pollLast(); if (importer == null) { importer = new BinaryImporter(); } try { return importer.load(assetInfo); } finally { importers.addLast(importer); } } }
public Savable load(URL f) throws IOException { return load(f, null); }
@Override public Object load(AssetInfo assetInfo) throws IOException { BinaryImporter importer = BinaryImporter.getInstance(); return importer.load(assetInfo); } }
String alias = readString(bis, aliasWidth); String className = readString(bis, classLength); String fieldName = readString(bis, fieldNameLength); BinaryClassField bcf = new BinaryClassField(fieldName, fieldAlias, fieldType); bco.nameFields.put(fieldName, bcf); baos = null; Savable rVal = readObject(id); if (debug) { logger.fine("Importer Stats: ");
private Savable[] resolveIDs(Object[] values) { if (values != null) { Savable[] savables = new Savable[values.length]; for (int i = 0; i < values.length; i++) { final ID id = (ID) values[i]; savables[i] = id != null ? importer.readObject(id.id) : null; } return savables; } else { return null; } }
public static BinaryImporter getInstance() { return new BinaryImporter(); }
int loc = locationTable.get(id); String alias = readString(aliasWidth, loc); loc+=aliasWidth;
public int getSavableVersion(Class<? extends Savable> desiredClass){ return SavableClassUtil.getSavedSavableVersion(savable, desiredClass, cObj.classHierarchyVersions, importer.getFormatVersion()); }
public Savable load(File f) throws IOException { return load(f, null); }
/** * Loads up an instance of HiScores for your disposal * * @return HiScores object */ public static HiScores load() { try { HiScores hiScores = (HiScores) BinaryImporter.getInstance().load(getFile()); // Ensure that the entries are in order, and remove excess data Collections.sort(hiScores.entries); hiScores.trimList(); return hiScores; } catch (IOException ex) { logger.log(Level.SEVERE, "Failed to load HiScores data!", ex); return new HiScores(); } }
@Override public Object load(final AssetInfo assetInfo) throws IOException { BinaryImporter importer = importers.pollLast(); if (importer == null) { importer = new BinaryImporter(); } try { return importer.load(assetInfo); } finally { importers.addLast(importer); } } }
String alias = readString(bis, aliasWidth); String className = readString(bis, classLength); String fieldName = readString(bis, fieldNameLength); BinaryClassField bcf = new BinaryClassField(fieldName, fieldAlias, fieldType); bco.nameFields.put(fieldName, bcf); baos = null; Savable rVal = readObject(id); if (debug) { logger.fine("Importer Stats: ");
public Savable readSavable(String name, Savable defVal) throws IOException { BinaryClassField field = cObj.nameFields.get(name); if (field == null || !fieldData.containsKey(field.alias)) return defVal; Object value = fieldData.get(field.alias); if (value == null) return null; else if (value instanceof ID) { value = importer.readObject(((ID) value).id); fieldData.put(field.alias, value); return (Savable) value; } else return defVal; }
public static BinaryImporter getInstance() { return new BinaryImporter(); }
int loc = locationTable.get(id); String alias = readString(aliasWidth, loc); loc+=aliasWidth;
public int getSavableVersion(Class<? extends Savable> desiredClass){ return SavableClassUtil.getSavedSavableVersion(savable, desiredClass, cObj.classHierarchyVersions, importer.getFormatVersion()); }
BinaryImporter imp = BinaryImporter.getInstance(); imp.setAssetManager(assetManager); terrain = (TerrainQuad) imp.load(new BufferedInputStream(fis)); rootNode.attachChild((Node)terrain);