ObjectOutput writeObject - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for ObjectOutput writeObject method.

This code example shows how to use the following methods:close, writeObject
	 
	public static void serializeToFile(Object obj, String filename){
		try{ 
			OutputStream file = new FileOutputStream(filename);
			OutputStream buffer = new BufferedOutputStream(file);
			ObjectOutput output = new ObjectOutputStream(buffer);
			output.writeObject(obj);
			output.close();
		}catch(IOException ex){
			throw new RuntimeException("Error while serializing " + MyUtilities.getStackTrace(ex));
		} 
	} 
	 
	public static Serializable deserializeFromFile(String filename){
		try{ 
			InputStream file = new FileInputStream(filename);
		    InputStream buffer = new BufferedInputStream(file);
		    ObjectInput input = new ObjectInputStream (buffer);
		    return (Serializable) input.readObject();
		}catch(Exception ex){
9
CodeRank
This code example shows how to use the following methods:close, writeObject
		serialize( constraintViolations );
	} 
 
	private byte[] serialize(Object o) throws Exception {
		ByteArrayOutputStream stream = new ByteArrayOutputStream();
		ObjectOutput out = new ObjectOutputStream( stream );
		out.writeObject( o );
		out.close();
		byte[] serialized = stream.toByteArray();
		stream.close();
		return serialized;
 
	} 
 
	private Set<ConstraintViolation<?>> deserialize(byte[] byteData) throws Exception {
		ByteArrayInputStream byteIn = new ByteArrayInputStream( byteData );
		ObjectInputStream in = new ObjectInputStream( byteIn );
		@SuppressWarnings("unchecked") 
		Set<ConstraintViolation<?>> deserializedViolations = (Set<ConstraintViolation<?>>) in.readObject();
		in.close();
9
CodeRank
This code example shows how to use the following methods:close, writeObject
        SerialDate d1 = SerialDate.createInstance(15, 4, 2000);
        SerialDate d2 = null;
 
        try { 
            ByteArrayOutputStream buffer = new ByteArrayOutputStream();
            ObjectOutput out = new ObjectOutputStream(buffer);
            out.writeObject(d1);
            out.close();
 
            ObjectInput in = new ObjectInputStream(new ByteArrayInputStream(buffer.toByteArray()));
            d2 = (SerialDate) in.readObject();
            in.close();
        } 
        catch (Exception e) {
            System.out.println(e.toString());
        } 
        assertEquals(d1, d2);
 
    } 
     
9
CodeRank
This code example shows how to use the following methods:close, writeObject
        final SpreadsheetDate d1 = new SpreadsheetDate(15, 4, 2000);
        SpreadsheetDate d2 = null;
 
        try { 
            final ByteArrayOutputStream buffer = new ByteArrayOutputStream();
            final ObjectOutput out = new ObjectOutputStream(buffer);
            out.writeObject(d1);
            out.close();
 
            ObjectInput in = new ObjectInputStream(new ByteArrayInputStream(
                    buffer.toByteArray()));
            d2 = (SpreadsheetDate) in.readObject();
            in.close();
        } 
        catch (Exception e) {
            System.out.println(e.toString());
        } 
        assertEquals(d1, d2);
 
    } 
9
CodeRank
This code example shows how to use the following methods:close, writeObject
    public void testSerialization() throws IOException, ClassNotFoundException {
 
        StandardTickUnitSource t1 = new StandardTickUnitSource();
 
        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
        ObjectOutput out = new ObjectOutputStream(buffer);
        out.writeObject(t1);
        out.close();
 
        ObjectInput in = new ObjectInputStream(new ByteArrayInputStream(
                buffer.toByteArray()));
        StandardTickUnitSource t2 = (StandardTickUnitSource) in.readObject();
        in.close();
 
        assertEquals(t1, t2);
 
    } 
 
} 
9
CodeRank
This code example shows how to use the following methods:writeObject
        super(targetClass);
    } 
 
    @Override 
    public void writeObject(ObjectOutput output, InfinispanBeanGroupEntry<I, T> entry) throws IOException {
        output.writeObject(entry.getBeans());
    } 
 
    @Override 
    public InfinispanBeanGroupEntry<I, T> readObject(ObjectInput input) throws IOException, ClassNotFoundException {
        MarshalledValue<Map<I, T>, MarshallingContext> value = (MarshalledValue<Map<I, T>, MarshallingContext>) input.readObject();
        return new InfinispanBeanGroupEntry<>(value);
    } 
} 
7
CodeRank
This code example shows how to use the following methods:close, writeObject
 
        ItemLabelPosition p1 = new ItemLabelPosition();
 
 
            ByteArrayOutputStream buffer = new ByteArrayOutputStream();
            ObjectOutput out = new ObjectOutputStream(buffer);
            out.writeObject(p1);
            out.close();
 
            ObjectInput in = new ObjectInputStream(
                    new ByteArrayInputStream(buffer.toByteArray()));
            ItemLabelPosition p2 = (ItemLabelPosition) in.readObject();
            in.close();
 
        assertEquals(p1, p2);
 
    } 
 
} 
9
CodeRank
This code example shows how to use the following methods:writeUTF, writeObject
    public boolean isLiteralText() { 
        return true; 
    } 
 
    public void writeExternal(ObjectOutput out) throws IOException {
        out.writeObject(this.value);
        out.writeUTF((this.expectedType != null) ? this.expectedType.getName()
                : ""); 
    } 
 
    public void readExternal(ObjectInput in) throws IOException,
            ClassNotFoundException {
        this.value = in.readObject();
        String type = in.readUTF();
        if (!"".equals(type)) {
            this.expectedType = ReflectionUtil.forName(type);
        } 
    } 
} 
7
CodeRank
This code example shows how to use the following methods:writeBoolean, writeInt, writeShort, writeObject
 
	public void writeExternal(ObjectOutput out) throws IOException {
		ExternalizableUtil.writeString(out, dspName);
		ExternalizableUtil.writeString(out, hint);
		ExternalizableUtil.writeString(out, name.getString());
		out.writeShort(type);
		ExternalizableUtil.writeString(out, strType);
		out.writeBoolean(required);
		out.writeObject(meta);
		out.writeInt(defaultType);
		out.writeBoolean(passByReference);
	} 
	 
 
	public boolean equals(Object obj){ 
		if(!(obj instanceof FunctionArgument)) return false; 
		return equals(this,(FunctionArgument)obj);
	} 
	 
	public static boolean equals(FunctionArgument left, FunctionArgument right) {
7
CodeRank
This code example shows how to use the following methods:writeLong, writeUTF, writeObject

Related ObjectOutput writeObject Questions & Answers:

writeObject Method Overview
Write an object to the underlying storage or stream.
See Code Examples for other Java 8 ObjectOutput Methods: