/** * The serial form currently mimics Android's java.util.HashMap version, e.g. see * http://omapzoom.org/?p=platform/libcore.git;a=blob;f=luni/src/main/java/java/util/HashMap.java */ private void writeObject(ObjectOutputStream stream) throws IOException { stream.defaultWriteObject(); stream.writeInt(size); for (int i = 0; i < size; i++) { stream.writeObject(keys[i]); stream.writeObject(values[i]); } }
/** Serializes and deserializes the specified object. */ @SuppressWarnings("unchecked") static <T> T reserialize(T object) { checkNotNull(object); ByteArrayOutputStream bytes = new ByteArrayOutputStream(); try { ObjectOutputStream out = new ObjectOutputStream(bytes); out.writeObject(object); ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(bytes.toByteArray())); return (T) in.readObject(); } catch (IOException | ClassNotFoundException e) { throw new RuntimeException(e); } }
FileOutputStream fos = context.openFileOutput(fileName, Context.MODE_PRIVATE); ObjectOutputStream os = new ObjectOutputStream(fos); os.writeObject(this); os.close(); fos.close();
public static byte[] serializeKerberosTicket(KerberosTicket tgt) throws Exception { ByteArrayOutputStream bao = new ByteArrayOutputStream(); ObjectOutputStream out = new ObjectOutputStream(bao); out.writeObject(tgt); out.flush(); out.close(); return bao.toByteArray(); }
public static void testSerialization(Object o) throws IOException { OutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(baos); oos.writeObject(o); }
/** * Writes the source object to an output stream using Java serialization. * The source object must implement {@link Serializable}. * @see ObjectOutputStream#writeObject(Object) */ @Override public void serialize(Object object, OutputStream outputStream) throws IOException { if (!(object instanceof Serializable)) { throw new IllegalArgumentException(getClass().getSimpleName() + " requires a Serializable payload " + "but received an object of type [" + object.getClass().getName() + "]"); } ObjectOutputStream objectOutputStream = new ObjectOutputStream(outputStream); objectOutputStream.writeObject(object); objectOutputStream.flush(); }
@SuppressWarnings("unchecked") static <T> T reserialize(T object) { try { ByteArrayOutputStream bytes = new ByteArrayOutputStream(); ObjectOutputStream out = new ObjectOutputStream(bytes); out.writeObject(object); ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(bytes.toByteArray())); return (T) in.readObject(); } catch (IOException | ClassNotFoundException e) { Helpers.fail(e, e.getMessage()); } throw new AssertionError("not reachable"); }
@SneakyThrows private InputStream getInputStream(final Object value) { ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); ObjectOutputStream objectOutputStream = new ObjectOutputStream(byteArrayOutputStream); objectOutputStream.writeObject(value); objectOutputStream.flush(); objectOutputStream.close(); return new ByteArrayInputStream(byteArrayOutputStream.toByteArray()); }
/** @serialData the ConcurrentMap of elements and their counts. */ private void writeObject(ObjectOutputStream stream) throws IOException { stream.defaultWriteObject(); stream.writeObject(countMap); }
private void save() throws IOException { ObjectOutputStream stream = null; try { stream = new ObjectOutputStream(new FileOutputStream(fHistoryStore)); stream.writeObject(this); } finally { if (stream != null) { stream.close(); } } }
public static byte[] serialize(Object obj) throws IOException { ByteArrayOutputStream out = new ByteArrayOutputStream(); ObjectOutputStream os = new ObjectOutputStream(out); os.writeObject(obj); return out.toByteArray(); } public static Object deserialize(byte[] data) throws IOException, ClassNotFoundException { ByteArrayInputStream in = new ByteArrayInputStream(data); ObjectInputStream is = new ObjectInputStream(in); return is.readObject(); }
public static byte[] javaSerialize(Object obj) { try { ByteArrayOutputStream bos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(bos); oos.writeObject(obj); oos.close(); return bos.toByteArray(); } catch (IOException e) { throw new RuntimeException(e); } }
/** * The serial form currently mimics Android's java.util.HashSet version, e.g. see * http://omapzoom.org/?p=platform/libcore.git;a=blob;f=luni/src/main/java/java/util/HashSet.java */ private void writeObject(ObjectOutputStream stream) throws IOException { stream.defaultWriteObject(); stream.writeInt(size); for (E e : this) { stream.writeObject(e); } }
public static Object serializeAndDeserialize(Object o) throws IOException, ClassNotFoundException { ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutputStream out = new ObjectOutputStream(buffer); out.writeObject(o); ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(buffer.toByteArray())); return in.readObject(); }
@SneakyThrows protected InputStream getInputStream(final Object value) { ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); ObjectOutputStream objectOutputStream = new ObjectOutputStream(byteArrayOutputStream); objectOutputStream.writeObject(value); objectOutputStream.flush(); objectOutputStream.close(); return new ByteArrayInputStream(byteArrayOutputStream.toByteArray()); }
/** * The serial form currently mimics Android's java.util.HashMap version, e.g. see * http://omapzoom.org/?p=platform/libcore.git;a=blob;f=luni/src/main/java/java/util/HashMap.java */ private void writeObject(ObjectOutputStream stream) throws IOException { stream.defaultWriteObject(); stream.writeInt(size); for (int i = 0; i < size; i++) { stream.writeObject(keys[i]); stream.writeObject(values[i]); } }
@NonNull private <T extends Serializable> T clone(@NonNull T item, @NonNull final Class<T> type) throws Exception { final ByteArrayOutputStream bytesOutput = new ByteArrayOutputStream(); try (final ObjectOutputStream objectOutput = new ObjectOutputStream(bytesOutput)) { objectOutput.writeObject(item); objectOutput.flush(); } final Object clone = new ObjectInputStream( new ByteArrayInputStream(bytesOutput.toByteArray())).readObject(); return type.cast(clone); }
@Override public byte[] serialize(Object object) { try { ByteArrayOutputStream bos = new ByteArrayOutputStream(); GZIPOutputStream gos = new GZIPOutputStream(bos); ObjectOutputStream oos = new ObjectOutputStream(gos); oos.writeObject(object); oos.close(); return bos.toByteArray(); } catch (IOException e) { throw new RuntimeException(e); } }
/** @serialData the ConcurrentMap of elements and their counts. */ private void writeObject(ObjectOutputStream stream) throws IOException { stream.defaultWriteObject(); stream.writeObject(countMap); }
public static Object serializeAndDeserialize(Object o) throws IOException, ClassNotFoundException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(baos); oos.writeObject(o); oos.flush(); baos.flush(); byte[] bytes = baos.toByteArray(); ByteArrayInputStream is = new ByteArrayInputStream(bytes); ObjectInputStream ois = new ObjectInputStream(is); Object o2 = ois.readObject(); return o2; }