Coverage Report - org.mule.module.pgp.TransformContinuouslyPolicy
 
Classes in this File Line Coverage Branch Coverage Complexity
TransformContinuouslyPolicy
0%
0/9
N/A
0
TransformContinuouslyPolicy$1
N/A
N/A
0
TransformContinuouslyPolicy$ContinuousWork
0%
0/7
0%
0/2
0
 
 1  
 /*
 2  
  * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
 3  
  * The software in this package is published under the terms of the CPAL v1.0
 4  
  * license, a copy of which has been included with this distribution in the
 5  
  * LICENSE.txt file.
 6  
  */
 7  
 package org.mule.module.pgp;
 8  
 
 9  
 import java.io.PipedOutputStream;
 10  
 
 11  
 /**
 12  
  * A {@link TransformPolicy} that copies the transformed bytes continuously into the {@link PipedOutputStream}
 13  
  * without taking into account about how many bytes the object has requested.
 14  
  */
 15  0
 public class TransformContinuouslyPolicy extends AbstractTransformPolicy
 16  
 {
 17  
 
 18  
     public static final long DEFAULT_CHUNK_SIZE = 1 << 24;
 19  
     
 20  
     private long chunkSize;
 21  
 
 22  
     public TransformContinuouslyPolicy()
 23  
     {
 24  0
         this(DEFAULT_CHUNK_SIZE);
 25  0
     }
 26  
 
 27  
     public TransformContinuouslyPolicy(long chunkSize)
 28  0
     {
 29  0
         this.chunkSize = chunkSize;
 30  0
     }
 31  
 
 32  
     /**
 33  
      * {@inheritDoc}
 34  
      */
 35  
     @Override
 36  
     public void readRequest(long length)
 37  
     {
 38  
         /**
 39  
          * Avoid calling super so that we don't add more bytes. 
 40  
          * The ContinuousWork will add the requested bytes as necessary
 41  
          * only start the copying thread
 42  
          */
 43  0
         startCopyingThread();
 44  0
     }
 45  
     
 46  
     /**
 47  
      * {@inheritDoc}
 48  
      */
 49  
     @Override
 50  
     protected Thread getCopyingThread()
 51  
     {
 52  0
         return new ContinuousWork();
 53  
     }
 54  
 
 55  0
     private class ContinuousWork extends TransformerWork
 56  
     {
 57  
         @Override
 58  
         protected void execute() throws Exception
 59  
         {
 60  0
             getTransformer().initialize(getInputStream().getOut());
 61  
             
 62  0
             boolean finishWriting = false;
 63  0
             while (!finishWriting)
 64  
             {
 65  0
                 getBytesRequested().addAndGet(chunkSize);
 66  0
                 finishWriting = getTransformer().write(getInputStream().getOut(), getBytesRequested());
 67  
             }            
 68  0
         }
 69  
     }
 70  
 }
 71  
 
 72