Java 8 ObjectOutputStream - 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 ObjectOutputStream class.

This code example shows how to use the following methods:close, writeBoolean, writeFloat, writeInt, writeLong
 
	@Override 
	@Test(enabled = false) 
	public void cycle() throws IOException { 
		ByteArrayOutputStream ba = new ByteArrayOutputStream();
		ObjectOutputStream oos = new ObjectOutputStream(ba);
 
		try { 
			oos.writeInt(300);
			oos.writeBoolean(true);
			oos.writeUTF("Questa e una prova di scrittura di una stringa");
			oos.writeFloat(3.0f);
			oos.writeLong(30000000L);
		} finally { 
			oos.close();
			ba.close();
		} 
	} 
} 
10
CodeRank
This code example shows how to use the following methods:close, writeObject
	@Override 
	public Object deepCopy(Object value) throws HibernateException {
		try { 
			// Write to new byte array to clone. 
			ByteArrayOutputStream baos = new ByteArrayOutputStream(OUTPUT_BYTE_ARRAY_INITIAL_SIZE);
			ObjectOutputStream oos = new ObjectOutputStream(baos);
			try { 
				oos.writeObject(value);
			} 
			finally { 
				oos.close();
			} 
 
			// Read it back and return a true copy. 
			ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
			ObjectInputStream ois = new ObjectInputStream(bais);
			try { 
				return ois.readObject();
			} 
			finally { 
10
CodeRank
This code example shows how to use the following methods:writeBoolean, writeInt, writeObject
This code example shows how to use the following methods:writeObject
 */ 
public class SerializationTestUtils { 
 
	public static void testSerialization(Object o) throws IOException {
		OutputStream baos = new ByteArrayOutputStream();
		ObjectOutputStream oos = new ObjectOutputStream(baos);
		oos.writeObject(o);
	} 
 
	public static boolean isSerializable(Object o) throws IOException {
		try { 
			testSerialization(o); 
			return true; 
		} 
		catch (NotSerializableException ex) {
			return false; 
		} 
	} 
 
	public static Object serializeAndDeserialize(Object o) throws IOException, ClassNotFoundException {
9
CodeRank
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
    input.close();
  } 
 
  private void saveToObj(Path serialObj) {
    try { 
      ObjectOutputStream output = new ObjectOutputStream(Files.newOutputStream(
          serialObj));
      output.writeObject(bigramHashTable);
      output.writeObject(frequencyTable);
      output.close();
      // log.info("serialize bigram dict."); 
    } catch (Exception e) {
      // log.warn(e.getMessage()); 
    } 
  } 
 
  private void load() throws IOException, ClassNotFoundException {
    InputStream input = this.getClass().getResourceAsStream("bigramdict.mem");
    loadFromInputStream(input);
  } 
9
CodeRank
This code example shows how to use the following methods:close, writeObject
 
    @Override 
    public ByteBuffer toByteBuffer(Object obj) {
        try { 
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            ObjectOutputStream oos = new ObjectOutputStream(baos);
            oos.writeObject(obj);
            oos.close();
 
            return ByteBuffer.wrap(baos.toByteArray());
        } catch (IOException ex) {
            throw new RuntimeException(ex);
        } 
    } 
 
    @Override 
    public Object fromByteBuffer(ByteBuffer bytes) {
        if ((bytes == null) || !bytes.hasRemaining()) {
            return null; 
        } 
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:writeObject
  public JavaJobSerializer() {} 
 
  @Override 
  public String serialize(Job job) throws IOException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ObjectOutputStream    oos  = new ObjectOutputStream(baos);
    oos.writeObject(job);
 
    return Base64.encodeToString(baos.toByteArray(), Base64.NO_WRAP);
  } 
 
  @Override 
  public Job deserialize(EncryptionKeys keys, boolean encrypted, String serialized) throws IOException {
    try { 
      ByteArrayInputStream bais = new ByteArrayInputStream(Base64.decode(serialized, Base64.NO_WRAP));
      ObjectInputStream    ois  = new ObjectInputStream(bais);
 
      return (Job)ois.readObject();
    } catch (ClassNotFoundException e) {
      throw new IOException(e);
9
CodeRank
This code example shows how to use the following methods:close, writeObject
ByteArrayOutputStream outStream;
        try 
        { 
            outStream = new ByteArrayOutputStream();
            ObjectOutputStream out = new ObjectOutputStream(outStream);
            out.writeObject(object);
            out.close();
        } 
        catch (IOException e)
        { 
            throw new NamingException(e.getMessage());
        } 
 
        BinaryRefAddr handle = new BinaryRefAddr("com.impetus.kundera.persistence.jta", outStream.toByteArray());
        Reference ret = new Reference(object.getClass().getName(), handle, UserTransactionFactory.class.getName(), null);
        return ret;
    } 
} 
9
CodeRank

Related Java 8 ObjectOutputStream Questions & Answers:

See Code Examples for Java 8 ObjectOutputStream Methods: