Search in sources :

Example 6 with ObjectOutput

use of java.io.ObjectOutput in project camel by apache.

the class ShiroSecurityHelper method encrypt.

public static ByteSource encrypt(ShiroSecurityToken securityToken, byte[] passPhrase, CipherService cipherService) throws Exception {
    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    ObjectOutput serialStream = new ObjectOutputStream(stream);
    try {
        serialStream.writeObject(securityToken);
        return cipherService.encrypt(stream.toByteArray(), passPhrase);
    } finally {
        close(serialStream);
        IOHelper.close(stream);
    }
}
Also used : ObjectOutput(java.io.ObjectOutput) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream)

Example 7 with ObjectOutput

use of java.io.ObjectOutput in project hibernate-orm by hibernate.

the class DeleteOrphanTest method serialize.

private byte[] serialize(Object object) throws IOException {
    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    ObjectOutput out = new ObjectOutputStream(stream);
    out.writeObject(object);
    out.close();
    byte[] serialized = stream.toByteArray();
    stream.close();
    return serialized;
}
Also used : ObjectOutput(java.io.ObjectOutput) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream)

Example 8 with ObjectOutput

use of java.io.ObjectOutput in project Serial by twitter.

the class LegacySerial method toByteArray.

/**
 * Serialize the given value and compress the result bytes. This method should be used only for values
 * that may occupy large amount of memories. Do not use this method for small objects because the
 * compression incurs performance overheads and the compressed data cannot be inspected using
 * SerializationUtils.dumpSerializedData
 *
 * @param value the value to be serialized.
 * @param serializer the serializer used to serialize value.
 * @return compressed bytes of the serialized value.
 */
@Override
@NotNull
public <T> byte[] toByteArray(@Nullable T value, @NotNull Serializer<T> serializer) throws IOException {
    if (value == null) {
        return InternalSerialUtils.EMPTY_BYTE_ARRAY;
    }
    final ByteArrayOutputStream byteOutputStream = new ByteArrayOutputStream();
    ObjectOutput objectOutput = null;
    try {
        objectOutput = new ObjectOutputStream(byteOutputStream);
        serializer.serialize(mContext, new LegacySerializerOutput(objectOutput), value);
    } catch (IOException e) {
        throw e;
    } finally {
        if (objectOutput != null) {
            try {
                objectOutput.close();
            } catch (IOException ignore) {
            }
        }
    }
    return byteOutputStream.toByteArray();
}
Also used : ObjectOutput(java.io.ObjectOutput) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) ObjectOutputStream(java.io.ObjectOutputStream) NotNull(org.jetbrains.annotations.NotNull)

Example 9 with ObjectOutput

use of java.io.ObjectOutput in project ignite by apache.

the class IgfsAttributesSelfTest method testSerialization.

/**
 * @throws Exception If failed.
 */
public void testSerialization() throws Exception {
    Map<String, IgfsMode> pathModes = new HashMap<>();
    pathModes.put("path1", PRIMARY);
    pathModes.put("path2", PROXY);
    IgfsAttributes attrs = new IgfsAttributes("testIgfsName", 513000, 888, "meta", "data", DUAL_SYNC, pathModes, true);
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    ObjectOutput os = new ObjectOutputStream(bos);
    os.writeObject(attrs);
    os.close();
    IgfsAttributes deserializedAttrs = (IgfsAttributes) new ObjectInputStream(new ByteArrayInputStream(bos.toByteArray())).readObject();
    assertTrue(eq(attrs, deserializedAttrs));
}
Also used : IgfsMode(org.apache.ignite.igfs.IgfsMode) ObjectOutput(java.io.ObjectOutput) HashMap(java.util.HashMap) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) ObjectInputStream(java.io.ObjectInputStream)

Example 10 with ObjectOutput

use of java.io.ObjectOutput in project ignite by apache.

the class GridClientJdkMarshaller method marshal.

/**
 * {@inheritDoc}
 */
@Override
public ByteBuffer marshal(Object obj, int off) throws IOException {
    GridByteArrayOutputStream bOut = new GridByteArrayOutputStream();
    ObjectOutput out = new ObjectOutputStream(bOut);
    out.writeObject(obj);
    out.flush();
    ByteBuffer buf = ByteBuffer.allocate(off + bOut.size());
    buf.position(off);
    buf.put(bOut.internalArray(), 0, bOut.size());
    buf.flip();
    return buf;
}
Also used : ObjectOutput(java.io.ObjectOutput) GridByteArrayOutputStream(org.apache.ignite.internal.util.io.GridByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) ByteBuffer(java.nio.ByteBuffer)

Aggregations

ObjectOutput (java.io.ObjectOutput)105 ObjectOutputStream (java.io.ObjectOutputStream)78 ByteArrayOutputStream (java.io.ByteArrayOutputStream)64 IOException (java.io.IOException)53 ObjectInput (java.io.ObjectInput)26 Test (org.junit.Test)24 ObjectInputStream (java.io.ObjectInputStream)20 ByteArrayInputStream (java.io.ByteArrayInputStream)19 WorkingMemory (org.drools.core.WorkingMemory)13 FileOutputStream (java.io.FileOutputStream)12 RuleImpl (org.drools.core.definitions.rule.impl.RuleImpl)12 Pattern (org.drools.core.rule.Pattern)12 Consequence (org.drools.core.spi.Consequence)12 KnowledgeHelper (org.drools.core.spi.KnowledgeHelper)12 OutputStream (java.io.OutputStream)11 InternalWorkingMemory (org.drools.core.common.InternalWorkingMemory)8 Declaration (org.drools.core.rule.Declaration)8 IntrospectionException (java.beans.IntrospectionException)7 File (java.io.File)7 InvalidRuleException (org.drools.core.rule.InvalidRuleException)7