Example usage for java.io RandomAccessFile getFD

List of usage examples for java.io RandomAccessFile getFD

Introduction

In this page you can find the example usage for java.io RandomAccessFile getFD.

Prototype

public final FileDescriptor getFD() throws IOException 

Source Link

Document

Returns the opaque file descriptor object associated with this stream.

Usage

From source file:org.wso2.carbon.apimgt.startup.publisher.APIManagerStartupPublisher.java

private API createAPIModel(String apiName, String apiProvider, String apiVersion, String apiEndpoint,
        String apiContext, String iconPath, String documentURL, String authType) throws APIManagementException {
    API api = null;/*  w w  w  .j av  a2  s  .  c  om*/
    RandomAccessFile randomAccessFile = null;
    FileInputStream fileInputStream = null;
    try {
        provider = APIManagerFactory.getInstance().getAPIProvider(apiProvider);
        APIIdentifier identifier = new APIIdentifier(apiProvider, apiName, apiVersion);
        api = new API(identifier);
        api.setContext(apiContext);
        api.setUrl(apiEndpoint);
        api.setUriTemplates(getURITemplates(apiEndpoint, authType));
        api.setVisibility(APIConstants.API_GLOBAL_VISIBILITY);
        api.addAvailableTiers(provider.getTiers());
        api.setEndpointSecured(false);
        api.setStatus(APIStatus.PUBLISHED);
        api.setTransports(Constants.TRANSPORT_HTTP + "," + Constants.TRANSPORT_HTTPS);

        /* Adding Icon*/
        File file;

        if (!APIStartupPublisherConstants.API_ICON_PATH_AND_DOCUMENT_URL_DEFAULT.equals(iconPath)) {
            file = new File(iconPath);
            String absolutePath = file.getAbsolutePath();
            randomAccessFile = new RandomAccessFile(absolutePath, "r");
            fileInputStream = new FileInputStream(randomAccessFile.getFD());

            ResourceFile icon = new ResourceFile(fileInputStream, getImageContentType(absolutePath));
            String thumbPath = APIUtil.getIconPath(identifier);
            String thumbnailUrl = provider.addResourceFile(thumbPath, icon);
            api.setThumbnailUrl(APIUtil.prependTenantPrefix(thumbnailUrl, apiProvider));

            /*Set permissions to anonymous role for thumbPath*/
            APIUtil.setResourcePermissions(apiProvider, null, null, thumbPath);

        }

    } catch (APIManagementException e) {
        handleException("Error while initializing API Provider", e);
    } catch (IOException e) {
        handleException("Error while reading image from icon path", e);
    } finally {

        if (randomAccessFile != null) {
            try {
                randomAccessFile.close();
            } catch (IOException ignored) {

            }
        }

        if (fileInputStream != null) {
            try {
                fileInputStream.close();
            } catch (IOException ignored) {

            }
        }
    }
    return api;
}

From source file:com.netscape.cms.logging.LogFile.java

/**
 * Open the log file. This creates the buffered FileWriter
 *
 *///from w w w .j  av  a  2s.c o  m
protected synchronized void open() throws IOException {
    RandomAccessFile out;

    try {
        out = new RandomAccessFile(mFile, "rw");
        out.seek(out.length());
        //XXX int or long?
        mBytesWritten = (int) out.length();
        if (!Utils.isNT()) {
            try {
                Utils.exec("chmod 00640 " + mFile.getCanonicalPath());
            } catch (IOException e) {
                CMS.debug("Unable to change file permissions on " + mFile.toString());
            }
        }
        mLogWriter = new BufferedWriter(new FileWriter(out.getFD()), mBufferSize);

        // The first time we open, mSignature will not have been
        // initialized yet. That's ok, we will push our first signature
        // in setupSigning().
        if (mLogSigning && (mSignature != null)) {
            try {
                pushSignature();
            } catch (ELogException le) {
                ConsoleError.send(new SystemEvent(CMS.getUserMessage("CMS_LOG_ILLEGALARGUMENT", mFileName)));
            }
        }
    } catch (IllegalArgumentException iae) {
        ConsoleError.send(new SystemEvent(CMS.getUserMessage("CMS_LOG_ILLEGALARGUMENT", mFileName)));
    } catch (GeneralSecurityException gse) {
        // error with signed audit log, shutdown CMS
        ConsoleError
                .send(new SystemEvent(CMS.getUserMessage("CMS_LOG_OPEN_FAILED", mFileName, gse.toString())));
        gse.printStackTrace();
        shutdownCMS();
    }

    mBytesUnflushed = 0;
}

From source file:com.codename1.impl.android.AndroidImplementation.java

/**
 * @inheritDoc//from  w  ww.jav  a2s.co  m
 */
public OutputStream openOutputStream(Object connection, int offset) throws IOException {
    String con = (String) connection;
    con = removeFilePrefix(con);
    RandomAccessFile rf = new RandomAccessFile(con, "rw");
    rf.seek(offset);
    FileOutputStream fc = new FileOutputStream(rf.getFD());
    BufferedOutputStream o = new BufferedOutputStream(fc, con);
    o.setConnection(rf);
    return o;
}