Java 8 ObjectOutput - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 ObjectOutput class.

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
Contextual code suggestions in your IDE  Get Codota for Java
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
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:write
    version.getSerializer().readFrom(iInput, version);
    recordType = iInput.readByte();
  } 
 
  public void writeExternal(final ObjectOutput iOutput) throws IOException {
    super.writeExternal(iOutput);
    version.getSerializer().writeTo(iOutput, version);
    iOutput.write(recordType);
  } 
} 
8
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
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
Contextual code suggestions in your IDE  Get Codota for Java
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
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:writeBoolean, writeInt, write, DataOutput.writeUTF
		this.content = content;
	} 
 
	public void writeExternal(ObjectOutput out) throws IOException {
		if ( accessType != null ) {
            out.writeBoolean( true );
            out.writeUTF( accessType.toString() );
		} else { 
            out.writeBoolean( false );
        } 
		if ( type != null ) {
            out.writeBoolean( true );
            out.writeUTF( type );
		} else { 
            out.writeBoolean( false );
        } 
		if ( content != null ) {
            out.writeBoolean( true );
            out.writeInt( content.length );
            out.write( content );

7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
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
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:writeInt, writeUTF, write
    } 
 
    @Override 
    public void writeObject(ObjectOutput output, ClientMapping mapping) throws IOException {
        byte[] address = mapping.getSourceNetworkAddress().getAddress();
        output.writeInt(address.length);
        output.write(address);
        output.writeInt(mapping.getSourceNetworkMaskBits());
        output.writeUTF(mapping.getDestinationAddress());
        output.writeInt(mapping.getDestinationPort());
    } 
 
    @Override 
    public ClientMapping readObject(ObjectInput input) throws IOException {
        byte[] sourceAddress = new byte[input.readInt()];
        input.readFully(sourceAddress);
        int sourcePort = input.readInt();
        String destAddress = input.readUTF();
        int destPort = input.readInt();
        return new ClientMapping(InetAddress.getByAddress(sourceAddress), sourcePort, destAddress, destPort);
8
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:writeBoolean, writeDouble, writeInt, writeLong
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
Contextual code suggestions in your IDE  Get Codota for Java

Related Java 8 ObjectOutput Questions & Answers:

See Code Examples for Java 8 ObjectOutput Methods: