PersistenceUtils.java 1.58 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  org.slf4j.Logger
 *  org.slf4j.LoggerFactory
 */
package com.adobe.aemfd.docmanager.internal.persistence;

import com.adobe.aemfd.docmanager.io.IOUtils;
import com.adobe.aemfd.docmanager.passivation.PassivationConnection;
import com.adobe.aemfd.docmanager.source.DocumentSourceHandler;
import com.adobe.aemfd.docmanager.source.FileSourceHandler;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public abstract class PersistenceUtils {
    private static final Logger logger = LoggerFactory.getLogger(PersistenceUtils.class);

    /*
     * WARNING - Removed try catching itself - possible behaviour change.
     */
    public static DocumentSourceHandler passivatePersistently(byte[] preBuffer, PassivationConnection conn) throws IOException {
        File tmp = IOUtils.createTempFile(null);
        FileOutputStream fos = new FileOutputStream(tmp);
        try {
            if (preBuffer != null) {
                IOUtils.copy(new ByteArrayInputStream(preBuffer), fos);
            }
            IOUtils.copy(conn.getContentStream(), fos);
        }
        finally {
            try {
                fos.close();
            }
            catch (IOException e) {
                logger.warn("Error closing output stream for file " + tmp.getAbsolutePath(), (Throwable)e);
            }
        }
        return new FileSourceHandler(tmp, conn.getContentType(), true);
    }
}