Search in sources :

Example 11 with HeapDataOutputStream

use of org.apache.geode.internal.HeapDataOutputStream in project geode by apache.

the class HandShake method write.

/**
   * client-to-server handshake. Nothing is sent to the server prior to invoking this method.
   */
private byte write(DataOutputStream dos, DataInputStream dis, byte communicationMode, int replyCode, int readTimeout, List ports, Properties p_credentials, DistributedMember member, boolean isCallbackConnection) throws IOException {
    HeapDataOutputStream hdos = new HeapDataOutputStream(32, Version.CURRENT);
    byte acceptanceCode = -1;
    try {
        hdos.writeByte(communicationMode);
        if (overrideClientVersion > 0) {
            // for testing
            Version.writeOrdinal(hdos, overrideClientVersion, true);
        } else {
            Version.writeOrdinal(hdos, currentClientVersion.ordinal(), true);
        }
        hdos.writeByte(replyCode);
        if (ports != null) {
            hdos.writeInt(ports.size());
            for (int i = 0; i < ports.size(); i++) {
                hdos.writeInt(Integer.parseInt((String) ports.get(i)));
            }
        } else {
            hdos.writeInt(readTimeout);
        }
        // we do not know the receiver's version at this point, but the on-wire
        // form of InternalDistributedMember changed in 9.0, so we must serialize
        // it using the previous version
        DataOutput idOut = new VersionedDataOutputStream(hdos, Version.GFE_82);
        DataSerializer.writeObject(this.id, idOut);
        if (currentClientVersion.compareTo(Version.GFE_603) >= 0) {
            for (int bytes = 0; bytes < this.overrides.length; bytes++) {
                hdos.writeByte(this.overrides[bytes]);
            }
        } else {
            // write the client conflation setting byte
            if (setClientConflationForTesting) {
                hdos.writeByte(clientConflationForTesting);
            } else {
                hdos.writeByte(this.clientConflation);
            }
        }
        if (isCallbackConnection || communicationMode == Acceptor.GATEWAY_TO_GATEWAY) {
            if (isCallbackConnection && this.multiuserSecureMode && communicationMode != Acceptor.GATEWAY_TO_GATEWAY) {
                hdos.writeByte(SECURITY_MULTIUSER_NOTIFICATIONCHANNEL);
                hdos.flush();
                dos.write(hdos.toByteArray());
                dos.flush();
            } else {
                writeCredentials(dos, dis, p_credentials, ports != null, member, hdos);
            }
        } else {
            String authInitMethod = this.system.getProperties().getProperty(SECURITY_CLIENT_AUTH_INIT);
            acceptanceCode = writeCredential(dos, dis, authInitMethod, ports != null, member, hdos);
        }
    } finally {
        hdos.close();
    }
    return acceptanceCode;
}
Also used : DataOutput(java.io.DataOutput) HeapDataOutputStream(org.apache.geode.internal.HeapDataOutputStream) VersionedDataOutputStream(org.apache.geode.internal.VersionedDataOutputStream)

Example 12 with HeapDataOutputStream

use of org.apache.geode.internal.HeapDataOutputStream in project geode by apache.

the class Message method serializeAndAddPart.

private void serializeAndAddPart(Object o, boolean zipValues) {
    if (zipValues) {
        throw new UnsupportedOperationException("zipValues no longer supported");
    }
    Version v = this.version;
    if (this.version.equals(Version.CURRENT)) {
        v = null;
    }
    // do NOT close the HeapDataOutputStream
    HeapDataOutputStream hdos = new HeapDataOutputStream(this.chunkSize, v);
    try {
        BlobHelper.serializeTo(o, hdos);
    } catch (IOException ex) {
        throw new SerializationException("failed serializing object", ex);
    }
    this.messageModified = true;
    Part part = this.partsList[this.currentPart];
    part.setPartState(hdos, true);
    this.currentPart++;
}
Also used : SerializationException(org.apache.geode.SerializationException) Version(org.apache.geode.internal.Version) HeapDataOutputStream(org.apache.geode.internal.HeapDataOutputStream) IOException(java.io.IOException)

Example 13 with HeapDataOutputStream

use of org.apache.geode.internal.HeapDataOutputStream in project geode by apache.

the class ServerConnection method encryptId.

private byte[] encryptId(long id, ServerConnection servConn) throws Exception {
    // deserialize this using handshake keys
    HeapDataOutputStream hdos = null;
    try {
        hdos = new HeapDataOutputStream(Version.CURRENT);
        hdos.writeLong(id);
        return ((HandShake) this.handshake).encryptBytes(hdos.toByteArray());
    } finally {
        hdos.close();
    }
}
Also used : ClientHandShake(org.apache.geode.internal.cache.tier.ClientHandShake) HeapDataOutputStream(org.apache.geode.internal.HeapDataOutputStream)

Example 14 with HeapDataOutputStream

use of org.apache.geode.internal.HeapDataOutputStream in project geode by apache.

the class OffHeapStoredObject method sendAsByteArray.

@Override
public void sendAsByteArray(DataOutput out) throws IOException {
    if (!isCompressed() && out instanceof HeapDataOutputStream) {
        ByteBuffer bb = createDirectByteBuffer();
        if (bb != null) {
            HeapDataOutputStream hdos = (HeapDataOutputStream) out;
            InternalDataSerializer.writeArrayLength(bb.remaining(), hdos);
            hdos.write(bb);
            return;
        }
    }
    super.sendAsByteArray(out);
}
Also used : HeapDataOutputStream(org.apache.geode.internal.HeapDataOutputStream) ByteBuffer(java.nio.ByteBuffer)

Example 15 with HeapDataOutputStream

use of org.apache.geode.internal.HeapDataOutputStream in project geode by apache.

the class PdxInstanceEnum method toBytes.

public byte[] toBytes() throws IOException {
    HeapDataOutputStream hdos = new HeapDataOutputStream(Version.CURRENT);
    sendTo(hdos);
    return hdos.toByteArray();
}
Also used : HeapDataOutputStream(org.apache.geode.internal.HeapDataOutputStream)

Aggregations

HeapDataOutputStream (org.apache.geode.internal.HeapDataOutputStream)134 Test (org.junit.Test)55 IOException (java.io.IOException)40 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)36 SerializationTest (org.apache.geode.test.junit.categories.SerializationTest)33 DataInputStream (java.io.DataInputStream)29 ByteArrayInputStream (java.io.ByteArrayInputStream)23 UnitTest (org.apache.geode.test.junit.categories.UnitTest)15 DiskAccessException (org.apache.geode.cache.DiskAccessException)12 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)11 PdxSerializerObject (org.apache.geode.internal.PdxSerializerObject)10 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)8 Version (org.apache.geode.internal.Version)8 DataInput (java.io.DataInput)7 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)7 OutputStream (java.io.OutputStream)6 Properties (java.util.Properties)6 ByteBuffer (java.nio.ByteBuffer)5 HashMap (java.util.HashMap)5 InternalGemFireException (org.apache.geode.InternalGemFireException)5