/*
 * Copyright (c) 2004-2017, by Alex Leigh.
 * All rights reserved.
 *
 * THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE
 * The copyright notice above does not evidence any
 * actual or intended publication of such source code.
 */

package lc.mecha.lang;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.io.ObjectInputStream;

/**
 * Created with IntelliJ IDEA.
 * User: aleigh
 * Date: 8/26/14
 * Time: 12:34 PM
 * To change this template use File | Settings | File Templates.
 */
public final class ObjectStreamUtil {
    private static final Logger logger = LoggerFactory.getLogger(ObjectStreamUtil.class);

    /**
     * Drain all the objects in the stream and simply log them to the output.
     *
     * @param ois
     * @throws java.io.IOException
     * @throws ClassNotFoundException
     */
    public static void drainResult(final ObjectInputStream ois) throws IOException, ClassNotFoundException {
        Object o;

        while ((o = ois.readObject()) != null) {
            logger.info("Read: {}", o);
        }
    }

    public static void silentDrain(final ObjectInputStream ois) throws IOException, ClassNotFoundException {
        while (ois.readObject() != null) {
            // Intentionally Blank
        }

    }
}
