FileDataBufferImpl.java 2.58 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  org.slf4j.Logger
 *  org.slf4j.LoggerFactory
 */
package com.adobe.aemds.datamanager.impl;

import com.adobe.CORBA.ServantBase;
import com.adobe.aemds.datamanager.impl.DataManagerManagedConnection;
import com.adobe.service.DataManager;
import com.adobe.service.FileDataBufferOperations;
import java.io.File;
import java.io.RandomAccessFile;
import org.omg.CORBA.BAD_INV_ORDER;
import org.omg.CORBA.UNKNOWN;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class FileDataBufferImpl
extends ServantBase
implements FileDataBufferOperations {
    private static final Logger logger = LoggerFactory.getLogger(DataManager.class);
    private String contentType = "unknown";
    private final String filePath;

    FileDataBufferImpl(String filePath, DataManagerManagedConnection resource) {
        this.filePath = filePath;
        resource.connect(this);
    }

    public String getFilePath() {
        return this.filePath;
    }

    public long getBufLength() {
        return new File(this.filePath).length();
    }

    public byte[] getBytes(long pos, long nBytes) {
        byte[] data;
        int count = (int)nBytes;
        if (count <= 0) {
            logger.error("Invalid arg nBytes for getBytes: {}", (Object)nBytes);
            throw new UNKNOWN("Invalid arg nBytes for getBytes: " + nBytes);
        }
        try {
            data = new byte[count];
        }
        catch (OutOfMemoryError e) {
            logger.error("Out of memory exception in getBytes for size: " + count, (Throwable)e);
            throw new UNKNOWN("Out of memory exception in getBytes for size: " + count);
        }
        try {
            RandomAccessFile inFile = new RandomAccessFile(this.filePath, "r");
            inFile.seek(pos);
            inFile.readFully(data);
            inFile.close();
        }
        catch (Exception e) {
            logger.error("Exception while performing operation on file:" + e.toString(), (Throwable)e);
            throw new UNKNOWN("Exception while performing operation on file:" + e.toString());
        }
        return data;
    }

    public String getContentType() {
        return this.contentType;
    }

    public void setContentType(String contentType) {
        if (this.contentType.equals("unknown")) {
            if (contentType != null) {
                this.contentType = contentType;
            }
        } else {
            logger.debug("Content type already set: {}", (Object)this.contentType);
            throw new BAD_INV_ORDER("Content type already set");
        }
    }
}