core/com.nokia.carbide.sdt.utils/src/com/nokia/sdt/utils/StandaloneFileTracker.java
author fturovic <frank.turovich@nokia.com>
Thu, 02 Apr 2009 15:23:07 -0500
branchRCL_2_0
changeset 25 1f39fea73e7e
parent 2 d760517a8095
permissions -rw-r--r--
updated splash for 2.0.4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
cawthron
parents:
diff changeset
     1
/*
cawthron
parents:
diff changeset
     2
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
cawthron
parents:
diff changeset
     3
* All rights reserved.
cawthron
parents:
diff changeset
     4
* This component and the accompanying materials are made available
cawthron
parents:
diff changeset
     5
* under the terms of the License "Eclipse Public License v1.0"
cawthron
parents:
diff changeset
     6
* which accompanies this distribution, and is available
cawthron
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
cawthron
parents:
diff changeset
     8
*
cawthron
parents:
diff changeset
     9
* Initial Contributors:
cawthron
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
cawthron
parents:
diff changeset
    11
*
cawthron
parents:
diff changeset
    12
* Contributors:
cawthron
parents:
diff changeset
    13
*
cawthron
parents:
diff changeset
    14
* Description: 
cawthron
parents:
diff changeset
    15
*
cawthron
parents:
diff changeset
    16
*/
cawthron
parents:
diff changeset
    17
package com.nokia.sdt.utils;
cawthron
parents:
diff changeset
    18
cawthron
parents:
diff changeset
    19
import org.eclipse.core.runtime.CoreException;
cawthron
parents:
diff changeset
    20
cawthron
parents:
diff changeset
    21
import com.nokia.cpp.internal.api.utils.core.FileUtils;
cawthron
parents:
diff changeset
    22
import com.nokia.cpp.internal.api.utils.core.Logging;
cawthron
parents:
diff changeset
    23
cawthron
parents:
diff changeset
    24
import java.io.*;
cawthron
parents:
diff changeset
    25
cawthron
parents:
diff changeset
    26
public class StandaloneFileTracker implements IFileTracker {
cawthron
parents:
diff changeset
    27
cawthron
parents:
diff changeset
    28
    /**
cawthron
parents:
diff changeset
    29
     * 
cawthron
parents:
diff changeset
    30
     */
cawthron
parents:
diff changeset
    31
    public StandaloneFileTracker() {
cawthron
parents:
diff changeset
    32
    }
cawthron
parents:
diff changeset
    33
cawthron
parents:
diff changeset
    34
    /* (non-Javadoc)
cawthron
parents:
diff changeset
    35
     * @see com.nokia.sdt.sourcegen.IFileTracker#loadFileText(org.eclipse.core.runtime.IPath)
cawthron
parents:
diff changeset
    36
     */
cawthron
parents:
diff changeset
    37
    public char[] loadFileText(File file) throws CoreException {
cawthron
parents:
diff changeset
    38
    	return FileUtils.readFileContents(file, "UTF-8");
cawthron
parents:
diff changeset
    39
    }
cawthron
parents:
diff changeset
    40
cawthron
parents:
diff changeset
    41
    /* (non-Javadoc)
cawthron
parents:
diff changeset
    42
     * @see com.nokia.sdt.sourcegen.IFileTracker#saveFileText(org.eclipse.core.runtime.IPath, char[])
cawthron
parents:
diff changeset
    43
     */
cawthron
parents:
diff changeset
    44
    public void saveFileText(File file, String charSet, char[] text) throws CoreException {
cawthron
parents:
diff changeset
    45
        try {
cawthron
parents:
diff changeset
    46
            Writer writer;
cawthron
parents:
diff changeset
    47
            if (charSet != null)
cawthron
parents:
diff changeset
    48
            	writer = new OutputStreamWriter(
cawthron
parents:
diff changeset
    49
                    new FileOutputStream(file), charSet);
cawthron
parents:
diff changeset
    50
            else
cawthron
parents:
diff changeset
    51
            	writer = new OutputStreamWriter(
cawthron
parents:
diff changeset
    52
            		new FileOutputStream(file));
cawthron
parents:
diff changeset
    53
            writer.write(text);
cawthron
parents:
diff changeset
    54
            writer.close();                
cawthron
parents:
diff changeset
    55
        } catch (UnsupportedEncodingException e) {
cawthron
parents:
diff changeset
    56
            throw new CoreException(Logging.newStatus(UtilsPlugin.getDefault(), e));
cawthron
parents:
diff changeset
    57
        } catch (IOException e) {
cawthron
parents:
diff changeset
    58
            throw new CoreException(Logging.newStatus(UtilsPlugin.getDefault(), e));
cawthron
parents:
diff changeset
    59
        }
cawthron
parents:
diff changeset
    60
    }
cawthron
parents:
diff changeset
    61
cawthron
parents:
diff changeset
    62
    /* (non-Javadoc)
cawthron
parents:
diff changeset
    63
     * @see com.nokia.sdt.utils.IFileSaver#touchFile(java.io.File)
cawthron
parents:
diff changeset
    64
     */
cawthron
parents:
diff changeset
    65
    public void touchFile(File file) throws CoreException {
cawthron
parents:
diff changeset
    66
    	if (file.exists())
cawthron
parents:
diff changeset
    67
    		file.setLastModified(System.currentTimeMillis());
cawthron
parents:
diff changeset
    68
    }
cawthron
parents:
diff changeset
    69
    
cawthron
parents:
diff changeset
    70
    /* (non-Javadoc)
cawthron
parents:
diff changeset
    71
     * @see com.nokia.sdt.utils.IFileSaver#fileExists(java.io.File)
cawthron
parents:
diff changeset
    72
     */
cawthron
parents:
diff changeset
    73
    public boolean fileExists(File file) {
cawthron
parents:
diff changeset
    74
    	return file.exists();
cawthron
parents:
diff changeset
    75
    }
cawthron
parents:
diff changeset
    76
    
cawthron
parents:
diff changeset
    77
    /* (non-Javadoc)
cawthron
parents:
diff changeset
    78
     * @see com.nokia.sdt.utils.IFileLoader#getModificationTime(java.io.File)
cawthron
parents:
diff changeset
    79
     */
cawthron
parents:
diff changeset
    80
    public long getModificationTime(File file) {
cawthron
parents:
diff changeset
    81
    	return file.lastModified();
cawthron
parents:
diff changeset
    82
    }
cawthron
parents:
diff changeset
    83
}