Example usage for android.os ParcelFileDescriptor MODE_CREATE

List of usage examples for android.os ParcelFileDescriptor MODE_CREATE

Introduction

In this page you can find the example usage for android.os ParcelFileDescriptor MODE_CREATE.

Prototype

int MODE_CREATE

To view the source code for android.os ParcelFileDescriptor MODE_CREATE.

Click Source Link

Document

For use with #open : create the file if it doesn't already exist.

Usage

From source file:com.hippo.content.FileProvider.java

/**
 * Copied from ContentResolver.java//from  w  w  w  .  ja  va 2  s .  c o  m
 */
private static int modeToMode(String mode) {
    int modeBits;
    if ("r".equals(mode)) {
        modeBits = ParcelFileDescriptor.MODE_READ_ONLY;
    } else if ("w".equals(mode) || "wt".equals(mode)) {
        modeBits = ParcelFileDescriptor.MODE_WRITE_ONLY | ParcelFileDescriptor.MODE_CREATE
                | ParcelFileDescriptor.MODE_TRUNCATE;
    } else if ("wa".equals(mode)) {
        modeBits = ParcelFileDescriptor.MODE_WRITE_ONLY | ParcelFileDescriptor.MODE_CREATE
                | ParcelFileDescriptor.MODE_APPEND;
    } else if ("rw".equals(mode)) {
        modeBits = ParcelFileDescriptor.MODE_READ_WRITE | ParcelFileDescriptor.MODE_CREATE;
    } else if ("rwt".equals(mode)) {
        modeBits = ParcelFileDescriptor.MODE_READ_WRITE | ParcelFileDescriptor.MODE_CREATE
                | ParcelFileDescriptor.MODE_TRUNCATE;
    } else {
        throw new IllegalArgumentException("Invalid mode: " + mode);
    }
    return modeBits;
}

From source file:com.ardnezar.lookapp.PeerConnectionClient.java

private void createPeerConnectionInternal(EglBase.Context renderEGLContext,
        List<PeerConnection.IceServer> list) {
    if (factory == null || isError) {
        Log.e(TAG, "Peerconnection factory is not created");
        return;/*from  ww w .  j ava 2 s.c  o m*/
    }
    Log.d(TAG, "Create peer connection.");

    //      Log.d(TAG, "PCConstraints: " + pcConstraints.toString());
    if (videoConstraints != null) {
        Log.d(TAG, "VideoConstraints: " + videoConstraints.toString());
    }
    queuedRemoteCandidates = new LinkedList<IceCandidate>();

    if (videoCallEnabled) {
        Log.d(TAG, "EGLContext: " + renderEGLContext);
        factory.setVideoHwAccelerationOptions(renderEGLContext, renderEGLContext);
    }

    PeerConnection.RTCConfiguration rtcConfig = null;
    if (list != null) {
        rtcConfig = new PeerConnection.RTCConfiguration(list);
    } else {
        rtcConfig = new PeerConnection.RTCConfiguration(signalingParameters.iceServers);
    }
    // TCP candidates are only useful when connecting to a server that supports
    // ICE-TCP.
    rtcConfig.tcpCandidatePolicy = PeerConnection.TcpCandidatePolicy.DISABLED;
    rtcConfig.bundlePolicy = PeerConnection.BundlePolicy.MAXBUNDLE;
    rtcConfig.rtcpMuxPolicy = PeerConnection.RtcpMuxPolicy.REQUIRE;
    // Use ECDSA encryption.
    rtcConfig.keyType = PeerConnection.KeyType.ECDSA;

    //      peerConnection = factory.createPeerConnection(
    //            rtcConfig, pcConstraints, pcObserver);
    isInitiator = false;

    // Set default WebRTC tracing and INFO libjingle logging.
    // NOTE: this _must_ happen while |factory| is alive!
    Logging.enableTracing("logcat:", EnumSet.of(Logging.TraceLevel.TRACE_DEFAULT), Logging.Severity.LS_INFO);

    mediaStream = factory.createLocalMediaStream("ARDAMS");
    if (videoCallEnabled) {
        String cameraDeviceName = CameraEnumerationAndroid.getDeviceName(0);
        String frontCameraDeviceName = CameraEnumerationAndroid.getNameOfFrontFacingDevice();
        if (numberOfCameras > 1 && frontCameraDeviceName != null) {
            cameraDeviceName = frontCameraDeviceName;
        }
        Log.d(TAG, "Opening camera: " + cameraDeviceName);
        videoCapturer = VideoCapturerAndroid.create(cameraDeviceName, null,
                peerConnectionParameters.captureToTexture ? renderEGLContext : null);
        if (videoCapturer == null) {
            reportError("Failed to open camera");
            return;
        }
        mediaStream.addTrack(createVideoTrack(videoCapturer));
    }

    mediaStream.addTrack(factory.createAudioTrack(AUDIO_TRACK_ID, factory.createAudioSource(audioConstraints)));
    peerConnection.addStream(mediaStream);

    if (peerConnectionParameters.aecDump) {
        try {
            aecDumpFileDescriptor = ParcelFileDescriptor.open(new File("/sdcard/Download/audio.aecdump"),
                    ParcelFileDescriptor.MODE_READ_WRITE | ParcelFileDescriptor.MODE_CREATE
                            | ParcelFileDescriptor.MODE_TRUNCATE);
            factory.startAecDump(aecDumpFileDescriptor.getFd());
        } catch (IOException e) {
            Log.e(TAG, "Can not open aecdump file", e);
        }
    }

    Log.d(TAG, "Peer connection created.");
}

From source file:com.almalence.plugins.capture.video.VideoCapturePlugin.java

/**
 * Appends mp4 audio/video from {@code anotherFileName} to
 * {@code mainFileName}.// ww  w  .j av a2  s  . co  m
 */
public static File append(File[] inputFiles) {
    try {
        File targetFile = inputFiles[0];
        int[] inputFilesFds = new int[inputFiles.length];
        ArrayList<ParcelFileDescriptor> pfdsList = new ArrayList<ParcelFileDescriptor>();

        int i = 0;
        for (File f : inputFiles) {
            ParcelFileDescriptor pfd = ParcelFileDescriptor.open(f, ParcelFileDescriptor.MODE_READ_WRITE);
            pfdsList.add(pfd);
            inputFilesFds[i] = pfd.getFd();
            i++;
        }

        if (targetFile.exists() && targetFile.length() > 0) {
            File tmpTargetFile = new File(targetFile.getAbsolutePath() + ".tmp");

            ParcelFileDescriptor targetFilePfd = ParcelFileDescriptor.open(tmpTargetFile,
                    ParcelFileDescriptor.MODE_CREATE | ParcelFileDescriptor.MODE_READ_WRITE);

            Mp4Editor.appendFds(inputFilesFds, targetFilePfd.getFd());

            targetFilePfd.close();
            for (ParcelFileDescriptor pfd : pfdsList) {
                pfd.close();
            }

            return tmpTargetFile;
        } else if (targetFile.createNewFile()) {
            copyFile(inputFiles[1].getAbsolutePath(), inputFiles[0].getAbsolutePath());
            return targetFile;
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}