/** * serializes the given object to the specified file. * * @param filename the file to write the object to * @param o the object to serialize * @throws Exception if serialization fails */ public static void write(String filename, Object o) throws Exception { write(new FileOutputStream(filename), o); }
/** * deserializes the content of the file and returns it, null if an error * occurred. * * @param filename the name of the file to deserialize * @return the deserialized content, null if problem occurred */ public static Object loadFromFile(String filename) { Object result; try { result = SerializationHelper.read(filename); } catch (Exception e) { result = null; } return result; }
/** * checks whether a class needs to declare a serialVersionUID, i.e., it * implements the java.io.Serializable interface but doesn't declare a * serialVersionUID. * * @param classname the class to check * @return true if the class needs to declare one, false otherwise (also if * the class cannot be loaded!) */ public static boolean needsUID(String classname) { boolean result; try { // result = needsUID(Class.forName(classname)); result = needsUID(WekaPackageClassLoaderManager.forName(classname)); } catch (Exception e) { result = false; } return result; }
/** * writes the serialized object to the speicified file * * @param filename the file to serialize the object to * @param o the object to serialize * @return true if writing was successful */ public static boolean saveToFile(String filename, Object o) { boolean result; if (SerializationHelper.isSerializable(o.getClass())) { try { SerializationHelper.write(filename, o); result = true; } catch (Exception e) { result = false; } } else { result = false; } return result; }
smo.buildClassifier(train_data); SerializationHelper s = new SerializationHelper(); s.write("SMO_samp.model", smo); Classifier c = new SMO(); c = (Classifier) s.read("SMO_Samp.model"); Evaluation evaluation = null; evaluation = new Evaluation (train_data);
/** * deserializes from the given stream and returns the object from it. * * @param stream the stream to deserialize from * @return the deserialized object * @throws Exception if deserialization fails */ public static Object read(InputStream stream) throws Exception { ObjectInputStream ois; Object result; ois = getObjectInputStream(stream); result = ois.readObject(); ois.close(); return result; }
/** * deserializes the given file and returns the objects from it. * * @param filename the file to deserialize from * @return the deserialized objects * @throws Exception if deserialization fails */ public static Object[] readAll(String filename) throws Exception { return readAll(new FileInputStream(filename)); }
/** * serializes the given objects to the specified file. * * @param filename the file to write the object to * @param o the objects to serialize * @throws Exception if serialization fails */ public static void writeAll(String filename, Object[] o) throws Exception { writeAll(new FileOutputStream(filename), o); }
/** * writes the serialized object to the speicified file * * @param filename the file to serialize the object to * @param o the object to serialize * @return true if writing was successful */ public static boolean saveToFile(String filename, Object o) { boolean result; if (SerializationHelper.isSerializable(o.getClass())) { try { SerializationHelper.write(filename, o); result = true; } catch (Exception e) { result = false; } } else { result = false; } return result; }
/** * deserializes from the given stream and returns the object from it. * * @param stream the stream to deserialize from * @return the deserialized object * @throws Exception if deserialization fails */ public static Object read(InputStream stream) throws Exception { ObjectInputStream ois; Object result; ois = getObjectInputStream(stream); result = ois.readObject(); ois.close(); return result; }
/** * deserializes the given file and returns the objects from it. * * @param filename the file to deserialize from * @return the deserialized objects * @throws Exception if deserialization fails */ public static Object[] readAll(String filename) throws Exception { return readAll(new FileInputStream(filename)); }
/** * serializes the given objects to the specified file. * * @param filename the file to write the object to * @param o the objects to serialize * @throws Exception if serialization fails */ public static void writeAll(String filename, Object[] o) throws Exception { writeAll(new FileOutputStream(filename), o); }
/** * deserializes the content of the file and returns it, null if an error * occurred. * * @param filename the name of the file to deserialize * @return the deserialized content, null if problem occurred */ public static Object loadFromFile(String filename) { Object result; try { result = SerializationHelper.read(filename); } catch (Exception e) { result = null; } return result; }
/** * serializes the given object to the specified file. * * @param filename the file to write the object to * @param o the object to serialize * @throws Exception if serialization fails */ public static void write(String filename, Object o) throws Exception { write(new FileOutputStream(filename), o); }
/** * tests whether the scheme declares a serialVersionUID. */ public void testSerialVersionUID() { boolean result; result = !SerializationHelper.needsUID(m_Stopwords.getClass()); if (!result) { fail("Doesn't declare serialVersionUID!"); } }
/** * deserializes from the given stream and returns the object from it. * * @param stream the stream to deserialize from * @return the deserialized object * @throws Exception if deserialization fails */ public static Object[] readAll(InputStream stream) throws Exception { ObjectInputStream ois; Vector<Object> result; ois = getObjectInputStream(stream); result = new Vector<Object>(); try { while (true) { result.add(ois.readObject()); } } catch (IOException e) { // ignored } ois.close(); return result.toArray(new Object[result.size()]); }