001/*
002 * (C) Copyright 2006-2009 Nuxeo SA (http://nuxeo.com/) and contributors.
003 *
004 * All rights reserved. This program and the accompanying materials
005 * are made available under the terms of the GNU Lesser General Public License
006 * (LGPL) version 2.1 which accompanies this distribution, and is available at
007 * http://www.gnu.org/licenses/lgpl.html
008 *
009 * This library is distributed in the hope that it will be useful,
010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012 * Lesser General Public License for more details.
013 *
014 * Contributors:
015 *     Nuxeo
016 */
017
018package org.nuxeo.ecm.platform.publisher.remoting.marshaling.io;
019
020import org.nuxeo.ecm.core.api.CoreSession;
021import org.nuxeo.ecm.core.api.DocumentModel;
022import org.nuxeo.ecm.core.io.ExportedDocument;
023import org.nuxeo.ecm.core.io.impl.ExportedDocumentImpl;
024import org.nuxeo.ecm.core.io.impl.plugins.DocumentModelReader;
025
026import java.io.IOException;
027
028/**
029 * {@link DocumentModelReader} implementation that uses inline blobs.
030 *
031 * @author tiry
032 */
033public class SingleDocumentReaderWithInLineBlobs extends DocumentModelReader {
034
035    protected DocumentModel doc;
036
037    private boolean readDone = false;
038
039    public SingleDocumentReaderWithInLineBlobs(CoreSession session, DocumentModel doc) {
040        super(session);
041        this.doc = doc;
042    }
043
044    @Override
045    public void close() {
046        super.close();
047        session = null;
048        doc = null;
049    }
050
051    @Override
052    public ExportedDocument read() throws IOException {
053        if (doc != null) {
054            if (readDone) {
055                return null;
056            } else {
057                readDone = true;
058                return new ExportedDocumentImpl(doc, true);
059            }
060        }
061        doc = null;
062        return null;
063    }
064
065}