Coverage Report - org.apache.camel.component.file.FileProducer
 
Classes in this File Line Coverage Branch Coverage Complexity
FileProducer
0% 
0% 
0
 
 1  
 /**
 2  
  * 
 3  
  * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE
 4  
  * file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file
 5  
  * to You under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the
 6  
  * License. You may obtain a copy of the License at
 7  
  * 
 8  
  * http://www.apache.org/licenses/LICENSE-2.0
 9  
  * 
 10  
  * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
 11  
  * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
 12  
  * specific language governing permissions and limitations under the License.
 13  
  */
 14  
 
 15  
 package org.apache.camel.component.file;
 16  
 
 17  
 import java.io.File;
 18  
 import java.io.RandomAccessFile;
 19  
 import java.nio.ByteBuffer;
 20  
 import java.nio.channels.FileChannel;
 21  
 import org.apache.camel.Producer;
 22  
 import org.apache.camel.impl.DefaultProducer;
 23  
 import org.apache.commons.logging.Log;
 24  
 import org.apache.commons.logging.LogFactory;
 25  
 
 26  
 /**
 27  
  * A {@link Producer} implementation for File
 28  
  * 
 29  
  * @version $Revision: 523016 $
 30  
  */
 31  0
 public class FileProducer extends DefaultProducer<FileExchange>{
 32  0
 
 33  0
     private static final transient Log log=LogFactory.getLog(FileProducer.class);
 34  
     private final FileEndpoint endpoint;
 35  
 
 36  0
     public FileProducer(FileEndpoint endpoint){
 37  0
         super(endpoint);
 38  0
         this.endpoint=endpoint;
 39  0
     }
 40  
 
 41  
     /**
 42  
      * @param exchange
 43  
      * @see org.apache.camel.Processor#process(java.lang.Object)
 44  
      */
 45  0
     public void process(FileExchange exchange){
 46  0
         ByteBuffer payload=exchange.getIn().getBody(ByteBuffer.class);
 47  0
         payload.flip();
 48  0
         File file=null;
 49  0
         if(endpoint.getFile()!=null&&endpoint.getFile().isDirectory()){
 50  0
             file=new File(endpoint.getFile(),exchange.getFile().getName());
 51  0
         }else{
 52  0
             file=exchange.getFile();
 53  0
         }
 54  0
         try{
 55  0
             FileChannel fc=new RandomAccessFile(file,"rw").getChannel();
 56  0
             fc.position(fc.size());
 57  0
             fc.write(payload);
 58  0
             fc.close();
 59  0
         }catch(Throwable e){
 60  0
             log.error("Failed to write to File: "+file,e);
 61  0
         }
 62  0
     }
 63  
 }