/*::.
==================================================================================================================================
=================================================¦ Copyright © 2003 Allen Baker ¦=================================================
+------------------------------+
File: NativeMethods.java
Originator: Allen Baker (2003.12.20)
LayoutRev: 5
================================================================================================================================== */
/*.
==========================================================================================
Package
------------------------------------------------------------------------------------------ */
package cosmicabyss.com.lib;
/*.
==========================================================================================
Imports
------------------------------------------------------------------------------------------ */
import java.io.*;
import java.util.*;
/*::
======================================================================================================================== *//**
Instances of this class are collections of "native" methods.
<BLOCKQUOTE>
<PRE id="unindent">
How to use this file:
=> USE DEV-C++ TO BUILD NativeMethods.dll.
-> DON'T TRY TO USE VisualStudio, YOU'LL NEVER FIGURE OUT HOW TO CONFIGURE THE NativeMethods stuff TO WORK WITH VS
This file uses JNI to call functions that are implemented in a "DLL" using the "C" programming language. The C
language implementation files and DLL files are in the directory
"\ABDITORY\programming\language\Java\NativeMethodDLLs\".
To add new "native" method signatures to this file or to modify the signatures of existing native methods in
this file:
1) Edit this file to make the changes.
2) Compile this file like any other java file in this package.
3) Use "javah" to generate a file containing the "mangled" signatures for the native methods defined in this
file. javah will write the mangled signatures into the file "cosmicabyss_com_lib_NativeMethods.h".
a) This is the command to run javah; notice that you MUST use the fully qualified name
(cosmicabyss.com.lib.NativeMethods) in oder for javah to create an output file with the correct name and
generate the correct mangled signatures.
i) javah -jni cosmicabyss.com.lib.NativeMethods
or, if the file "jni.bat" is available in this directory:
ii) jni NativeMethods
b) cosmicabyss_com_lib_NativeMethods.h is "included" (by using a "#include" preprocessor directive) in
the header file that is part of the C language implementation of the DLL. When the contents of
cosmicabyss_com_lib_NativeMethods.h are changed by running javah, the next time the DLL is rebuilt, the
new contents will be included in the DLL build.
5) Replace any modified signatures in the file
"\ABDITORY\programming\language\Java\NativeMethodDLLs\NativeMethods.c".
6) Add a new implementation in \ABDITORY\programming\language\Java\NativeMethodDLLs\NativeMethods.c for any
new signatures
7) Using the C language IDE, open the project
"\ABDITORY\programming\language\Java\NativeMethodDLLs\NativeMethods.dev" and execute "rebuild all" to
regenerate the DLL.
8) Test that things went right by running the "main" method in this file by using the command line:
a) java cosmicabyss.com.lib.NativeMethods
or, if the file "run.bat" is available in this directory:
b) run NativeMethods
</PRE>
</BLOCKQUOTE>
<P>
<DL>
<DT>
<B>
Example usage:
</B>
<DD>
<BLOCKQUOTE>
<PRE id="unindent">
=========================================================================================
copy an existing file to a new test file that the native methods can
be run against
-----------------------------------------------------------------------------------------
String fileName = "NativeMethodsTest.txt";
File srcFile = new File("tools_java_util_NativeMethods.h");
File dstFile = new File(fileName);
dstFile.delete();
dstFile.copyFrom(srcFile);
=========================================================================================
test the native methods
-----------------------------------------------------------------------------------------
NativeMethods nm = new NativeMethods();
System.out.println();
System.out.println("Times for file: " + fileName);
System.out.println();
System.out.println(" created: " + nm.getCreated (fileName));
System.out.println(" modified: " + nm.getLastModified (fileName));
System.out.println(" accessed: " + nm.getLastAccessed (fileName));
System.out.println();
nm.setCreated (fileName,2000,10,22,13,44,55,666);
nm.setLastModified (fileName,2001,11,23,14,45,56,667);
nm.setLastAccessed (fileName,2002,12,24,15,46,57,668);
System.out.println(" created: " + nm.getCreated (fileName));
System.out.println(" modified: " + nm.getLastModified (fileName));
System.out.println(" accessed: " + nm.getLastAccessed (fileName));
</PRE>
</BLOCKQUOTE>
</DD>
</DT>
<DT>
<B>
View Source:
</B>
<DD>
<A href="NativeMethods.java.html">
NativeMethods.java
</A>
</DD>
</DT>
<DT>
<B>
Author:
</B>
<DD>
<A href="mailto:sourcecode.v01@cosmicabyss.com">
Allen Baker
</A>
</DD>
</DT>
</DL>
*//*
======================================================================================================================== */
public class NativeMethods
{
/*: :METHOD:000:BOOKMARK:
====================================================================================================
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]
==================================================================================================== *//**
This method sets the created time of the file to the time represented by the year, month, day, hour,
minute, second, and millisecond specified.
<P><B>Implementation: </B><A HREF="NativeMethods.java.html#000">View source</A>
@param
FileName is the name of the file to change the time stamp on.
@param
Yyyy is the year to set the created time of the file to.
@param
MM is the month to set the created time of the file to.
@param
Dd is the day of the month to set the created time of the file to.
@param
HH is the hour in 24hr format to set the created time of the file to.
@param
Mm is the minute to set the created time of the file to.
@param
Ss is the second to set the created time of the file to.
@param
Ms is the millisecond to set the created time of the file to.
*//*
---------------------------------------------------------------------------------------------------- */
public native void setCreated
(
String fileName,
int yyyy,
int MM,
int dd,
int HH,
int mm,
int ss,
int ms
);
/*: :METHOD:001:BOOKMARK:
====================================================================================================
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]
==================================================================================================== *//**
This method sets the last modified time of the file to the time represented by the year, month, day,
hour, minute, second, and millisecond specified.
<P><B>Implementation: </B><A HREF="NativeMethods.java.html#001">View source</A>
@param
FileName is the name of the file to change the time stamp on.
@param
Yyyy is the year to set the last modified time of the file to.
@param
MM is the month to set the last modified time of the file to.
@param
Dd is the day of the month to set the last modified time of the file to.
@param
HH is the hour in 24hr format to set the last modified time of the file to.
@param
Mm is the minute to set the last modified time of the file to.
@param
Ss is the second to set the last modified time of the file to.
@param
Ms is the millisecond to set the last modified time of the file to.
*//*
---------------------------------------------------------------------------------------------------- */
public native void setLastModified
(
String fileName,
int yyyy,
int MM,
int dd,
int HH,
int mm,
int ss,
int ms
);
/*: :METHOD:002:BOOKMARK:
====================================================================================================
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]
==================================================================================================== *//**
This method sets the last accessed time of the file to the time represented by the year, month, day,
hour, minute, second, and millisecond specified.
<P><B>Implementation: </B><A HREF="NativeMethods.java.html#002">View source</A>
@param
FileName is the name of the file to change the time stamp on.
@param
Yyyy is the year to set the last accessed time of the file to.
@param
MM is the month to set the last accessed time of the file to.
@param
Dd is the day of the month to set the last accessed time of the file to.
@param
HH is the hour in 24hr format to set the last accessed time of the file to.
@param
Mm is the minute to set the last accessed time of the file to.
@param
Ss is the second to set the last accessed time of the file to.
@param
Ms is the millisecond to set the last accessed time of the file to.
*//*
---------------------------------------------------------------------------------------------------- */
public native void setLastAccessed
(
String fileName,
int yyyy,
int MM,
int dd,
int HH,
int mm,
int ss,
int ms
);
/*: :METHOD:003:BOOKMARK:
====================================================================================================
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]
==================================================================================================== *//**
This method gets the created time of the file and returns it in a String formatted like this:
Yyyy:MM:dd:HH:mm:ss:ms
Where
<BLOCKQUOTE>
<PRE id="unindent">
yyyy is the year component of the file's created time.
MM is the month component (1..12) of the file's created time.
dd is the day of the month component of the file's created time.
HH is the hour component (in 24hr format) of the file's created time.
mm is the minute component of the file's created time.
ss is the second component of the file's created time.
ms is the millisecond component of the file's created time.
</PRE>
</BLOCKQUOTE>
<P><B>Implementation: </B><A HREF="NativeMethods.java.html#003">View source</A>
@return
The date String
@param
FileName is the name of the file to get the time stamp from.
*//*
---------------------------------------------------------------------------------------------------- */
public native String getCreated(String fileName);
/*: :METHOD:004:BOOKMARK:
====================================================================================================
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]
==================================================================================================== *//**
This method gets the last modified time of the file and returns it in a String formatted like this:
Yyyy:MM:dd:HH:mm:ss:ms
Where
<BLOCKQUOTE>
<PRE id="unindent">
yyyy is the year component of the file's last modified time.
MM is the month component (1..12) of the file's last modified time.
dd is the day of the month component of the file's last modified time.
HH is the hour component (in 24hr format) of the file's last modified time.
mm is the minute component of the file's last modified time.
ss is the second component of the file's last modified time.
ms is the millisecond component of the file's last modified time.
</PRE>
</BLOCKQUOTE>
<P><B>Implementation: </B><A HREF="NativeMethods.java.html#004">View source</A>
@return
The date String
@param
FileName is the name of the file to get the time stamp from.
*//*
---------------------------------------------------------------------------------------------------- */
public native String getLastModified(String fileName);
/*: :METHOD:005:BOOKMARK:
====================================================================================================
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]
==================================================================================================== *//**
This method gets the last accessed time of the file and returns it in a String formatted like this:
Yyyy:MM:dd:HH:mm:ss:ms
Where
<BLOCKQUOTE>
<PRE id="unindent">
yyyy is the year component of the file's last accessed time.
MM is the month component (1..12) of the file's last accessed time.
dd is the day of the month component of the file's last accessed time.
HH is the hour component (in 24hr format) of the file's last accessed time.
mm is the minute component of the file's last accessed time.
ss is the second component of the file's last accessed time.
ms is the millisecond component of the file's last accessed time.
</PRE>
</BLOCKQUOTE>
<P><B>Implementation: </B><A HREF="NativeMethods.java.html#005">View source</A>
@return
The date String
@param
FileName is the name of the file to get the time stamp from.
*//*
---------------------------------------------------------------------------------------------------- */
public native String getLastAccessed(String fileName);
/*:.
==============================================================================================================
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@[ Private Class Initialization ]@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
============================================================================================================== */
static
{
System.load("C:/adb/pkg/java/NativeMethodDLLs/NativeMethods.dll");
}
/*:.
==============================================================================================================
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@[ Protected ]@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
============================================================================================================== */
/*:.
==============================================================================================================
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@[ Private ]@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
============================================================================================================== */
/*:.
==============================================================================================================
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@[ Inner Classes ]@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
============================================================================================================== */
/*:.
==============================================================================================================
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@[ Public Static Methods ]@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
============================================================================================================== */
/*: :METHOD:006:BOOKMARK:
====================================================================================================
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]
==================================================================================================== *//**
This method allows the NativeMethods class file to be unit tested as a stand-alone application. It's
the method that's called when the class is invoked from the command line by using the java
application launcher - "java". Main() is not a required method, but the practice of putting one in
each class and wrapping class test code within it allows easy unit testing of the class; and main
does not need to be removed when testing is complete.
<P>
<DL>
<DT>
<B>
Command line usage:
</B>
<DD>
Java cosmicabyss.com.lib.NativeMethods
</DD>
</DT>
</DL>
<P><B>Implementation: </B><A HREF="NativeMethods.java.html#006">View source</A>
@param
pArgs contains the command line arguments with which the class was invoked as an application.
*//*
---------------------------------------------------------------------------------------------------- */
public static void main(String[] pArgs) throws Exception
{
/*.
==========================================================================================
Copy an existing file to a new test file that the native methods can be run against
------------------------------------------------------------------------------------------ */
String fileName = "/temp/sync.log";
File srcFile = new File("tools_java_util_NativeMethods.h");
/*.
==========================================================================================
Test the native methods
------------------------------------------------------------------------------------------ */
NativeMethods nm = new NativeMethods();
System.out.println();
System.out.println("Times for file: " + fileName);
System.out.println();
System.out.println(" created: " + nm.getCreated (fileName));
System.out.println(" modified: " + nm.getLastModified (fileName));
System.out.println(" accessed: " + nm.getLastAccessed (fileName));
System.out.println();
nm.setCreated (fileName,2000,10,22,13,44,55,666);
nm.setLastModified (fileName,2001,11,23,14,45,56,667);
nm.setLastAccessed (fileName,2002,12,24,15,46,57,668);
System.out.println(" created: " + nm.getCreated (fileName));
System.out.println(" modified: " + nm.getLastModified (fileName));
System.out.println(" accessed: " + nm.getLastAccessed (fileName));
}
} // class NativeMethods