public CoreObject clone() { try { return (CoreObject) SerializationUtil.deserialize(SerializationUtil.serialize(this)); } catch (Exception e) { e.printStackTrace(); return null; } } }
public static Object load(String filename) throws ClassNotFoundException, IOException { return load(new File(filename)); }
public Matrix load(File file) throws IOException, ClassNotFoundException { return (Matrix) SerializationUtil.loadCompressed(file); }
public static Matrix fromStream(InputStream stream, Object... parameters) throws FileNotFoundException, IOException, ClassNotFoundException { return (Matrix) SerializationUtil.deserialize(stream); } }
public static final void toStream(OutputStream stream, Matrix m, Object... parameters) throws IOException { SerializationUtil.serialize(m, stream); }
public void save(File file) throws IOException { SerializationUtil.saveCompressed(file, this); }
public static void save(String filename, Object o) throws IOException { save(new File(filename), o); }
@SuppressWarnings("unchecked") public V readValue(InputStream is) { try { return (V) SerializationUtil.deserialize(is); } catch (Exception e) { e.printStackTrace(); return null; } }
public static long sizeOf(Serializable o) throws IOException { return serialize(o).length; }
public static void saveCompressed(String filename, Object o) throws IOException { saveCompressed(new File(filename), o); }
public V get(Object key) { try { prepareReader(); Text k = new Text(SerializationUtil.serialize((Serializable) key)); Text v = new Text(); Text t = (Text) reader.get(k, v); if (t == null || t.getBytes() == null || t.getBytes().length == 0) { return null; } return (V) SerializationUtil.deserialize(t.getBytes()); } catch (Exception e) { throw new RuntimeException("could not get value for key: " + key, e); } }
public static Object deserialize(byte[] data) throws ClassNotFoundException, IOException { ByteArrayInputStream bis = new ByteArrayInputStream(data); Object o = deserialize(bis); return o; }
public final void writeValue(OutputStream os, V value) { try { SerializationUtil.serialize((Serializable) value, os); } catch (Exception e) { e.printStackTrace(); } }
public static Object loadCompressed(String filename) throws ClassNotFoundException, IOException { return loadCompressed(new File(filename)); }
@SuppressWarnings("unchecked") @Test public void testSerialize() throws Exception { List<String> m = createList(); m.add("a"); m.add("b"); if (m instanceof Serializable) { byte[] data = SerializationUtil.serialize((Serializable) m); List<String> m2 = (List<String>) SerializationUtil.deserialize(data); assertEquals(getLabel(), m, m2); } }
@SuppressWarnings("unchecked") public V get(Object key) { try { byte[] data = map.get(key); return data == null ? null : (V) SerializationUtil.deserialize(data); } catch (Exception e) { throw new RuntimeException(e); } }
public static byte[] serialize(Serializable o) throws IOException { ByteArrayOutputStream bos = new ByteArrayOutputStream(); serialize(o, bos); return bos.toByteArray(); }
@SuppressWarnings("unchecked") @Test public void testSerialize() throws Exception { Set<String> m = createSet(); m.add("a"); m.add("b"); if (m instanceof Serializable) { byte[] data = SerializationUtil.serialize((Serializable) m); Set<String> m2 = (Set<String>) SerializationUtil.deserialize(data); assertEquals(getLabel(), m, m2); } }
public static Object load(File file) throws ClassNotFoundException, IOException { FileInputStream fis = new FileInputStream(file); BufferedInputStream bis = new BufferedInputStream(fis); Object o = deserialize(bis); bis.close(); fis.close(); return o; }
public static void saveCompressed(File file, Object o) throws IOException { FileOutputStream fos = new FileOutputStream(file); GZIPOutputStream bos = new GZIPOutputStream(fos); serialize(o, bos); bos.close(); fos.close(); }