Copyright (c) 1998 Sun Microsystems, Inc. All Rights Reserved.
Sun grants you ("Licensee") a non-exclusive, royalty free, license to use,
modify and redistribute this software in source and binary code form,
provided that i) this copyright notice and license appear on all copies of
the software; and ii) Licensee does not utilize the software in a manner
which is disparaging to Sun.
This software is provided "AS IS," without a warranty of any kind. ALL
EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY
IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE
LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS
LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,
INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF
OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
This software is not designed or intended for use in on-line control of
aircraft, air traffic, aircraft navigation or aircraft communications; or in
the design, construction, operation or maintenance of any nuclear
facility. Licensee represents and warrants that it will not use or
redistribute the Software for such purposes.
/*
* @(#)Main.java 1.5 98/03/22
*
* Copyright (c) 1998 Sun Microsystems, Inc. All Rights Reserved.
*
* See also the LICENSE file in this distribution.
*/
/**
* Provides amain()
method for running the shared stubs example.
* Shared stubs allow you to call native code (such as the standard C
* library'sprintf
function) from Java code, with very little
* work.
*
* This class uses our prototype implementation of the shared stubs
* distributed with this example.
*
* @author Sheng Liang
* @see CFunc
* @see CPtr
* @see CMalloc
*/
public class Main {
/**
* Demonstrates callingprintf
,scanf
, etc from
* the C library using shared stubs.
*
* Note that this is an example demonstrating the use of shared stubs, and
* must not be construed as us encouraging the use ofprintf
* from Java code! Infact, we strongly discourage you from doing so ---
* the Java platform APIs provide powerful, type-safe and portable
* alternatives for these C functions, and the Java versions will be a
* performance win. We hope that shared stubs will be useful to you if
* you absolutely must write native methods.
*
* Output from C's printf is enclosed in <>, to distinguish it from things
* we print with System.out.println.
*
* @param main_args Arguments passed from the command line. Currently
* unused.
*/
public static void main(String[] main_args) {
/* Which OS are we running on? */
String osName = System.getProperty("os.name");
String libc, libm;
/* JDK1.1 returns "Solaris", 1.2 returns "SunOS". */
if (osName.equals("SunOS") || osName.equals("Solaris")) {
libc = "libc.so";
libm = "libm.so";
} else {
libc = libm = "msvcrt.dll"; // Win32
}
/* Printing a message with printf(). Note that we first create an
instance of CFunc that wraps around C's printf(). Then we do the
actual call, dispatching to one of the "callXXX" methods on this
instance, based on the return type; in this case it happens to be
callInt. Arguments to the C function are passed as an array of
Objects. Notice we use the "anonymous array creation" syntax for
creating the array of arguments. */
CFunc printf = new CFunc(libc, "printf");
int ires = printf.callInt(new Object[]
{"\n
feedme java project
is free software, licensed under the terms of the GNU General Public License, that feeds/imports media from anywhere to xbox360 media center extenders, ipods, web servers, file servers, etc. using Java.
Please read the license here.
Please read the license here.
Thursday, September 6, 2007
JNI's public class Main
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment