/*******************************************************************************
 * Copyright (c) 2012 Symplectic Ltd. All rights reserved.
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 ******************************************************************************/
package uk.co.symplectic.vivoweb.harvester.store;

import uk.co.symplectic.elements.api.ElementsObjectCategory;
import uk.co.symplectic.vivoweb.harvester.fetch.model.ElementsObjectInfo;
import uk.co.symplectic.vivoweb.harvester.fetch.model.ElementsObjectInfoCache;
import uk.co.symplectic.xml.StAXUtils;
import uk.co.symplectic.xml.XMLStreamProcessor;

import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;

public class ElementsStoredObject {
    private File file;
    private ElementsObjectCategory category;
    private String id;

    private ElementsObjectInfo objectInfo = null;

    ElementsStoredObject(File file, ElementsObjectCategory category, String id) {
        this.file = file;
        this.category = category;
        this.id = id;
    }

    ElementsStoredObject(File file, ElementsObjectCategory category, String id, ElementsObjectInfo objectInfo) {
        this.file = file;
        this.category = category;
        this.id = id;
        this.objectInfo = objectInfo;
    }

    public ElementsObjectInfo getObjectInfo() {
        if (objectInfo == null) {
            parseObjectInfo();
        }

        return objectInfo;
    }

    public File getFile() {
        return file;
    }

    public ElementsObjectCategory getCategory() {
        return category;
    }

    public String getId() {
        return id;
    }

    private synchronized void parseObjectInfo() {
        if (objectInfo == null) {
            objectInfo = ElementsObjectInfoCache.get(category, id);

            if (objectInfo == null && file != null && file.exists()) {
                InputStream inputStream = null;
                try {
                    inputStream = new BufferedInputStream(new FileInputStream(file));

                    XMLInputFactory xmlInputFactory = StAXUtils.getXMLInputFactory();
                    XMLStreamReader xmlReader = xmlInputFactory.createXMLStreamReader(inputStream);

                    ElementsObjectInfoObserver observer = new ElementsObjectInfoObserver();
                    XMLStreamProcessor processor = new XMLStreamProcessor();

                    processor.process(xmlReader, observer);

                    objectInfo = observer.getObjectInfo();
                    ElementsObjectInfoCache.put(objectInfo);
                } catch (FileNotFoundException fileNotFoundException) {
                } catch (XMLStreamException xmlStreamException) {
                } finally {
                    if (inputStream != null) {
                        try { inputStream.close(); } catch (IOException e) {}
                    }
                }
            }
        }
    }
}

@@ -3153,32 +3153,157 @@
 amException) %7B%0D%0A
+                    throw new IllegalStateException(%22Catastrophic failure reading files - abandoning%22, xmlStreamException);%0D%0A
                 

Make catastrophic file reading problem throw a runtime Exception (happy to swallow file not found)