FileDocCategorySizeDatePackage
DrmOutputStream.javaAPI DocAndroid 5.1 API3784Thu Mar 12 22:22:30 GMT 2015android.drm

DrmOutputStream

public class DrmOutputStream extends OutputStream
Stream that applies a {@link DrmManagerClient} transformation to data before writing to disk, similar to a {@link FilterOutputStream}.
hide

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)

param
pfd Opened with "rw" mode.


               
          
              
        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 voidclose()

        if (mSessionId == INVALID_SESSION) {
            Log.w(TAG, "Closing stream without finishing");
        }

        mPfd.close();
    
public voidfinish()

        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 voidwrite(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 voidwrite(int oneByte)

        Streams.writeSingleByte(this, oneByte);