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

The following examples show how to use java.io.ObjectOutput#write() . 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: JGroupMember.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
/**
   * For Externalizable
   * 
   * @see java.io.Externalizable
   */
  public void writeExternal(ObjectOutput out) throws IOException {
    if (ipAddr == null)
      throw new InternalGemFireError(LocalizedStrings.JGroupMember_ATTEMPT_TO_EXTERNALIZE_NULL_IP_ADDRESS.toLocalizedString());

//    ipAddr.writeExternal(out);
    // do it the way we like
    byte[] address = ipAddr.getIpAddress().getAddress();
    
    out.writeInt(address.length); // IPv6 compatible
    out.write(address);
    out.writeInt(ipAddr.getPort());
    out.write(ipAddr.getFlags());
    Version.writeOrdinal(out, ipAddr.getVersionOrdinal(), true);
    byte bytes[] = new MemberAttributes(ipAddr.getDirectPort(), ipAddr.getProcessId(),
        ipAddr.getVmKind(), ipAddr.getBirthViewId(), ipAddr.getName(), ipAddr.getRoles(),
        (DurableClientAttributes)ipAddr.getDurableClientAttributes()).toByteArray();
    if (bytes == null)
      out.writeInt(0);
    else {
      out.writeInt(bytes.length);
      out.write(bytes);
    }
  }
 
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: BinaryObjectImpl.java    From ignite with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override public void writeExternal(ObjectOutput out) throws IOException {
    if (detachAllowed) {
        int len = length();

        out.writeInt(len);
        out.write(arr, start, len);
        out.writeInt(0);
    }
    else {
        out.writeInt(arr.length);
        out.write(arr);
        out.writeInt(start);
    }
}
 
Example 4
Source File: ClientProxyMembershipID.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
   * For Externalizable
   * 
   * @see Externalizable
   */
  public void writeExternal(ObjectOutput out) throws IOException
  {
//    if (this.transientPort == 0) {
//      InternalDistributedSystem.getLoggerI18n().warning(
//          LocalizedStrings.DEBUG,
//          "externalizing a client ID with zero port: " + this.toString(),
//          new Exception("Stack trace"));
//    }
    Assert.assertTrue(this.identity.length <= BYTES_32KB);
    out.writeShort(this.identity.length);
    out.write(this.identity);
    out.writeInt(this.uniqueId);

  }
 
Example 5
Source File: RpcMessage.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
@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 6
Source File: ClientProxyMembershipID.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
   * For Externalizable
   * 
   * @see Externalizable
   */
  public void writeExternal(ObjectOutput out) throws IOException
  {
//    if (this.transientPort == 0) {
//      InternalDistributedSystem.getLoggerI18n().warning(
//          LocalizedStrings.DEBUG,
//          "externalizing a client ID with zero port: " + this.toString(),
//          new Exception("Stack trace"));
//    }
    Assert.assertTrue(this.identity.length <= BYTES_32KB);
    out.writeShort(this.identity.length);
    out.write(this.identity);
    out.writeInt(this.uniqueId);

  }
 
Example 7
Source File: GemFireTimeSync.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
@Override
public void writeExternal(ObjectOutput out) throws IOException {
  if (!JChannel.getGfFunctions().
      isVersionForStreamAtLeast(out, JGroupsVersion.GFXD_20_ORDINAL)) {
    // GFXD1.4 wrote an unused version
    out.writeInt(0);
  }
  out.writeLong(this.procID);
  out.writeLong(this.time);
  out.writeLong(this.coordTimeBeforeJoin);
  out.writeLong(this.coordTimeAfterJoin);
  out.write(this.opType);
}
 
Example 8
Source File: ReplicationData.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
public void writeExternal(ObjectOutput out) throws IOException {
    out.writeInt(type);
    if(data != null) {
        out.writeInt(data.length);
        out.write(data, 0, data.length);
    }
    else
        out.writeInt(0);
    if(transaction != null) {
        out.writeBoolean(true);
        transaction.writeExternal(out);
    }
    else
        out.writeBoolean(false);
    if(use_locks) {
        out.writeBoolean(true);
        if(lock_info != null) {
            out.writeInt(lock_info.length);
            out.write(lock_info, 0, lock_info.length);
        }
        else
            out.writeInt(0);
        out.writeLong(lock_acquisition_timeout);
        out.writeLong(lock_lease_timeout);
    }
    else
        out.writeBoolean(false);
}
 
Example 9
Source File: AbstractStruct.java    From org.openntf.domino with Apache License 2.0 5 votes vote down vote up
@Override
public void writeExternal(final ObjectOutput out) throws IOException {
	byte[] storage = getBytes();
	//		getByteBuffer().get(storage);
	out.writeInt(storage.length);
	out.write(storage);
}
 
Example 10
Source File: IndexTransformFunction.java    From spliceengine with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void writeExternal(ObjectOutput out) throws IOException {
    byte[] message = tentativeIndex.toByteArray();
    out.writeInt(message.length);
    out.write(message);
    ArrayUtil.writeIntArray(out,projectedMapping);
}
 
Example 11
Source File: MimeType.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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
Source File: MimeType.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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 13
Source File: AbstractStepInterpolator.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/** Save the base state of the instance.
 * This method performs step finalization if it has not been done
 * before.
 * @param out stream where to save the state
 * @exception IOException in case of write error
 */
