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);
}
}
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;
}
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();
}
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));
}
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;
}
Aggregations