Search in sources :

Example 1 with LARGE_INTEGER

use of com.sun.jna.platform.win32.WinNT.LARGE_INTEGER in project jna by java-native-access.

the class Kernel32Test method testFileTimeFromLargeInteger.

/**
     * Test FILETIME's LARGE_INTEGER constructor
     * @throws IOException
     */
public final void testFileTimeFromLargeInteger() throws IOException {
    File tmp = File.createTempFile("testGetFileInformationByHandleEx", "jna");
    tmp.deleteOnExit();
    HANDLE hFile = Kernel32.INSTANCE.CreateFile(tmp.getAbsolutePath(), WinNT.GENERIC_WRITE, WinNT.FILE_SHARE_WRITE, new WinBase.SECURITY_ATTRIBUTES(), WinNT.OPEN_EXISTING, WinNT.FILE_ATTRIBUTE_NORMAL, null);
    assertFalse(WinBase.INVALID_HANDLE_VALUE.equals(hFile));
    try {
        Memory p = new Memory(FILE_BASIC_INFO.sizeOf());
        if (false == Kernel32.INSTANCE.GetFileInformationByHandleEx(hFile, WinBase.FileBasicInfo, p, new DWORD(p.size()))) {
            fail("GetFileInformationByHandleEx failed with " + Kernel32.INSTANCE.GetLastError());
        }
        FILE_BASIC_INFO fbi = new FILE_BASIC_INFO(p);
        FILETIME ft = new FILETIME(fbi.LastWriteTime);
        SYSTEMTIME stUTC = new SYSTEMTIME();
        SYSTEMTIME stLocal = new SYSTEMTIME();
        Kernel32.INSTANCE.FileTimeToSystemTime(ft, stUTC);
        // Covert to local
        Kernel32.INSTANCE.SystemTimeToTzSpecificLocalTime(null, stUTC, stLocal);
        FileTime calculatedCreateTime = FileTime.fromMillis(stLocal.toCalendar().getTimeInMillis());
        // Actual file's createTime
        FileTime createTime = Files.getLastModifiedTime(Paths.get(tmp.getAbsolutePath()));
        assertEquals(createTime.toMillis(), calculatedCreateTime.toMillis());
    } finally {
        Kernel32.INSTANCE.CloseHandle(hFile);
    }
}
Also used : FILETIME(com.sun.jna.platform.win32.WinBase.FILETIME) Memory(com.sun.jna.Memory) SYSTEMTIME(com.sun.jna.platform.win32.WinBase.SYSTEMTIME) DWORD(com.sun.jna.platform.win32.WinDef.DWORD) FileTime(java.nio.file.attribute.FileTime) File(java.io.File) HANDLE(com.sun.jna.platform.win32.WinNT.HANDLE) FILE_BASIC_INFO(com.sun.jna.platform.win32.WinBase.FILE_BASIC_INFO)

Example 2 with LARGE_INTEGER

use of com.sun.jna.platform.win32.WinNT.LARGE_INTEGER in project jna by java-native-access.

the class WinNTTypesTest method testLargeIntegerUnionLongValue.

@Test
public void testLargeIntegerUnionLongValue() {
    for (long expected : new long[] { Long.MIN_VALUE, Integer.MIN_VALUE, Short.MIN_VALUE, Byte.MIN_VALUE, 0L, Long.MAX_VALUE, Integer.MAX_VALUE, Short.MAX_VALUE, Byte.MAX_VALUE }) {
        LARGE_INTEGER large = new LARGE_INTEGER(expected);
        assertEquals("Mismatched large value", expected, large.getValue());
        LARGE_INTEGER.LowHigh loHi = new LARGE_INTEGER.LowHigh(expected);
        assertEquals("Mismatched low part", loHi.LowPart, large.getLow());
        assertEquals("Mismatched high part", loHi.HighPart, large.getHigh());
    }
}
Also used : LARGE_INTEGER(com.sun.jna.platform.win32.WinNT.LARGE_INTEGER) Test(org.junit.Test)

Aggregations

Memory (com.sun.jna.Memory)1 FILETIME (com.sun.jna.platform.win32.WinBase.FILETIME)1 FILE_BASIC_INFO (com.sun.jna.platform.win32.WinBase.FILE_BASIC_INFO)1 SYSTEMTIME (com.sun.jna.platform.win32.WinBase.SYSTEMTIME)1 DWORD (com.sun.jna.platform.win32.WinDef.DWORD)1 HANDLE (com.sun.jna.platform.win32.WinNT.HANDLE)1 LARGE_INTEGER (com.sun.jna.platform.win32.WinNT.LARGE_INTEGER)1 File (java.io.File)1 FileTime (java.nio.file.attribute.FileTime)1 Test (org.junit.Test)1