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

The following examples show how to use java.io.ObjectOutput#flush() . 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
Source File: Dn.java    From directory-ldap-api with 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 2
Source File: LdifControl.java    From directory-ldap-api with 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 3
Source File: DefaultModification.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * @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 4
Source File: EJBRequest.java    From tomee with 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 5
Source File: DefaultEntry.java    From MyVirtualDirectory with 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 6
Source File: JdkPluginTest.java    From HotswapAgent with GNU General Public License v2.0 5 votes vote down vote up
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 7
Source File: DroolsObjectIOTest.java    From kogito-runtimes with Apache License 2.0 5 votes vote down vote up
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 8
Source File: DroolsObjectIOTest.java    From kogito-runtimes with Apache License 2.0 5 votes vote down vote up
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 9
Source File: ByteArrayKeyTest.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
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 10
Source File: TestJavaSerialization.java    From yauaa with 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 11
Source File: ClientConfigurationTest.java    From ignite with 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 12
Source File: DefaultEntry.java    From directory-ldap-api with 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 13
Source File: BitArray.java    From openjdk-jdk8u with 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 14
Source File: ClientCacheConfigurationTest.java    From ignite with Apache License 2.0 4 votes vote down vote up
/** 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));
}
 
Example 15
Source File: Value.java    From directory-ldap-api with 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 16
Source File: BitArray.java    From openjdk-8-source with 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 17
Source File: BitArray.java    From jdk1.8-source-analysis with 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 18
Source File: BitArray.java    From openjdk-jdk9 with 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 19
Source File: BitArray.java    From jdk8u60 with 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 20
Source File: CoreDictionaryImpl.java    From mynlp with 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();
}