buildframework/helium/sf/java/core/src/com/nokia/helium/core/ant/types/FileMessage.java
changeset 628 7c4a911dc066
equal deleted inserted replaced
588:c7c26511138f 628:7c4a911dc066
       
     1 /*
       
     2 * Copyright (c) 2007-2008 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  
       
    15 *
       
    16 */
       
    17 
       
    18  
       
    19 package com.nokia.helium.core.ant.types;
       
    20 
       
    21 import java.io.File;
       
    22 import com.nokia.helium.core.MessageCreationException;
       
    23 import com.nokia.helium.core.ant.Message;
       
    24 
       
    25 import org.apache.tools.ant.types.DataType;
       
    26 
       
    27 import java.io.FileNotFoundException;
       
    28 import java.io.InputStream;
       
    29 import java.io.FileInputStream;
       
    30     
       
    31 /**
       
    32  * Helper class to store the list of targets to be recorded and to be sent for diamonds.
       
    33  *
       
    34  * Example 1:
       
    35  * <pre>
       
    36  *     &lt;hlm:filemessage id="initial-message" file="${build.output.dir}/temp.xml" /&gt;
       
    37  * 
       
    38  * </pre>
       
    39  * @ant.type name="fileMessage" category="Core" 
       
    40  */
       
    41 public class FileMessage extends DataType implements Message {
       
    42     
       
    43     private File file;
       
    44     
       
    45     /**
       
    46      * Helper function set file to send as message
       
    47      * 
       
    48      * @param inputFile to be sent.
       
    49      */
       
    50     public void setFile(File inputFile) {
       
    51         file = inputFile;
       
    52     }
       
    53 
       
    54     /**
       
    55      * Helper function to the stream for the file
       
    56      * 
       
    57      * @return stream of the file content
       
    58      */
       
    59     public InputStream getInputStream() throws MessageCreationException {
       
    60         if (file == null) {
       
    61             throw new MessageCreationException("file attribute is not defined at " + this.getLocation().toString());
       
    62         }
       
    63         try {
       
    64             return  new FileInputStream(file);
       
    65         } catch (FileNotFoundException ex) { 
       
    66             throw new MessageCreationException("file Not found:" + file);
       
    67         }
       
    68     }
       
    69 
       
    70 }