diff options
| author | Jeff Sharkey <jsharkey@android.com> | 2014-02-06 18:50:05 +0000 |
|---|---|---|
| committer | Android (Google) Code Review <android-gerrit@google.com> | 2014-02-06 18:50:05 +0000 |
| commit | 2b1252ddd2650cb38918cb85d2a3711b2cfa8db5 (patch) | |
| tree | 09c72dc2746c76dca727afcc1f86ca7698571264 /drm/java | |
| parent | d1c2c5421181b988f09fd12d9633e2a7c2a8ab60 (diff) | |
| parent | ebf8ad5d91b22eb4359c75711a5b70ddcce0723d (diff) | |
| download | frameworks_base-2b1252ddd2650cb38918cb85d2a3711b2cfa8db5.zip frameworks_base-2b1252ddd2650cb38918cb85d2a3711b2cfa8db5.tar.gz frameworks_base-2b1252ddd2650cb38918cb85d2a3711b2cfa8db5.tar.bz2 | |
Merge "Update DrmOutputStream to use raw FileDescriptor."
Diffstat (limited to 'drm/java')
| -rw-r--r-- | drm/java/android/drm/DrmOutputStream.java | 33 |
1 files changed, 22 insertions, 11 deletions
diff --git a/drm/java/android/drm/DrmOutputStream.java b/drm/java/android/drm/DrmOutputStream.java index 87677b8..22e7ac2 100644 --- a/drm/java/android/drm/DrmOutputStream.java +++ b/drm/java/android/drm/DrmOutputStream.java @@ -18,18 +18,23 @@ package android.drm; import static android.drm.DrmConvertedStatus.STATUS_OK; import static android.drm.DrmManagerClient.INVALID_SESSION; +import static libcore.io.OsConstants.SEEK_SET; +import android.os.ParcelFileDescriptor; import android.util.Log; +import libcore.io.ErrnoException; +import libcore.io.IoBridge; +import libcore.io.Libcore; +import libcore.io.Streams; + +import java.io.FileDescriptor; import java.io.FilterOutputStream; import java.io.IOException; import java.io.OutputStream; -import java.io.RandomAccessFile; import java.net.UnknownServiceException; import java.util.Arrays; -import libcore.io.Streams; - /** * Stream that applies a {@link DrmManagerClient} transformation to data before * writing to disk, similar to a {@link FilterOutputStream}. @@ -40,17 +45,19 @@ public class DrmOutputStream extends OutputStream { private static final String TAG = "DrmOutputStream"; private final DrmManagerClient mClient; - private final RandomAccessFile mFile; + private final ParcelFileDescriptor mPfd; + private final FileDescriptor mFd; private int mSessionId = INVALID_SESSION; /** - * @param file Opened with "rw" mode. + * @param pfd Opened with "rw" mode. */ - public DrmOutputStream(DrmManagerClient client, RandomAccessFile file, String mimeType) + public DrmOutputStream(DrmManagerClient client, ParcelFileDescriptor pfd, String mimeType) throws IOException { mClient = client; - mFile = file; + mPfd = pfd; + mFd = pfd.getFileDescriptor(); mSessionId = mClient.openConvertSession(mimeType); if (mSessionId == INVALID_SESSION) { @@ -61,8 +68,12 @@ public class DrmOutputStream extends OutputStream { public void finish() throws IOException { final DrmConvertedStatus status = mClient.closeConvertSession(mSessionId); if (status.statusCode == STATUS_OK) { - mFile.seek(status.offset); - mFile.write(status.convertedData); + try { + Libcore.os.lseek(mFd, status.offset, SEEK_SET); + } catch (ErrnoException e) { + e.rethrowAsIOException(); + } + IoBridge.write(mFd, status.convertedData, 0, status.convertedData.length); mSessionId = INVALID_SESSION; } else { throw new IOException("Unexpected DRM status: " + status.statusCode); @@ -75,7 +86,7 @@ public class DrmOutputStream extends OutputStream { Log.w(TAG, "Closing stream without finishing"); } - mFile.close(); + mPfd.close(); } @Override @@ -92,7 +103,7 @@ public class DrmOutputStream extends OutputStream { final DrmConvertedStatus status = mClient.convertData(mSessionId, exactBuffer); if (status.statusCode == STATUS_OK) { - mFile.write(status.convertedData); + IoBridge.write(mFd, status.convertedData, 0, status.convertedData.length); } else { throw new IOException("Unexpected DRM status: " + status.statusCode); } |
