Java Code Examples for java.io.ObjectOutput.write()

The following are Jave code examples for showing how to use write() of the java.io.ObjectOutput class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: incubator-netbeans   File: NbObjectOutputStream.java   Source Code and License Vote up 6 votes
/** Writes an object safely to the object output.
 * Can be read by {@link NbObjectInputStream#readSafely}.
* @param oo object output to write to
* @param obj the object to write
* @exception SafeException if the object simply fails to be serialized
* @exception IOException if something more serious fails
*/
public static void writeSafely(ObjectOutput oo, Object obj)
throws IOException {
    ByteArrayOutputStream bos = new ByteArrayOutputStream(200);

    try {
        NbObjectOutputStream oos = new NbObjectOutputStream(bos);
        oos.writeObject(obj);
        oos.flush();
        bos.close();
    } catch (Exception exc) {
        // exception during safe of the object
        // encapsulate all exceptions into safe exception
        oo.writeInt(0);
        throw new SafeException(exc);
    }

    oo.writeInt(bos.size());
    oo.write(bos.toByteArray());
}
 
Example 2
Project: directory-ldap-api   File: LdifControl.java   Source Code and License Vote up 6 votes
/**
 * {@inheritDoc}
 */
@Override
public void writeExternal( ObjectOutput out ) throws IOException
{
    out.writeUTF( oid );
    out.writeBoolean( criticality );

    if ( hasValue() )
    {
        out.writeBoolean( true );
        out.writeInt( value.length );

        if ( value.length > 0 )
        {
            out.write( value );
        }
    }
    else
    {
        out.writeBoolean( false );
    }

    out.flush();
}
 
Example 3
Project: lazycat   File: RpcMessage.java   Source Code and License Vote up 5 votes
@Override
public void writeExternal(ObjectOutput out) throws IOException {
	out.writeBoolean(reply);
	out.writeInt(uuid.length);
	out.write(uuid, 0, uuid.length);
	out.writeInt(rpcId.length);
	out.write(rpcId, 0, rpcId.length);
	out.writeObject(message);
}
 
Example 4
Project: lazycat   File: AbstractReplicatedMap.java   Source Code and License Vote up 5 votes
/**
 * @deprecated Unused - will be removed in 8.0.x
 */
@Deprecated
protected void writeMembers(ObjectOutput out, Member[] members) throws IOException {
	if (members == null)
		members = new Member[0];
	out.writeInt(members.length);
	for (int i = 0; i < members.length; i++) {
		if (members[i] != null) {
			byte[] d = members[i] != null ? ((MemberImpl) members[i]).getData(false) : new byte[0];
			out.writeInt(d.length);
			out.write(d);
		}
	}
}
 
Example 5
Project: lazycat   File: ByteMessage.java   Source Code and License Vote up 5 votes
/**
 * @see java.io.Externalizable#writeExternal
 * @param out
 *            ObjectOutput
 * @throws IOException
 */
@Override
public void writeExternal(ObjectOutput out) throws IOException {
	out.writeInt(message != null ? message.length : 0);
	if (message != null)
		out.write(message, 0, message.length);
}
 
Example 6
Project: QDrill   File: LoopedAbstractDrillSerializable.java   Source Code and License Vote up 5 votes
@Override
public void writeExternal(ObjectOutput out) throws IOException {
  final ByteArrayOutputStream baos = new ByteArrayOutputStream();
  writeToStream(baos);
  final byte[] ba = baos.toByteArray();
  out.writeInt(ba.length);
  out.write(ba);
}
 
Example 7
Project: OpenJSharp   File: MimeType.java   Source Code and License Vote up 5 votes
/**
 * The object implements the writeExternal method to save its contents
 * by calling the methods of DataOutput for its primitive values or
 * calling the writeObject method of ObjectOutput for objects, strings
 * and arrays.
 * @exception IOException Includes any I/O exceptions that may occur
 */
public void writeExternal(ObjectOutput out) throws IOException {
    String s = toString(); // contains ASCII chars only
    // one-to-one correspondence between ASCII char and byte in UTF string
    if (s.length() <= 65535) { // 65535 is max length of UTF string
        out.writeUTF(s);
    } else {
        out.writeByte(0);
        out.writeByte(0);
        out.writeInt(s.length());
        out.write(s.getBytes());
    }
}
 
Example 8
Project: monarch   File: ByteBufferInputStream.java   Source Code and License Vote up 5 votes
public void writeExternal(ObjectOutput out) throws IOException {
  out.writeBoolean(this.buffer != null);
  if (this.buffer != null) {
    out.writeInt(this.buffer.capacity());
    out.writeInt(this.buffer.limit());
    out.writeInt(this.buffer.position());
    for (int i = 0; i < this.buffer.capacity(); i++) {
      out.write(this.buffer.get(i));
    }
  }
}
 
