Coverage Report - org.mule.transport.file.ReceiverFileInputStream
 
Classes in this File Line Coverage Branch Coverage Complexity
ReceiverFileInputStream
0%
0/17
0%
0/6
0
 
 1  
 /*
 2  
  * $Id: ReceiverFileInputStream.java 19191 2010-08-25 21:05:23Z tcarlson $
 3  
  * --------------------------------------------------------------------------------------
 4  
  * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
 5  
  *
 6  
  * The software in this package is published under the terms of the CPAL v1.0
 7  
  * license, a copy of which has been included with this distribution in the
 8  
  * LICENSE.txt file.
 9  
  */
 10  
 
 11  
 package org.mule.transport.file;
 12  
 
 13  
 import org.mule.api.DefaultMuleException;
 14  
 import org.mule.transport.file.i18n.FileMessages;
 15  
 import org.mule.util.FileUtils;
 16  
 
 17  
 import java.io.File;
 18  
 import java.io.FileInputStream;
 19  
 import java.io.FileNotFoundException;
 20  
 import java.io.IOException;
 21  
 
 22  
 /**
 23  
  * This implementation is used when streaming and will move or delete the source file
 24  
  * when the stream is closed.
 25  
  */
 26  
 class ReceiverFileInputStream extends FileInputStream
 27  
 {
 28  
     private File currentFile;
 29  
     private boolean deleteOnClose;
 30  
     private File moveToOnClose;
 31  
 
 32  
     public ReceiverFileInputStream(File currentFile, boolean deleteOnClose, File moveToOnClose)
 33  
         throws FileNotFoundException
 34  
     {
 35  0
         super(currentFile);
 36  0
         this.currentFile = currentFile;
 37  0
         this.deleteOnClose = deleteOnClose;
 38  0
         this.moveToOnClose = moveToOnClose;
 39  0
     }
 40  
 
 41  
     @Override
 42  
     public void close() throws IOException
 43  
     {
 44  0
         super.close();
 45  
 
 46  0
         if (moveToOnClose != null)
 47  
         {
 48  0
             FileUtils.moveFileWithCopyFallback(currentFile, moveToOnClose);
 49  
         }
 50  0
         else if (deleteOnClose)
 51  
         {
 52  0
             if (!currentFile.delete())
 53  
             {
 54  
                 try
 55  
                 {
 56  0
                     throw new DefaultMuleException(FileMessages.failedToDeleteFile(currentFile));
 57  
                 }
 58  0
                 catch (DefaultMuleException e)
 59  
                 {
 60  0
                     IOException e2 = new IOException();
 61  0
                     e2.initCause(e);
 62  0
                     throw e2;
 63  
                 }
 64  
             }
 65  
         }
 66  0
     }
 67  
 
 68  
     public File getCurrentFile()
 69  
     {
 70  0
         return currentFile;
 71  
     }
 72  
 }