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

The following are Jave code examples for showing how to use flush() 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.
+ Save this method
Example 1
Project: directory-ldap-api   File: DefaultModification.java   View Source Code Vote up 6 votes
/**
 * @see java.io.Externalizable#writeExternal(ObjectOutput)
 */
@Override
public void writeExternal( ObjectOutput out ) throws IOException
{
    // The operation
    out.writeInt( operation.getValue() );

    // The EntryAttribute if not null
    if ( attribute != null )
    {
        out.writeBoolean( true );
        attribute.writeExternal( out );
    }
    else
    {
        out.writeBoolean( false );
    }

    out.flush();
}
 
Example 2
Project: directory-ldap-api   File: LdifControl.java   View Source Code 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: directory-ldap-api   File: Dn.java   View Source Code Vote up 6 votes
/**
 * {@inheritDoc}
 */
@Override
public void writeExternal( ObjectOutput out ) throws IOException
{
    if ( upName == null )
    {
        String message = "Cannot serialize a NULL Dn";
        LOG.error( message );
        throw new IOException( message );
    }

    // Write the UPName
    out.writeUTF( upName );

    // Write the RDNs.
    // First the number of RDNs
    out.writeInt( size() );

    // Loop on the RDNs
    for ( Rdn rdn : rdns )
    {
        rdn.writeExternal( out );
    }

    out.flush();
}
 
Example 4
Project: shareMySheet   File: Message.java   View Source Code Vote up 5 votes
public byte[] toByteArray() throws IOException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ObjectOutput out = new ObjectOutputStream(baos);
    out.writeObject(this);
    out.flush();
    return baos.toByteArray();
}
 
Example 5
Project: directory-ldap-api   File: DefaultEntry.java   View Source Code Vote up 5 votes
/**
 * This is the place where we serialize entries, and all theirs
 * elements.
 * <br>
 * The structure used to store the entry is the following :
 * <ul>
 *   <li>
 *     <b>[Dn]</b> : If it's null, stores an empty Dn
 *   </li>
 *   <li>
 *     <b>[attributes number]</b> : the number of attributes.
 *   </li>
 *   <li>
 *     <b>[attribute]*</b> : each attribute, if we have some
 *   </li>
 * </ul>
 * 
 * {@inheritDoc}
 */
@Override
public void writeExternal( ObjectOutput out ) throws IOException
{
    // First, the Dn
    if ( dn == null )
    {
        // Write an empty Dn
        Dn.EMPTY_DN.writeExternal( out );
    }
    else
    {
        // Write the Dn
        dn.writeExternal( out );
    }

    // Then the attributes.
    // Store the attributes' nulber first
    out.writeInt( attributes.size() );

    // Iterate through the keys.
    for ( Attribute attribute : attributes.values() )
    {
        // Store the attribute
        attribute.writeExternal( out );
    }

    out.flush();
}
 
Example 6
Project: directory-ldap-api   File: DefaultAttribute.java   View Source Code Vote up 5 votes
/**
 * This is the place where we serialize attributes, and all theirs
 * elements.
 * 
 * {@inheritDoc}
 */
@Override
public void writeExternal( ObjectOutput out ) throws IOException
{
    // Write the UPId
    out.writeUTF( upId );
    
    // Write the ID
    out.writeUTF( id );

    // Write the HR flag, if not null
    if ( isHR != null )
    {
        out.writeBoolean( true );
        out.writeBoolean( isHR );
    }
    else
    {
        out.writeBoolean( false );
    }

    // Write the number of values
    out.writeInt( size() );

    if ( size() > 0 )
    {
        // Write each value
        for ( Value value : values )
        {
            // Write the value
            value.writeExternal( out );
        }
    }

    out.flush();
}
 
Example 7
Project: happylifeplat-tcc   File: JavaSerializer.java   View Source Code Vote up 5 votes
@Override
public byte[] serialize(Object obj) throws TccException {
    try (ByteArrayOutputStream arrayOutputStream = new ByteArrayOutputStream()) {
        ObjectOutput objectOutput = new ObjectOutputStream(arrayOutputStream);
        objectOutput.writeObject(obj);
        objectOutput.flush();
        objectOutput.close();
        return arrayOutputStream.toByteArray();
    } catch (IOException e) {
        throw new TccException("JAVA serialize error " + e.getMessage());
    }
}
 
Example 8
Project: keyboard-light-composer   File: KlcColor.java   View Source Code Vote up 5 votes
@Override
public void writeExternal(ObjectOutput out) throws IOException {
	out.writeObject(color.getRed());
	out.writeObject(color.getGreen());
	out.writeObject(color.getBlue());
	out.writeObject(color.getOpacity());
	out.flush();
}
 
Example 9
Project: directory-ldap-api   File: Value.java   View Source Code 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 10
Project: OpenJSharp   File: BitArray.java   View Source Code Vote up 4 votes
public void writeExternal(ObjectOutput out) throws IOException {
    out.writeInt(_bitSize);
    out.writeInt(_mask);
    out.writeObject(_bits);
    out.flush();
}
 
Example 11
Project: openjdk-jdk10   File: BitArray.java   View Source Code Vote up 4 votes
public void writeExternal(ObjectOutput out) throws IOException {
    out.writeInt(_bitSize);
    out.writeInt(_mask);
    out.writeObject(_bits);
    out.flush();
}
 
Example 12
Project: directory-ldap-api   File: Rdn.java   View Source Code Vote up 3 votes
/**
 * A Rdn is composed of on to many Avas (AttributeType And Value).
 * We should write all those Avas sequencially, following the
 * structure :
 * <ul>
 *   <li>
 *     <b>parentId</b> The parent entry's Id
 *   </li>
 *   <li>
 *     <b>nbAvas</b> The number of Avas to write. Can't be 0.
 *   </li>
 *   <li>
 *     <b>upName</b> The User provided Rdn
 *   </li>
 *   <li>
 *     <b>Avas</b>
 *   </li>
 * </ul>
 * <br>
 * For each Ava :
 * <ul>
 *   <li>
 *     <b>start</b> The position of this Ava in the upName string
 *   </li>
 *   <li>
 *     <b>length</b> The Ava user provided length
 *   </li>
 *   <li>
 *     <b>Call the Ava write method</b> The Ava itself
 *   </li>
 * </ul>
 *
 * @see Externalizable#readExternal(ObjectInput)
 * @param out The stream into which the serialized Rdn will be put
 * @throws IOException If the stream can't be written
 */
@Override
public void writeExternal( ObjectOutput out ) throws IOException
{
    out.writeInt( nbAvas );
    out.writeUTF( upName );

    switch ( nbAvas )
    {
        case 0:
            break;

        case 1:
            ava.writeExternal( out );
            break;

        default:
            for ( Ava localAva : avas )
            {
                localAva.writeExternal( out );
            }

            break;
    }

    out.writeInt( h );

    out.flush();
}