DrmOutputStreampublic class DrmOutputStream extends OutputStream Stream that applies a {@link DrmManagerClient} transformation to data before
writing to disk, similar to a {@link FilterOutputStream}. |
Fields Summary |
---|
private static final String | TAG | private final DrmManagerClient | mClient | private final android.os.ParcelFileDescriptor | mPfd | private final FileDescriptor | mFd | private int | mSessionId |
Constructors Summary |
---|
public DrmOutputStream(DrmManagerClient client, android.os.ParcelFileDescriptor pfd, String mimeType)
mClient = client;
mPfd = pfd;
mFd = pfd.getFileDescriptor();
mSessionId = mClient.openConvertSession(mimeType);
if (mSessionId == INVALID_SESSION) {
throw new UnknownServiceException("Failed to open DRM session for " + mimeType);
}
|
Methods Summary |
---|
public void | close()
if (mSessionId == INVALID_SESSION) {
Log.w(TAG, "Closing stream without finishing");
}
mPfd.close();
| public void | finish()
final DrmConvertedStatus status = mClient.closeConvertSession(mSessionId);
if (status.statusCode == STATUS_OK) {
try {
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);
}
| public void | write(byte[] buffer, int offset, int count)
Arrays.checkOffsetAndCount(buffer.length, offset, count);
final byte[] exactBuffer;
if (count == buffer.length) {
exactBuffer = buffer;
} else {
exactBuffer = new byte[count];
System.arraycopy(buffer, offset, exactBuffer, 0, count);
}
final DrmConvertedStatus status = mClient.convertData(mSessionId, exactBuffer);
if (status.statusCode == STATUS_OK) {
IoBridge.write(mFd, status.convertedData, 0, status.convertedData.length);
} else {
throw new IOException("Unexpected DRM status: " + status.statusCode);
}
| public void | write(int oneByte)
Streams.writeSingleByte(this, oneByte);
|
|