protected void writeBaseExternal(final ObjectOutput out)
  throws IOException {

  if (currentState == null) {
      out.writeInt(-1);
  } else {
      out.writeInt(currentState.length);
  }
  out.writeDouble(globalPreviousTime);
  out.writeDouble(globalCurrentTime);
  out.writeDouble(softPreviousTime);
  out.writeDouble(softCurrentTime);
  out.writeDouble(h);
  out.writeBoolean(forward);
  out.writeObject(primaryMapper);
  out.write(secondaryMappers.length);
  for (final EquationsMapper  mapper : secondaryMappers) {
      out.writeObject(mapper);
  }

  if (currentState != null) {
      for (int i = 0; i < currentState.length; ++i) {
          out.writeDouble(currentState[i]);
      }
  }

  out.writeDouble(interpolatedTime);

  // we do not store the interpolated state,
  // it will be recomputed as needed after reading

  try {
      // finalize the step (and don't bother saving the now true flag)
      finalizeStep();
  } catch (MaxCountExceededException mcee) {
      final IOException ioe = new IOException(mcee.getLocalizedMessage());
      ioe.initCause(mcee);
      throw ioe;
  }

}
 
Example 14
Source File: EventActionExternalizer.java    From apicurio-studio with Apache License 2.0 4 votes vote down vote up
@Override
public void writeObject(ObjectOutput output, EventAction eventAction) throws IOException {
    byte[] bytes = EventActionUtil.serialize(eventAction);
    output.write(bytes.length);
    output.write(bytes);
}
 
Example 15
Source File: ClientSystemStatesNotification.java    From riotapi with Apache License 2.0 4 votes vote down vote up
@Override
public void writeExternal(ObjectOutput out) throws IOException {
    String asString = json.toString();
    out.writeInt(asString.length());
    out.write(asString.getBytes("UTF-8"));
}
 
Example 16
Source File: SQLDecimal.java    From spliceengine with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * Distill the BigDecimal to a byte array and
 * write out: <UL>
 *	<LI> scale (zero or positive) as a byte </LI>
 *	<LI> length of byte array as a byte</LI>
 *	<LI> the byte array </LI> </UL>
 *
 */
public void writeExternal(ObjectOutput out) throws IOException {
       out.writeBoolean(isNull);
       if (isNull)
           return;

	int scale;
	byte[] byteArray;
	if (value != null) {
		scale = value.scale();

		// J2SE 5.0 introduced negative scale value for BigDecimals.
		// In previouse Java releases a negative scale was not allowed
		// (threw an exception on setScale and the constructor that took
		// a scale).
		//
		// Thus the Derby format for DECIMAL implictly assumed a
		// positive or zero scale value, and thus now must explicitly
		// be positive. This is to allow databases created under J2SE 5.0
		// to continue to be supported under JDK 1.3/JDK 1.4, ie. to continue
		// the platform independence, independent of OS/cpu and JVM.
		//
		// If the scale is negative set the scale to be zero, this results
		// in an unchanged value with a new scale. A BigDecimal with a
		// negative scale by definition is a whole number.
		// e.g. 1000 can be represented by:
		//    a BigDecimal with scale -3 (unscaled value of 1)
		// or a BigDecimal with scale 0 (unscaled value of 1000)

		if (scale < 0) {
			scale = 0;
			setValue(value.setScale(0));
		}

		BigInteger bi = value.unscaledValue();
		byteArray = bi.toByteArray();
	} else {
		scale = rawScale;
		byteArray = rawData;
	}

	if (SanityManager.DEBUG)
	{
		if (scale < 0)
			SanityManager.THROWASSERT("DECIMAL scale at writeExternal is negative "
				+ scale + " value " + toString());
	}

	out.writeByte(scale);
	out.writeByte(byteArray.length);
	out.write(byteArray);
}
 
Example 17
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 18
Source File: MemberImpl.java    From Tomcat7.0.67 with Apache License 2.0 4 votes vote down vote up
@Override
public void writeExternal(ObjectOutput out) throws IOException {
    byte[] data = this.getData();
    out.writeInt(data.length);
    out.write(data);
}
 
Example 19
Source File: AbstractStepInterpolator.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/** Save the base state of the instance.
 * This method performs step finalization if it has not been done
 * before.
 * @param out stream where to save the state
 * @exception IOException in case of write error
 */
protected void writeBaseExternal(final ObjectOutput out)
  throws IOException {

  if (currentState == null) {
      out.writeInt(-1);
  } else {
      out.writeInt(currentState.length);
  }
  out.writeDouble(globalPreviousTime);
  out.writeDouble(globalCurrentTime);
  out.writeDouble(softPreviousTime);
  out.writeDouble(softCurrentTime);
  out.writeDouble(h);
  out.writeBoolean(forward);
  out.writeObject(primaryMapper);
  out.write(secondaryMappers.length);
  for (final EquationsMapper  mapper : secondaryMappers) {
      out.writeObject(mapper);
  }

  if (currentState != null) {
      for (int i = 0; i < currentState.length; ++i) {
          out.writeDouble(currentState[i]);
      }
  }

  out.writeDouble(interpolatedTime);

  // we do not store the interpolated state,
  // it will be recomputed as needed after reading

  try {
      // finalize the step (and don't bother saving the now true flag)
      finalizeStep();
  } catch (MaxCountExceededException mcee) {
      final IOException ioe = new IOException(mcee.getLocalizedMessage());
      ioe.initCause(mcee);
      throw ioe;
  }

}
 
Example 20
Source File: ByteArray.java    From gemfirexd-oss with Apache License 2.0 2 votes vote down vote up
/**
 * Write the byte array out w/o compression
 *
 * @param out write bytes here.
 *
 * @exception IOException		thrown on error
 */
public void writeExternal(ObjectOutput out) throws IOException
{
	out.writeInt(length);
	out.write(array, offset, length);
}