001: /*
002: * BEGIN_HEADER - DO NOT EDIT
003: *
004: * The contents of this file are subject to the terms
005: * of the Common Development and Distribution License
006: * (the "License"). You may not use this file except
007: * in compliance with the License.
008: *
009: * You can obtain a copy of the license at
010: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
011: * See the License for the specific language governing
012: * permissions and limitations under the License.
013: *
014: * When distributing Covered Code, include this CDDL
015: * HEADER in each file and include the License file at
016: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
017: * If applicable add the following below this CDDL HEADER,
018: * with the fields enclosed by brackets "[]" replaced with
019: * your own identifying information: Portions Copyright
020: * [year] [name of copyright owner]
021: */
022:
023: /*
024: * @(#)InstallerUtilities.java
025: * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
026: *
027: * END_HEADER - DO NOT EDIT
028: */
029: package com.sun.jbi.installer;
030:
031: import java.io.File;
032: import java.io.FileOutputStream;
033: import java.io.FileInputStream;
034: import java.io.FileWriter;
035: import java.io.FileReader;
036: import java.io.InputStream;
037: import java.io.OutputStream;
038: import java.util.Properties;
039: import java.util.ResourceBundle;
040:
041: /**
042: * This class has utility methods
043: */
044: public class InstallerUtilities {
045:
046: /**
047: * This method is used to write to log file
048: * @param logFile, the log File
049: * @param append, the contents are appended to the file if true
050: * @param inputString, contents to be written to the log file
051: */
052: public static void writeToLogFile(File logFile, boolean append,
053: String inputString) {
054: try {
055: FileWriter logWriter = new FileWriter(logFile, append);
056: logWriter.write(inputString);
057: logWriter.flush();
058: logWriter.close();
059: } catch (Exception e) {
060:
061: }
062: }
063:
064: /**
065: * This method is used to copy a file
066: */
067: public static void copyFile(File sourceFile, File destinationFile)
068: throws Exception {
069:
070: InputStream in = new FileInputStream(sourceFile);
071: OutputStream out = new FileOutputStream(destinationFile);
072:
073: byte[] buf = new byte[1024];
074: int len;
075: while ((len = in.read(buf)) > 0) {
076: out.write(buf, 0, len);
077: }
078: in.close();
079: out.close();
080: }
081:
082: /**
083: * This method is used to read a property from a property file.
084: */
085:
086: public static String getProperty(File propertyFile, String property) {
087:
088: try {
089: InputStream inputStream = new FileInputStream(propertyFile);
090: Properties props = new Properties();
091: props.load(inputStream);
092: return props.getProperty(property);
093: } catch (Exception e) {
094: return null;
095: }
096:
097: }
098:
099: /**
100: * This method is used to write a property to a property file
101: */
102:
103: /* public static void setProperty(File propertyFile, String property, String value){
104:
105: try {
106:
107: Properties props = new Properties();
108: props.setProperty(property, value);
109: String comment = ResourceBundle.getBundle(InstallConstants.RESOURCE_BUNDLE).getString("comment-property-file");
110:
111: props.store(new FileOutputStream(propertyFile),comment );
112: } catch (Exception e){
113: }
114: } */
115: }
|