All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.pyx4j.jni.FileUtil Maven / Gradle / Ivy

/*
 * Pyx4j framework
 * Copyright (C) 2006 pyx4.com.
 *
 * @author vlads
 * @version $Id: FileUtil.java 31 2007-03-14 05:55:16Z vlads $
 * 
 * Created on 03.02.2005 by vlads
 */
package com.pyx4j.jni;

import java.io.File;
import java.util.Calendar;
import java.util.GregorianCalendar;

/**
 * Access and modify file creation time on windows.
 */
public class FileUtil {

    static {
        Common.isAvailable();
    }
    
    public static int setFileCreationTime(String fileName, long msec) {
        if (Common.isAvailable()) {
            Calendar c = new GregorianCalendar();
            c.setTimeInMillis(msec);
            int dls = c.get(Calendar.DST_OFFSET);
            if (dls != 0) {
                msec += dls; 
            }
            return setFileCreationTimeStamp(fileName, msec);
        } else {
            return 1;
        }
    }
    
    public static long getFileCreationTime(String fileName) {
		long ts;
		if (Common.isAvailable()) {
			ts = getFileCreationTimeStamp(fileName);
			if (ts == -1) {
				ts = new File(fileName).lastModified();
			}
		} else {
			ts = new File(fileName).lastModified();
		}
		if (Common.isWindows()) {
			Calendar c = new GregorianCalendar();
			c.setTimeInMillis(ts);
			// daylight saving.
			int dls = c.get(Calendar.DST_OFFSET);
			if (dls == 0) {
				return ts;
			}
			return ts - dls;
		} else {
			return ts;
		}
	}
    
    public static int getLastSystemError() {
        if (!Common.isAvailable()) {
            return 0;
        } else {
            return getLastError();
        }
    }
    
    public static native long getFileCreationTimeStamp(String fileName);
    
    public static native int setFileCreationTimeStamp(String fileName, long sec);
    
    public static native int getLastError();
    
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy