/** * 负责将可序列化对象存入数据库<br> * This method is responsible for storing serializable objects in the database. * * @param <T> * @param name * @param serializableObject */ @Override public <T extends Serializable> void save(String name, T serializableObject) { ensureNotClosed(); try { Files.write(getDefaultPath(), DeepCopy.serialize(serializableObject)); } catch (IOException ex) { throw new RuntimeException(ex); } }
/** * Loads serializable objects from the database. * * @param <T> * @param name * @param klass * @return */ @Override @SuppressWarnings("unchecked") public <T extends Serializable> T load(String name, Class<T> klass) { ensureNotClosed(); try { // read the stored serialized object T serializableObject = (T) DeepCopy.deserialize(Files.readAllBytes(getDefaultPath())); return serializableObject; } catch (NoSuchFileException ex) { return null; } catch (IOException ex) { throw new RuntimeException(ex); } }