Example 9
Project: dremio-oss   File: LoopedAbstractSerializable.java   Source Code and License Vote up 5 votes
@Override
public void writeExternal(ObjectOutput out) throws IOException {
  final ByteArrayOutputStream baos = new ByteArrayOutputStream();
  writeToStream(baos);
  final byte[] ba = baos.toByteArray();
  out.writeInt(ba.length);
  out.write(ba);
}
 
Example 10
Project: apache-tomcat-7.0.73-with-comment   File: RpcMessage.java   Source Code and License Vote up 5 votes
@Override
public void writeExternal(ObjectOutput out) throws IOException {
    out.writeInt(uuid.length);
    out.write(uuid, 0, uuid.length);
    out.writeInt(rpcId.length);
    out.write(rpcId, 0, rpcId.length);
}
 
Example 11
Project: openjdk-jdk10   File: MimeType.java   Source Code and License Vote up 5 votes
/**
 * The object implements the writeExternal method to save its contents by
 * calling the methods of DataOutput for its primitive values or calling the
 * writeObject method of ObjectOutput for objects, strings and arrays.
 *
 * @throws IOException Includes any I/O exceptions that may occur
 */
public void writeExternal(ObjectOutput out) throws IOException {
    String s = toString(); // contains ASCII chars only
    // one-to-one correspondence between ASCII char and byte in UTF string
    if (s.length() <= 65535) { // 65535 is max length of UTF string
        out.writeUTF(s);
    } else {
        out.writeByte(0);
        out.writeByte(0);
        out.writeInt(s.length());
        out.write(s.getBytes());
    }
}
 
Example 12
Project: directory-ldap-api   File: Value.java   Source Code and License Vote up 4 votes
/**
 * {@inheritDoc}
 */
@Override
public void writeExternal( ObjectOutput out ) throws IOException
{
    // Write a boolean for the HR flag
    out.writeBoolean( isHR );

    if ( isHR )
    { 
        // Write the value if any
        out.writeBoolean( upValue != null );

        if ( upValue != null )
        {
            // Write the value
            out.writeInt( bytes.length );

            if ( bytes.length > 0 )
            {
                out.write( bytes );
            }
        }

        // Write the prepared value if any
        out.writeBoolean( normValue != null );

        if ( normValue != null )
        {
            // Write the value
            out.writeUTF( normValue );
        }
    }
    else
    {
        // Just write the bytes if not null
        out.writeBoolean( bytes != null );

        if ( bytes != null )
        {
            out.writeInt( bytes.length );
            
            if ( bytes.length > 0 )
            {
                out.write( bytes );
            }
        }
    }

    // and flush the data
    out.flush();
}
 
Example 13
Project: mycat-src-1.6.1-RELEASE   File: UTF8String.java   Source Code and License Vote up 4 votes
public void writeExternal(ObjectOutput out) throws IOException {
  byte[] bytes = getBytes();
  out.writeInt(bytes.length);
  out.write(bytes);
}
 
Example 14
Project: tomcat7   File: ByteMessage.java   Source Code and License Vote up 4 votes
/**
 * @see java.io.Externalizable#writeExternal
 * @param out ObjectOutput
 * @throws IOException
 */
@Override
public void writeExternal(ObjectOutput out) throws IOException {
    out.writeInt(message!=null?message.length:0);
    if ( message!=null ) out.write(message,0,message.length);
}
 
Example 15
Project: hashsdn-controller   File: AbstractIdentifiablePayload.java   Source Code and License Vote up 4 votes
@Override
public final void writeExternal(final ObjectOutput out) throws IOException {
    out.writeInt(serialized.length);
    out.write(serialized);
}
 
Example 16
Project: hashsdn-controller   File: MemberName.java   Source Code and License Vote up 4 votes
@Override
public void writeExternal(final ObjectOutput out) throws IOException {
    out.writeInt(serialized.length);
    out.write(serialized);
}
 
Example 17
Project: scala-playground   File: BinaryTrade.java   Source Code and License Vote up 4 votes
@Override
public void writeExternal(ObjectOutput out) throws IOException {
  out.write(data);
}
 
Example 18
Project: hashsdn-controller   File: CommitTransactionPayload.java   Source Code and License Vote up 4 votes
@Override
public void writeExternal(final ObjectOutput out) throws IOException {
    out.writeInt(serialized.length);
    out.write(serialized);
}
 
Example 19
Project: apache-tomcat-7.0.73-with-comment   File: ByteMessage.java   Source Code and License Vote up 4 votes
/**
 * @see java.io.Externalizable#writeExternal
 * @param out ObjectOutput
 * @throws IOException
 */
@Override
public void writeExternal(ObjectOutput out) throws IOException {
    out.writeInt(message!=null?message.length:0);
    if ( message!=null ) out.write(message,0,message.length);
}
 
Example 20
Project: apache-tomcat-7.0.73-with-comment   File: MemberImpl.java   Source Code and License Vote up 4 votes
@Override
public void writeExternal(ObjectOutput out) throws IOException {
    byte[] data = this.getData();
    out.writeInt(data.length);
    out.write(data);
}