public static void sendObject(Object object, DataOutputStream output) throws IOException {
        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
        try (ObjectOutputStream serializer = new ObjectOutputStream(buffer)) {
            serializer.writeObject(object);
        }

        byte[] data = buffer.toByteArray();
        output.writeInt(data.length);
        output.write(data);
    }
Serializes the object first into an in-memory buffer and then
writes it to the output stream with a preceding size integer.

@param object object to be serialized
@param output output stream
@throws IOException if the object could not be serialized
tika-core/src/main/java/org/apache/tika/fork/ForkObjectInputStream.java