Example usage for android.os ParcelFileDescriptor MODE_TRUNCATE

List of usage examples for android.os ParcelFileDescriptor MODE_TRUNCATE

Introduction

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

Prototype

int MODE_TRUNCATE

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

Click Source Link

Document

For use with #open : erase contents of file when opening.

Usage

From source file:org.getlantern.firetweet.provider.FiretweetDataProvider.java

@Override
public ParcelFileDescriptor openFile(final Uri uri, final String mode) throws FileNotFoundException {
    if (uri == null || mode == null)
        throw new IllegalArgumentException();
    final int table_id = getTableId(uri);
    final String table = getTableNameById(table_id);
    final int mode_code;
    if ("r".equals(mode)) {
        mode_code = ParcelFileDescriptor.MODE_READ_ONLY;
    } else if ("rw".equals(mode)) {
        mode_code = ParcelFileDescriptor.MODE_READ_WRITE;
    } else if ("rwt".equals(mode)) {
        mode_code = ParcelFileDescriptor.MODE_READ_WRITE | ParcelFileDescriptor.MODE_TRUNCATE;
    } else/* w ww. ja v  a  2s  .  c o m*/
        throw new IllegalArgumentException();
    if (mode_code == ParcelFileDescriptor.MODE_READ_ONLY) {
        checkReadPermission(table_id, table, null);
    } else if ((mode_code & ParcelFileDescriptor.MODE_READ_WRITE) != 0) {
        checkReadPermission(table_id, table, null);
        checkWritePermission(table_id, table);
    }
    switch (table_id) {
    case VIRTUAL_TABLE_ID_CACHED_IMAGES: {
        return getCachedImageFd(uri.getQueryParameter(QUERY_PARAM_URL));
    }
    case VIRTUAL_TABLE_ID_CACHE_FILES: {
        return getCacheFileFd(uri.getLastPathSegment());
    }
    }
    return null;
}

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

/**
 * Copied from ContentResolver.java/* w ww  . j  av  a2  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;/* ww w.  j a va 2  s.  com*/
    }
    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.");
}