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

The following examples show how to use java.io.ObjectOutput#flush() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
/**
 * @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
Source Project: tomee   File: EJBRequest.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Write to server.
 * WARNING: To maintain backwards compatibility never change the order or insert new writes, always append to
 * {@link org.apache.openejb.client.EJBRequest.Body#writeExternal(java.io.ObjectOutput)}
 *
 * @param out ObjectOutput
 * @throws IOException
 */
@Override
public void writeExternal(final ObjectOutput out) throws IOException {

    out.writeByte(requestMethod.getCode());

    if (deploymentCode > 0) {
        out.writeObject(null);
    } else {
        out.writeObject(deploymentId);
    }

    out.writeShort(deploymentCode);
    out.writeObject(clientIdentity);
    out.writeInt(serverHash);
    out.flush();

    body.setMetaData(metaData);
    body.writeExternal(out);
}
 
Example 3
Source Project: directory-ldap-api   File: LdifControl.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * {@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 4
Source Project: directory-ldap-api   File: Dn.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void writeExternal( ObjectOutput out ) throws IOException
{
    if ( upName == null )
    {
        String message = I18n.err( I18n.ERR_13624_CANNOT_SERIALIZE_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 5
private byte[] writeObject(Object o) throws IOException {
    try (ByteArrayOutputStream  bos = new ByteArrayOutputStream()) {
        ObjectOutput out = new ObjectOutputStream(bos);
        out.writeObject(o);
        out.flush();
        return bos.toByteArray();
    }
}
 
Example 6
private static byte[] serialize(Object obj) throws IOException {
    ByteArrayOutputStream   bytes   = new ByteArrayOutputStream();
    ObjectOutput            out = new DroolsObjectOutputStream(bytes);

    out.writeObject(obj);
    out.flush();
    out.close();

    return bytes.toByteArray();
}
 
Example 7
private static byte[] marshal(Object obj) throws IOException {
    ByteArrayOutputStream   bytes   = new ByteArrayOutputStream();
    ObjectOutput            out = new ObjectOutputStream(bytes);

    out.writeObject(obj);
    out.flush();
    out.close();

    return bytes.toByteArray();
}
 
Example 8
public void testReadWriteExternal() throws IOException, ClassNotFoundException {

      final ByteArrayOutputStream baos = new ByteArrayOutputStream(100);
      final ObjectOutput oos = new ObjectOutputStream(baos);
      oos.writeObject(byteArrayKey);
      oos.flush();

      assertEquals(byteArrayKey, new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray())).readObject());
   }
 
Example 9
Source Project: yauaa   File: TestJavaSerialization.java    License: Apache License 2.0 5 votes vote down vote up
byte[] serialize(UserAgentAnalyzerTester uaa) throws IOException {
    try (ByteArrayOutputStream bos = new ByteArrayOutputStream()) {
        ObjectOutput out = new ObjectOutputStream(bos);
        out.writeObject(uaa);
        out.flush();
        return bos.toByteArray();
    }
}
 
Example 10
Source Project: ignite   File: ClientConfigurationTest.java    License: Apache License 2.0 5 votes vote down vote up
/** Serialization/deserialization. */
@Test
public void testSerialization() throws IOException, ClassNotFoundException {
    ClientConfiguration target = new ClientConfiguration()
        .setAddresses("127.0.0.1:10800", "127.0.0.1:10801")
        .setTimeout(123)
        .setBinaryConfiguration(new BinaryConfiguration()
            .setClassNames(Collections.singleton("Person"))
        )
        .setSslMode(SslMode.REQUIRED)
        .setSslClientCertificateKeyStorePath("client.jks")
        .setSslClientCertificateKeyStoreType("JKS")
        .setSslClientCertificateKeyStorePassword("123456")
        .setSslTrustCertificateKeyStorePath("trust.jks")
        .setSslTrustCertificateKeyStoreType("JKS")
        .setSslTrustCertificateKeyStorePassword("123456")
        .setSslKeyAlgorithm("SunX509");

    ByteArrayOutputStream outBytes = new ByteArrayOutputStream();

    ObjectOutput out = new ObjectOutputStream(outBytes);

    out.writeObject(target);
    out.flush();

    ObjectInput in = new ObjectInputStream(new ByteArrayInputStream(outBytes.toByteArray()));

    Object desTarget = in.readObject();

    assertTrue(Comparers.equal(target, desTarget));
}
 
Example 11
Source Project: directory-ldap-api   File: DefaultEntry.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 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 12
Source Project: MyVirtualDirectory   File: DefaultEntry.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 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}
 */
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 13
Source Project: jdk1.8-source-analysis   File: BitArray.java    License: Apache License 2.0 4 votes vote down vote up
public void writeExternal(ObjectOutput out) throws IOException {
    out.writeInt(_bitSize);
    out.writeInt(_mask);
    out.writeObject(_bits);
    out.flush();
}
 
Example 14
Source Project: mynlp   File: CoreDictionaryImpl.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void writeExternal(ObjectOutput out) throws IOException {
    out.writeInt(totalFreq);
    trie.save(out);
    out.flush();
}
 
Example 15
Source Project: jdk8u60   File: BitArray.java    License: GNU General Public License v2.0 4 votes vote down vote up
public void writeExternal(ObjectOutput out) throws IOException {
    out.writeInt(_bitSize);
    out.writeInt(_mask);
    out.writeObject(_bits);
    out.flush();
}
 
Example 16
public void writeExternal(ObjectOutput out) throws IOException {
    out.writeInt(_bitSize);
    out.writeInt(_mask);
    out.writeObject(_bits);
    out.flush();
}
 
Example 17
public void writeExternal(ObjectOutput out) throws IOException {
    out.writeInt(_bitSize);
    out.writeInt(_mask);
    out.writeObject(_bits);
    out.flush();
}
 
Example 18
public void writeExternal(ObjectOutput out) throws IOException {
    out.writeInt(_bitSize);
    out.writeInt(_mask);
    out.writeObject(_bits);
    out.flush();
}
 
Example 19
Source Project: directory-ldap-api   File: Value.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * {@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 20
/** Serialization/deserialization. */
@Test
public void testSerialization() throws IOException, ClassNotFoundException {
    ClientCacheConfiguration target = new ClientCacheConfiguration().setName("Person")
        .setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL)
        .setBackups(3)
        .setCacheMode(CacheMode.PARTITIONED)
        .setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC)
        .setEagerTtl(false)
        .setGroupName("FunctionalTest")
        .setDefaultLockTimeout(12345)
        .setPartitionLossPolicy(PartitionLossPolicy.READ_WRITE_ALL)
        .setReadFromBackup(true)
        .setRebalanceBatchSize(67890)
        .setRebalanceBatchesPrefetchCount(102938)
        .setRebalanceDelay(54321)
        .setRebalanceMode(CacheRebalanceMode.SYNC)
        .setRebalanceOrder(2)
        .setRebalanceThrottle(564738)
        .setRebalanceTimeout(142536)
        .setKeyConfiguration(new CacheKeyConfiguration("Employee", "orgId"))
        .setQueryEntities(new QueryEntity(int.class.getName(), "Employee")
            .setTableName("EMPLOYEE")
            .setFields(
                Stream.of(
                    new SimpleEntry<>("id", Integer.class.getName()),
                    new SimpleEntry<>("orgId", Integer.class.getName())
                ).collect(Collectors.toMap(
                    SimpleEntry::getKey, SimpleEntry::getValue, (a, b) -> a, LinkedHashMap::new
                ))
            )
            .setKeyFields(Collections.singleton("id"))
            .setNotNullFields(Collections.singleton("id"))
            .setDefaultFieldValues(Collections.singletonMap("id", 0))
            .setIndexes(Collections.singletonList(new QueryIndex("id", true, "IDX_EMPLOYEE_ID")))
            .setAliases(Stream.of("id", "orgId").collect(Collectors.toMap(f -> f, String::toUpperCase)))
        );

    ByteArrayOutputStream outBytes = new ByteArrayOutputStream();

    ObjectOutput out = new ObjectOutputStream(outBytes);

    out.writeObject(target);
    out.flush();

    ObjectInput in = new ObjectInputStream(new ByteArrayInputStream(outBytes.toByteArray()));

    Object desTarget = in.readObject();

    assertTrue(Comparers.equal(target, desTarget));
}