private Throwable waitForResponse(List<ForkResource> resources) throws IOException {
        output.flush();
        while (!Thread.currentThread().isInterrupted()) {
            int type = input.read();
            if (type == -1) {
                throw new IOException("Lost connection to a forked server process");
            } else if (type == ForkServer.RESOURCE) {
                ForkResource resource = resources.get(input.readUnsignedByte());
                resource.process(input, output);
            } else if ((byte) type == ForkServer.ERROR) {
                try {
                    return (Throwable) ForkObjectInputStream.readObject(input, loader);
                } catch (ClassNotFoundException e) {
                    throw new IOException("Unable to deserialize an exception", e);
                }
            } else {
                return null;
            }
        }
        throw new IOException(new InterruptedException());
    }
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 resources list of fork resources, used when adding proxies
@throws IOException if the object could not be serialized
tika-core/src/main/java/org/apache/tika/fork/ForkClient.java