Coverage Report - org.mule.transport.file.ReceiverFileInputStream
 
Classes in this File Line Coverage Branch Coverage Complexity
ReceiverFileInputStream
100%
17/17
100%
6/6
3
 
 1  
 /*
 2  
  * $Id: ReceiverFileInputStream.java 11549 2008-04-09 05:12:30Z dirk.olmes $
 3  
  * --------------------------------------------------------------------------------------
 4  
  * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.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  32
         super(currentFile);
 36  32
         this.currentFile = currentFile;
 37  32
         this.deleteOnClose = deleteOnClose;
 38  32
         this.moveToOnClose = moveToOnClose;
 39  32
     }
 40  
 
 41  
     public void close() throws IOException
 42  
     {
 43  58
         super.close();
 44  
 
 45  58
         if (moveToOnClose != null)
 46  
         {
 47  16
             FileUtils.moveFile(currentFile, moveToOnClose);
 48  
         }
 49  42
         else if (deleteOnClose)
 50  
         {
 51  24
             if (!currentFile.delete())
 52  
             {
 53  
                 try
 54  
                 {
 55  14
                     throw new DefaultMuleException(
 56  
                         FileMessages.failedToDeleteFile(currentFile.getAbsolutePath()));
 57  
                 }
 58  14
                 catch (DefaultMuleException e)
 59  
                 {
 60  14
                     IOException e2 = new IOException();
 61  14
                     e2.initCause(e);
 62  14
                     throw e2;
 63  
                 }
 64  
             }
 65  
         }
 66  44
     }
 67  
 
 68  
     public File getCurrentFile()
 69  
     {
 70  32
         return currentFile;
 71  
     }
 72  
 
 73  
 }