class EncryptedSampleImpl implements Sample {

        private final Sample clearSample;
        private int index;

        private EncryptedSampleImpl(
                Sample clearSample,
                int index
                ) {

            this.clearSample = clearSample;
            this.index = index;
        }

        public void writeTo(WritableByteChannel channel) throws IOException {<FILL_FUNCTION_BODY>}

        public long getSize() {
            return clearSample.getSize();
        }

        public ByteBuffer asByteBuffer() {
            ByteBuffer sample = (ByteBuffer) ((Buffer)clearSample.asByteBuffer()).rewind();
            ByteBuffer encSample = ByteBuffer.allocate(sample.limit());

            SampleEntry se = sampleEntries.get(index);
            KeyIdKeyPair keyIdKeyPair = keys.get(index);
            CencSampleAuxiliaryDataFormat entry = auxiliaryDataFormats.get(index);
            SchemeTypeBox schm = Path.getPath((Container) se, "sinf[0]/schm[0]");
            assert schm != null;
            String encryptionAlgo = schm.getSchemeType();
            Cipher cipher = ciphers.get(encryptionAlgo);
            initCipher(cipher, entry.iv, keyIdKeyPair.getKey());
            try {
                if (entry.pairs != null) {
                    for (CencSampleAuxiliaryDataFormat.Pair pair : entry.pairs) {
                        byte[] clears = new byte[pair.clear()];
                        sample.get(clears);
                        encSample.put(clears);
                        if (pair.encrypted() > 0) {
                            byte[] toBeEncrypted = new byte[l2i(pair.encrypted())];
                            sample.get(toBeEncrypted);
                            assert (toBeEncrypted.length % 16) == 0;
                            byte[] encrypted = cipher.update(toBeEncrypted);
                            assert encrypted.length == toBeEncrypted.length;
                            encSample.put(encrypted);
                        }

                    }
                } else {

                    byte[] fullyEncryptedSample = new byte[sample.limit()];
                    sample.get(fullyEncryptedSample);
                    if ("cbc1".equals(encryptionAlgo)) {
                        int encryptedLength = fullyEncryptedSample.length / 16 * 16;
                        encSample.put(cipher.doFinal(fullyEncryptedSample, 0, encryptedLength));
                        encSample.put(fullyEncryptedSample, encryptedLength, fullyEncryptedSample.length - encryptedLength);
                    } else if ("cenc".equals(encryptionAlgo)) {
                        encSample.put(cipher.doFinal(fullyEncryptedSample));
                    }
                }
                ((Buffer)sample).rewind();
            } catch (IllegalBlockSizeException | BadPaddingException e) {
                throw new RuntimeException(e);
            }
            ((Buffer)encSample).rewind();
            return encSample;
        }

        @Override
        public SampleEntry getSampleEntry() {
            return sampleEntries.get(index);
        }
    }


            ByteBuffer sample = (ByteBuffer)((Buffer)clearSample.asByteBuffer()).rewind();
            SampleEntry se = sampleEntries.get(index);
            KeyIdKeyPair keyIdKeyPair = keys.get(index);
            CencSampleAuxiliaryDataFormat entry = auxiliaryDataFormats.get(index);
            SchemeTypeBox schm = Path.getPath((Container) se, "sinf[0]/schm[0]");
            assert schm != null;
            String encryptionAlgo = schm.getSchemeType();
            Cipher cipher = ciphers.get(encryptionAlgo);
            initCipher(cipher, entry.iv, keyIdKeyPair.getKey());
            try {
                if (entry.pairs != null && entry.pairs.length > 0) {
                    byte[] fullSample = new byte[sample.limit()];
                    sample.get(fullSample);
                    int offset = 0;

                    for (CencSampleAuxiliaryDataFormat.Pair pair : entry.pairs) {
                        offset += pair.clear();
                        if (pair.encrypted() > 0) {
                            cipher.update(fullSample,
                                    offset,
                                    l2i(pair.encrypted()),
                                    fullSample,
                                    offset);
                            offset += pair.encrypted();
                        }
                    }
                    channel.write(ByteBuffer.wrap(fullSample));
                } else {
                    byte[] fullyEncryptedSample = new byte[sample.limit()];
                    sample.get(fullyEncryptedSample);
                    if ("cbc1".equals(encryptionAlgo)) {
                        int encryptedLength = fullyEncryptedSample.length / 16 * 16;
                        channel.write(ByteBuffer.wrap(cipher.doFinal(fullyEncryptedSample, 0, encryptedLength)));
                        channel.write(ByteBuffer.wrap(fullyEncryptedSample, encryptedLength, fullyEncryptedSample.length - encryptedLength));
                    } else if ("cenc".equals(encryptionAlgo)) {
                        channel.write(ByteBuffer.wrap(cipher.doFinal(fullyEncryptedSample)));
                    }
                }
                ((Buffer)sample).rewind();
            } catch (IllegalBlockSizeException | BadPaddingException | ShortBufferException e) {
                throw new RuntimeException(e);
            }

        
<methods>public boolean add(org.mp4parser.muxer.Sample) ,public void add(int, org.mp4parser.muxer.Sample) ,public boolean addAll(int, Collection<? extends org.mp4parser.muxer.Sample>) ,public void clear() ,public boolean equals(java.lang.Object) ,public abstract org.mp4parser.muxer.Sample get(int) ,public int hashCode() ,public int indexOf(java.lang.Object) ,public Iterator<org.mp4parser.muxer.Sample> iterator() ,public int lastIndexOf(java.lang.Object) ,public ListIterator<org.mp4parser.muxer.Sample> listIterator() ,public ListIterator<org.mp4parser.muxer.Sample> listIterator(int) ,public org.mp4parser.muxer.Sample remove(int) ,public org.mp4parser.muxer.Sample set(int, org.mp4parser.muxer.Sample) ,public List<org.mp4parser.muxer.Sample> subList(int, int) <variables>protected transient int modCount