bouncy castle java example
Sponsored Links
Sponsored Links
Secleted [ 0 ] software to compare
Results 1 - 15 of about 5196
Legion of the Bouncy Castle Java Cryptography API 1.37
The Legion of the Bouncy Castle Java Cryptography API provides a lightweight cryptography API in Java. more>>
The Legion of the Bouncy Castle Java Cryptography API provides a lightweight cryptography API in Java. A provider for the JCE and JCA, a clean-room implementation of the JCE 1.2.1, generators for Version 1 and Version 3 X.509 certificates, generators for Version 2 X.509 attribute certificates, PKCS12 support, and APIs for dealing with S/MIME, CMS, OCSP, TSP, and OpenPGP. Versions are provided for the J2ME, and JDK 1.0-1.5.
Main features:
- A lightweight cryptography API in Java.
- A provider for the JCE and JCA.
- A clean room implementation of the JCE 1.2.1.
- A library for reading and writing encoded ASN.1 objects.
- Generators for Version 1 and Version 3 X.509 certificates, Version 2 CRLs, and PKCS12 files.
- Generators for Version 2 X.509 attribute certificates.
- Generators/Processors for S/MIME and CMS (PKCS7).
- Generators/Processors for OCSP (RFC 2560).
- Generators/Processors for TSP (RFC 3161).
- Generators/Processors for OpenPGP (RFC 2440).
- A signed jar version suitable for JDK 1.4/1.5 and the Sun JCE.
<<lessMain features:
- A lightweight cryptography API in Java.
- A provider for the JCE and JCA.
- A clean room implementation of the JCE 1.2.1.
- A library for reading and writing encoded ASN.1 objects.
- Generators for Version 1 and Version 3 X.509 certificates, Version 2 CRLs, and PKCS12 files.
- Generators for Version 2 X.509 attribute certificates.
- Generators/Processors for S/MIME and CMS (PKCS7).
- Generators/Processors for OCSP (RFC 2560).
- Generators/Processors for TSP (RFC 3161).
- Generators/Processors for OpenPGP (RFC 2440).
- A signed jar version suitable for JDK 1.4/1.5 and the Sun JCE.
Download (21.2MB)
Added: 2007-06-15 License: Freely Distributable Price:
532 downloads
Sitemaps for Java Beta
Sitemaps for Java provides a Java API for the creation of Google Sitemaps and -Indexes. more>>
Sitemaps for Java provides a Java API for the creation of Google Sitemaps and -Indexes.
Sitemaps for Java allows developers to easily create Google Sitemaps. It handles every aspect of Sitemap creation, allowing you to create unlimited Sitemaps and -Indexes.
Provided is API / Javadoc, an example-usage as well as Sitemap ressources and other information
Enhancements:
- Initial beta-release of Sitemaps for Java, this includes basic functionality to create Google Sitemaps and -Indexes with/without compressed Sitemaps
- unlimited number of URLs, Sitemaps and -Indexes.
<<lessSitemaps for Java allows developers to easily create Google Sitemaps. It handles every aspect of Sitemap creation, allowing you to create unlimited Sitemaps and -Indexes.
Provided is API / Javadoc, an example-usage as well as Sitemap ressources and other information
Enhancements:
- Initial beta-release of Sitemaps for Java, this includes basic functionality to create Google Sitemaps and -Indexes with/without compressed Sitemaps
- unlimited number of URLs, Sitemaps and -Indexes.
Download (0.34MB)
Added: 2007-02-07 License: GPL (GNU General Public License) Price:
993 downloads
FreeCell Java Applet 1.1
FreeCell Java Applet project is a Java applet of the popular FreeCell card game. more>>
FreeCell Java Applet project is a Java applet of the popular FreeCell card game.
This is a Java applet of the popular FreeCell card game.
FreeCell is the enormously popular solitaire game. Because all cards are visible at the start of the game, it is almost entirely a game of skill.
Almost all FreeCell positions can be won. The most notable exception is the game #11982.
<<lessThis is a Java applet of the popular FreeCell card game.
FreeCell is the enormously popular solitaire game. Because all cards are visible at the start of the game, it is almost entirely a game of skill.
Almost all FreeCell positions can be won. The most notable exception is the game #11982.
Download (0.023MB)
Added: 2006-12-20 License: (FDL) GNU Free Documentation License Price:
1053 downloads
Java::Import::Examples 0.03
Java::Import::Examples is an example of how to use Java::Import to call into Java classes. more>>
Java::Import::Examples is an example of how to use Java::Import to call into Java classes.
Making RMI calls from Perl
One nice thing about Java is the extremely straight forward manner in which it allows you to make calls to remote objects residing on distant servers. Many people use this ability as a point of integration between their system and a posible third party or legacy system. Unfortunatly, for the most part the ability to make calls to these remote objects is something that only other Java applications can do without making a big fuss about it. However, we can now do this from Perl.
Assume that I have a RMI server from which I can get data from in the form of simple Java Beans. One method of doing this is to use the GCJ::Cni library and natively compile and wrap a set of Java Classes which can then be used from my Perl script. However, there is an easier way.
Lets begin by descriping the Java interfaces that well be working with. We first have the Remote Interface that we will be interacting with:
import java.rmi.*;
public interface RemoteInterface extends Remote {
public SomeBean getMessage(String seedMessage) throws RemoteException;
}
And we also have the bean we will be asking for:
import java.io.*;
public class SomeBean implements Serializable {
private String value;
public SomeBean() {}
public void setValue ( String _value ) { ... }
public String getValue ( ) { ... }
}
As far as any Perl client program is concerned this is all we need to know about.
Now all there is left to do is write a client:
use Java::Import qw(
java.rmi.Naming
);
my $remote_interface = java::rmi::Naming->lookup(jstring("//localhost/Home"));
my $bean = $remote_interface->getMessage(jstring("Hi there"));
print $bean->getValue(), "n";
Thats all there is. Notice that all we had to tell Java::Import about was java.rmi.Naming, this is because it was the only class we used by name in our Perl code, every other Java class (the objects held by $bean and $remote_interface) was returned by some other method call originating from java.rmi.Naming.
In order to run this example we have to make sure everything is in its place. We start by compiling the client code. Assuming that we have been given a Stub class file (RemoteObject_Stub.class) we can do the following:
gcj -C SomeBean.java RemoteInterface.java
fastjar -cvf client.jar SomeBean.class RemoteInterface.class RemoteObject_Stub.class
Making sure our server is reachable we can then run the client code:
CLASSPATH=client.jar perl client.pl
Thats it, you should then see the message returned by your server.
<<lessMaking RMI calls from Perl
One nice thing about Java is the extremely straight forward manner in which it allows you to make calls to remote objects residing on distant servers. Many people use this ability as a point of integration between their system and a posible third party or legacy system. Unfortunatly, for the most part the ability to make calls to these remote objects is something that only other Java applications can do without making a big fuss about it. However, we can now do this from Perl.
Assume that I have a RMI server from which I can get data from in the form of simple Java Beans. One method of doing this is to use the GCJ::Cni library and natively compile and wrap a set of Java Classes which can then be used from my Perl script. However, there is an easier way.
Lets begin by descriping the Java interfaces that well be working with. We first have the Remote Interface that we will be interacting with:
import java.rmi.*;
public interface RemoteInterface extends Remote {
public SomeBean getMessage(String seedMessage) throws RemoteException;
}
And we also have the bean we will be asking for:
import java.io.*;
public class SomeBean implements Serializable {
private String value;
public SomeBean() {}
public void setValue ( String _value ) { ... }
public String getValue ( ) { ... }
}
As far as any Perl client program is concerned this is all we need to know about.
Now all there is left to do is write a client:
use Java::Import qw(
java.rmi.Naming
);
my $remote_interface = java::rmi::Naming->lookup(jstring("//localhost/Home"));
my $bean = $remote_interface->getMessage(jstring("Hi there"));
print $bean->getValue(), "n";
Thats all there is. Notice that all we had to tell Java::Import about was java.rmi.Naming, this is because it was the only class we used by name in our Perl code, every other Java class (the objects held by $bean and $remote_interface) was returned by some other method call originating from java.rmi.Naming.
In order to run this example we have to make sure everything is in its place. We start by compiling the client code. Assuming that we have been given a Stub class file (RemoteObject_Stub.class) we can do the following:
gcj -C SomeBean.java RemoteInterface.java
fastjar -cvf client.jar SomeBean.class RemoteInterface.class RemoteObject_Stub.class
Making sure our server is reachable we can then run the client code:
CLASSPATH=client.jar perl client.pl
Thats it, you should then see the message returned by your server.
Download (0.028MB)
Added: 2007-06-01 License: Perl Artistic License Price:
876 downloads
JSwat Java Debugger 4.2
JSwat is a graphical, stand-alone Java debugger, using the JPDA library. more>>
JSwat is a graphical, stand-alone Java debugger, using the JPDA library.
JSwat Java Debugger offers breakpoints with monitors and conditions, colorized source code display, single-stepping, displaying variables, viewing stack frames, and expression evaluation.
Main features:
- breakpoints with conditionals and monitors
- colorized source code display
- graphical display panels showing threads
- stack frames
- visible variables
- loaded classes
- command interface for more advanced features
- Java-like expression evaluation, including method invocation.
<<lessJSwat Java Debugger offers breakpoints with monitors and conditions, colorized source code display, single-stepping, displaying variables, viewing stack frames, and expression evaluation.
Main features:
- breakpoints with conditionals and monitors
- colorized source code display
- graphical display panels showing threads
- stack frames
- visible variables
- loaded classes
- command interface for more advanced features
- Java-like expression evaluation, including method invocation.
Download (11.9MB)
Added: 2007-05-18 License: CDDL (Common Development and Distribution License) Price:
895 downloads
The Java Exorcist 0.1.0
The Java Exorcist project can be used to extend the Java language syntactically. more>>
The Java Exorcist projects aim is to create a small and easy to use tool, that can be used to extend the Java language syntactically. Why would you do that? There are basically two reasons:
First, you just might want to fix your pet-peeve in the language itself. For example, create new keywords like unless, foreach, new operators, or generate setter getters automatically for a bean property.
Secondly, you might tune the language itself for a specific project, so the project code may look more clean and thought out. For example: specific logger keyword, which automatically checks (if statement) whether the logger should be invoked or not, or even ommits the whole logging compile-time, when its disabled! Or create a method modifier transaction to enclose the whole method in a project specific transaction.
How it works on the outside
Exorcist is a compiler of extended Java code. The compiler can be used in command-line mode, or through Ant. Basically, with no extensions configured, Exorcist only compiles the standard java code. To extend the language, you can plug in classes, which extend a single interface of the exorcist framework, and implement a single (and simple) method. Thats it.
How it works inside
Exorcist works like a pre-processor. It translates the extended language into plain Java code, and then compiles it using the standard Java compiler (javac).
To analyze a language, there are two steps involved. The first is a Lexical analysis, the second is the Parsing of the lexical tokens. Lexical tokens are strings, numbers, operators, dots, semicolons, etc. These are also called terminal symbols, because they can not be analyzed further. During parsing, lexical tokens are read, and non-terminal symbols may be produced.
These include things like: expression, method body, declaration, if-statement, etc. The Exorcists tranformation engine works basically with lexical token lists. Each extension first matches itself to the start of the received token list, using terminal and non-terminal symbols freely. If the match is detected, the extension is free to modify the input token list as it pleases, and with it modify the output clean Java source code.
<<lessFirst, you just might want to fix your pet-peeve in the language itself. For example, create new keywords like unless, foreach, new operators, or generate setter getters automatically for a bean property.
Secondly, you might tune the language itself for a specific project, so the project code may look more clean and thought out. For example: specific logger keyword, which automatically checks (if statement) whether the logger should be invoked or not, or even ommits the whole logging compile-time, when its disabled! Or create a method modifier transaction to enclose the whole method in a project specific transaction.
How it works on the outside
Exorcist is a compiler of extended Java code. The compiler can be used in command-line mode, or through Ant. Basically, with no extensions configured, Exorcist only compiles the standard java code. To extend the language, you can plug in classes, which extend a single interface of the exorcist framework, and implement a single (and simple) method. Thats it.
How it works inside
Exorcist works like a pre-processor. It translates the extended language into plain Java code, and then compiles it using the standard Java compiler (javac).
To analyze a language, there are two steps involved. The first is a Lexical analysis, the second is the Parsing of the lexical tokens. Lexical tokens are strings, numbers, operators, dots, semicolons, etc. These are also called terminal symbols, because they can not be analyzed further. During parsing, lexical tokens are read, and non-terminal symbols may be produced.
These include things like: expression, method body, declaration, if-statement, etc. The Exorcists tranformation engine works basically with lexical token lists. Each extension first matches itself to the start of the received token list, using terminal and non-terminal symbols freely. If the match is detected, the extension is free to modify the input token list as it pleases, and with it modify the output clean Java source code.
Download (0.73MB)
Added: 2007-05-04 License: GPL (GNU General Public License) Price:
903 downloads
SJPT: Simple Java Parsing Toolkit
SJPT: Simple Java Parsing Toolkit is a simple Java parser toolkit. more>>
SJPT is parsing toolkit that supports both top-down (LL(1) and Simple Precedence) and bottom-up parsing (LR(0), SLR(1), LR(1) and LALR(1)).
The toolkit also supports generating Java parsers for all the bottom-up parsing methods, based on a CUP definition (similar to Yacc and CUP, but not restricted to LALR parsers only). I worked alone on this project for the laboratory on Compilers.
SJPT is free software under the terms of the GNU GPL.
<<lessThe toolkit also supports generating Java parsers for all the bottom-up parsing methods, based on a CUP definition (similar to Yacc and CUP, but not restricted to LALR parsers only). I worked alone on this project for the laboratory on Compilers.
SJPT is free software under the terms of the GNU GPL.
Download (0.26MB)
Added: 2005-04-22 License: GPL (GNU General Public License) Price:
1650 downloads
Holotzs Castle 1.3.10
Holotzs Castle is an awesome platform game. more>>
Holotzs Castle is an awesome platform game.
A great mistery is hidden beyond the walls of Holotzs Castle. Will you be able to help Ybelle and Ludar to escape alive from the castle?
Test your dexterity with this tremendously exciting platform game!
<<lessA great mistery is hidden beyond the walls of Holotzs Castle. Will you be able to help Ybelle and Ludar to escape alive from the castle?
Test your dexterity with this tremendously exciting platform game!
Download (3.4MB)
Added: 2007-07-07 License: GPL (GNU General Public License) Price:
841 downloads
The Castle 0.7.0
The Castle is a first-person shooter (FPS) style game in a dark fantasy setting. more>>
The Castle is a first-person shooter (FPS) style game in a dark fantasy setting. Your main weapon is a sword, so the fight is mostly short-range. 3 main levels included, packed with creatures, items and sounds.
Also a bonus level, from a well-known 3D game, will be available to you from "New Game" menu once you finish the main game (you can also switch to this level from the debug menu, if youre impatient).
<<lessAlso a bonus level, from a well-known 3D game, will be available to you from "New Game" menu once you finish the main game (you can also switch to this level from the debug menu, if youre impatient).
Download (37MB)
Added: 2007-06-15 License: GPL (GNU General Public License) Price:
862 downloads
Castle Linux 2.4
Castle is a server distribution from the ALT Linux Team in Russia. more>>
Castle is a server distribution from the ALT Linux Team in Russia. Installation instructions and some other documentation is available in English.
Brief RSBAC instructions:
1. During installation process you will have to create security officer account. This is a user that can setup RSBAC security configuration.
2. Installer applies to RSBAC kernel two special parameters "rsbac_auth_enable_login" and "rsbac_softmode". Please, dont remove it. You need it for correct installation process.
3. Run RSBAC kernel just after system installation.
4. After reboot RSBAC will function in normal mode. If you need soft mode again, use rsbac_softmode kernel parameter during boot.
5. After finishing system configuration please reboot your server.
6. RSBAC will work in normal mode at all future startups of the system. You can boot RSBAC kernel in "soft" mode again using "rsbac_softmode" kernel parameter.
7. Login as security officer you have created during installation process and run main RSBAC configuration utility "rsbac_admin".
Default security configuration:
* All system directories are in "read only" and "execute only" mode.
* Base system configuration files (e.g /etc/lilo.conf /etc/fstab) are also in read only mode.
* Home directory is available only for users and security officer (but he has no access to users home directories).Security Officers home is situated in the root directory (/secoff) and is open only for the owner. You can also create trusted environment for security officer by putting special files into the home.
* There are some useful scripts in security officers home: to enable/disable useradd, to enable/disable install and an example script for http protection.
<<lessBrief RSBAC instructions:
1. During installation process you will have to create security officer account. This is a user that can setup RSBAC security configuration.
2. Installer applies to RSBAC kernel two special parameters "rsbac_auth_enable_login" and "rsbac_softmode". Please, dont remove it. You need it for correct installation process.
3. Run RSBAC kernel just after system installation.
4. After reboot RSBAC will function in normal mode. If you need soft mode again, use rsbac_softmode kernel parameter during boot.
5. After finishing system configuration please reboot your server.
6. RSBAC will work in normal mode at all future startups of the system. You can boot RSBAC kernel in "soft" mode again using "rsbac_softmode" kernel parameter.
7. Login as security officer you have created during installation process and run main RSBAC configuration utility "rsbac_admin".
Default security configuration:
* All system directories are in "read only" and "execute only" mode.
* Base system configuration files (e.g /etc/lilo.conf /etc/fstab) are also in read only mode.
* Home directory is available only for users and security officer (but he has no access to users home directories).Security Officers home is situated in the root directory (/secoff) and is open only for the owner. You can also create trusted environment for security officer by putting special files into the home.
* There are some useful scripts in security officers home: to enable/disable useradd, to enable/disable install and an example script for http protection.
Download (706MB)
Added: 2005-05-17 License: GPL (GNU General Public License) Price:
1620 downloads
Java Brainfuck Compiler 2.0
Java Brainfuck Compiler is an optimising Brainfuck to Java bytecode compiler. more>>
The Java Brainfuck Compiler is a compiler for the uniquely powerful Brainfuck language, which produces Java bytecode that will run on any Java Virtual Machine (with no intermediate steps such as going by way of Java code).
<<less Download (0.010MB)
Added: 2005-04-18 License: GPL (GNU General Public License) Price:
1682 downloads
Inline::Java 0.52
Inline::Java lets you write Perl classes in Java and wrap/use existing Java classes. more>>
Inline::Java lets you write Perl classes in Java and wrap/use existing Java classes. The project is an ILSM (Inline Language Support Module) for Java 2, and is part of the Inline family of modules.
<<less Download (0.092MB)
Added: 2007-03-01 License: Perl Artistic License Price:
579 downloads
Sparklines for Java 1.2
Sparklines are intense, simple, wordlike graphics. more>>
Sparklines are intense, simple, wordlike graphics.
Theres a PHP library for producing sparklines, and even a sparkline web service, but I wanted something I could use to generate sparklines in both Java and JSTL (and I thought it would be a fun project). (Its also worth checking out Whys minimalist python sparklines, which encode the image data directly in the HTML as a data: URI [this library allows you to encode the images as using either data: format or javascript: format (supported by IE) in JSTL])
JSTL examples
< %@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" % >
< %@ taglib prefix="spark" uri="http://www.representqueens.com/taglibs/spark" % >
< c:set var="test" value="5, 35, 22, 19, 16, 10, 4, 33, 9, 12, 27, 36, 22" / >
< img src="< spark:bar name="test" color="red" / >" / >
will produce:
(I think the default size might be a little large).
The "name" attribute specifies the key to find the data (Uses JspContext.findAttribute). It expects the value to be either a List , a Number[], or a String of comma separated int values. Its the only manditory attribute.
The other attributes are width, height, spacing, color, highColor, lastColor, output. You can replace "bar" with "line" to get a linegraph (note: highColor and lastColor are currently not supported for line graphs).
The color attributes can either be a color name (a field name from java.awt.Color), or a HTML hex color (e.g. #ff0000 for red).
Enhancements:
- This release properly URL encodes parameters for server generated sparklines.
- This fixes an issue when using hex specified image colors.
- The tag parameter "background" has been added as a workaround for IE6 PNG transparency.
<<lessTheres a PHP library for producing sparklines, and even a sparkline web service, but I wanted something I could use to generate sparklines in both Java and JSTL (and I thought it would be a fun project). (Its also worth checking out Whys minimalist python sparklines, which encode the image data directly in the HTML as a data: URI [this library allows you to encode the images as using either data: format or javascript: format (supported by IE) in JSTL])
JSTL examples
< %@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" % >
< %@ taglib prefix="spark" uri="http://www.representqueens.com/taglibs/spark" % >
< c:set var="test" value="5, 35, 22, 19, 16, 10, 4, 33, 9, 12, 27, 36, 22" / >
< img src="< spark:bar name="test" color="red" / >" / >
will produce:
(I think the default size might be a little large).
The "name" attribute specifies the key to find the data (Uses JspContext.findAttribute). It expects the value to be either a List , a Number[], or a String of comma separated int values. Its the only manditory attribute.
The other attributes are width, height, spacing, color, highColor, lastColor, output. You can replace "bar" with "line" to get a linegraph (note: highColor and lastColor are currently not supported for line graphs).
The color attributes can either be a color name (a field name from java.awt.Color), or a HTML hex color (e.g. #ff0000 for red).
Enhancements:
- This release properly URL encodes parameters for server generated sparklines.
- This fixes an issue when using hex specified image colors.
- The tag parameter "background" has been added as a workaround for IE6 PNG transparency.
Download (0.030MB)
Added: 2007-03-14 License: The Apache License 2.0 Price:
956 downloads
Secure Java Diary 0.3.0a
Secure Java Diary is a Java Diary with Strong Encryption. more>>
Secure Diary is a Java application that uses the Bouncy Castle JCE to provide strong encryption for your diary.
It stores the entries using blowfish and triple DES. It allows you to enter/view/export diary enteries in multiple diaries.
<<lessIt stores the entries using blowfish and triple DES. It allows you to enter/view/export diary enteries in multiple diaries.
Download (0.82MB)
Added: 2005-04-26 License: GPL (GNU General Public License) Price:
1649 downloads
GCJ::Cni::Examples 0.03
GCJ::Cni::Examples is a Perl module with examples of how to use GCJs CNI interface to write Perl Modules in Java. more>>
GCJ::Cni::Examples is a Perl module with examples of how to use GCJs CNI interface to write Perl Modules in Java.
EXAMPLES
Writing Treaded modules in Java
One benefit of using GCJ is that it takes advantage of POSIX threading. This is nice since Perls threading model is, shall we say, less than ideal. Now, you could theoretically write a module in C or C++ and and use the standard POSIX library to do your threaded work for you, however, why not take advantage of the nice Threading interface that Java provides to you by default. This may also come in handy if you have a massively threaded Java library that youd like to call from Perl.
For this example assume that I want to do matrix multiplication, albeit in a very crazy manner. Therefore, I will write a Java class, Matrix, and a method, multiply, which will take another matrix to perform the operation between. Heres the crazy part, for each cell in the resulting matrix I will spawn a new thread, as an internal class, and give it a row and a column from which they will derive the result. I know this is a little wierd but the point is that Ill be spawning a lot of new threads. To multiply two 10x10 matrices we will have to spawn 100 threads (one thread per cell in the resulting 10x10 matrix). Imagine doing this in Perl, then imagine doing it in Java; natively compiled Java. Much faster and a lot less headaches.
The Java Interface/pseudocode is as follows:
public class Matrix {
public Matrix ( int numRows, int numCols ) {
...Constructor stuff...
}
public void set ( int row, int col, int val ) {
...set an element...
}
public int get ( int row, int col ) {
...get an element...
}
public Matrix multiply ( Matrix times ) {
...set it up...
for ( int i = 0; i < rows; i++ ) {
for ( int j = 0; j < times.getCols(); j++ ) {
//GO NUTS!!!!
ArrayMultiplier multiplier = new ArrayMultiplier(this, times, result, i, j);
multiplier.start();
...etc...
}
}
...wait for the threads to exit and return the new matrix...
}
public int getRows ( ) {
...get number of rows...
}
public int getCols ( ) {
...get number of columns...
}
public void print ( ) {
...print the matrix to stdout...
}
private class ArrayMultiplier extends Thread {
public ArrayMultiplier ( Matrix a, Matrix b, Matrix result, int row, int col ) {
...Construct this bad boy...
}
public void run ( ) {
int sum = 0;
for ( int i = 0; i < a.getCols(); i++ ) {
sum += (a.get(row, i) * b.get(i, col));
}
result.set(row, col, sum);
}
}
}
Now, we want to call this class from Perl. My perferred manner is through SWIG so thats what were going to use. However, you do not need to use SWIG, you can use whatever method you prefer when wrapping C++ classes. We begin by creating a C++ header file from our above class. This is done by using GCJs gcjh utility. First we need to class compile Matrix.java
gcj -C Matrix.java
Then we go ahead and create the header file:
gcjh Matrix
Easy enough. We can then extract the interface we want to have available in Perl from the generated header file and from it create a i file to be used as input to SWIG. I usually start by copying my header file to the same named file but with an i extension instead. I then remove all of the grimy C++ gruff, private methods and variables, slap a module directive on it and call it done. It wont always be this easy though. When youre done an interface file for the above class should look something like this:
%module Matrix;
typedef int jint;
class Matrix
{
public:
Matrix (jint, jint);
virtual void set (jint, jint, jint);
virtual jint get (jint, jint);
virtual ::Matrix *multiply (::Matrix *);
virtual jint getRows ();
virtual jint getCols ();
virtual void print ();
};
We then put SWIG to work and generate our C++ wrapper for Perl:
swig -perl -c++ Matrix.i
After the above command we now will see two new files in our current directory, Matrix.pm and Matrix_wrap.cxx; these correspond the module directive we gave in Matrix.i.
At this point all we have left to do is compile, and use.
gcj -c Matrix.java
gcc -c -I -include Matrix.h Matrix_wrap.cxx
gcc -shared -lgcj -lstdc++ Matrix.o Matrix_wrap.o -oMatrix.so
A simple Perl file using this module might look something like:
sub populate_matrix {
my $matrix = shift;
for ( my $i = 0; $i < $matrix->getRows(); $i++ ) {
for ( my $j = 0; $j < $matrix->getCols(); $j++ ) {
$matrix->set($i, $j, $i * $j);
}
}
}
use GCJ::Cni;
use Matrix;
GCJ::Cni::JvCreateJavaVM(undef);
GCJ::Cni::JvAttachCurrentThread(undef, undef);
my $matrix = new Matrix::Matrix(10, 10);
populate_matrix($matrix);
my $matrix2 = new Matrix::Matrix(10, 10);
populate_matrix($matrix2);
$matrix3 = $matrix->multiply($matrix2);
$matrix3->print();
GCJ::Cni::JvDetachCurrentThread();
Ill leave it up to the reader to write a Perl module that does the same thing, that is, spawns 100 threads. In my own personal fiddling I found that just spawning that many threads (never mind doing any kind of work) was over 3 time slower in Perl. In this situation we at least get to use our favorite language, Perl, and offload some of the heavy hitting to a language more suited for it.
Where this really comes in handy is when you have an existing multi-threaded Java library that you would like to expose to Perl. You could theoretically natively compile various components of your library and then generate Perl bindings to access it. In this way, you get a little extra speed and efficiency as well as code reuse and binding.
<<lessEXAMPLES
Writing Treaded modules in Java
One benefit of using GCJ is that it takes advantage of POSIX threading. This is nice since Perls threading model is, shall we say, less than ideal. Now, you could theoretically write a module in C or C++ and and use the standard POSIX library to do your threaded work for you, however, why not take advantage of the nice Threading interface that Java provides to you by default. This may also come in handy if you have a massively threaded Java library that youd like to call from Perl.
For this example assume that I want to do matrix multiplication, albeit in a very crazy manner. Therefore, I will write a Java class, Matrix, and a method, multiply, which will take another matrix to perform the operation between. Heres the crazy part, for each cell in the resulting matrix I will spawn a new thread, as an internal class, and give it a row and a column from which they will derive the result. I know this is a little wierd but the point is that Ill be spawning a lot of new threads. To multiply two 10x10 matrices we will have to spawn 100 threads (one thread per cell in the resulting 10x10 matrix). Imagine doing this in Perl, then imagine doing it in Java; natively compiled Java. Much faster and a lot less headaches.
The Java Interface/pseudocode is as follows:
public class Matrix {
public Matrix ( int numRows, int numCols ) {
...Constructor stuff...
}
public void set ( int row, int col, int val ) {
...set an element...
}
public int get ( int row, int col ) {
...get an element...
}
public Matrix multiply ( Matrix times ) {
...set it up...
for ( int i = 0; i < rows; i++ ) {
for ( int j = 0; j < times.getCols(); j++ ) {
//GO NUTS!!!!
ArrayMultiplier multiplier = new ArrayMultiplier(this, times, result, i, j);
multiplier.start();
...etc...
}
}
...wait for the threads to exit and return the new matrix...
}
public int getRows ( ) {
...get number of rows...
}
public int getCols ( ) {
...get number of columns...
}
public void print ( ) {
...print the matrix to stdout...
}
private class ArrayMultiplier extends Thread {
public ArrayMultiplier ( Matrix a, Matrix b, Matrix result, int row, int col ) {
...Construct this bad boy...
}
public void run ( ) {
int sum = 0;
for ( int i = 0; i < a.getCols(); i++ ) {
sum += (a.get(row, i) * b.get(i, col));
}
result.set(row, col, sum);
}
}
}
Now, we want to call this class from Perl. My perferred manner is through SWIG so thats what were going to use. However, you do not need to use SWIG, you can use whatever method you prefer when wrapping C++ classes. We begin by creating a C++ header file from our above class. This is done by using GCJs gcjh utility. First we need to class compile Matrix.java
gcj -C Matrix.java
Then we go ahead and create the header file:
gcjh Matrix
Easy enough. We can then extract the interface we want to have available in Perl from the generated header file and from it create a i file to be used as input to SWIG. I usually start by copying my header file to the same named file but with an i extension instead. I then remove all of the grimy C++ gruff, private methods and variables, slap a module directive on it and call it done. It wont always be this easy though. When youre done an interface file for the above class should look something like this:
%module Matrix;
typedef int jint;
class Matrix
{
public:
Matrix (jint, jint);
virtual void set (jint, jint, jint);
virtual jint get (jint, jint);
virtual ::Matrix *multiply (::Matrix *);
virtual jint getRows ();
virtual jint getCols ();
virtual void print ();
};
We then put SWIG to work and generate our C++ wrapper for Perl:
swig -perl -c++ Matrix.i
After the above command we now will see two new files in our current directory, Matrix.pm and Matrix_wrap.cxx; these correspond the module directive we gave in Matrix.i.
At this point all we have left to do is compile, and use.
gcj -c Matrix.java
gcc -c -I -include Matrix.h Matrix_wrap.cxx
gcc -shared -lgcj -lstdc++ Matrix.o Matrix_wrap.o -oMatrix.so
A simple Perl file using this module might look something like:
sub populate_matrix {
my $matrix = shift;
for ( my $i = 0; $i < $matrix->getRows(); $i++ ) {
for ( my $j = 0; $j < $matrix->getCols(); $j++ ) {
$matrix->set($i, $j, $i * $j);
}
}
}
use GCJ::Cni;
use Matrix;
GCJ::Cni::JvCreateJavaVM(undef);
GCJ::Cni::JvAttachCurrentThread(undef, undef);
my $matrix = new Matrix::Matrix(10, 10);
populate_matrix($matrix);
my $matrix2 = new Matrix::Matrix(10, 10);
populate_matrix($matrix2);
$matrix3 = $matrix->multiply($matrix2);
$matrix3->print();
GCJ::Cni::JvDetachCurrentThread();
Ill leave it up to the reader to write a Perl module that does the same thing, that is, spawns 100 threads. In my own personal fiddling I found that just spawning that many threads (never mind doing any kind of work) was over 3 time slower in Perl. In this situation we at least get to use our favorite language, Perl, and offload some of the heavy hitting to a language more suited for it.
Where this really comes in handy is when you have an existing multi-threaded Java library that you would like to expose to Perl. You could theoretically natively compile various components of your library and then generate Perl bindings to access it. In this way, you get a little extra speed and efficiency as well as code reuse and binding.
Download (0.020MB)
Added: 2007-06-04 License: Perl Artistic License Price:
877 downloads
Secleted [ 0 ] software to compare
Copyright Notice:
Software piracy is theft, Using crack, password, serial numbers, registration codes, key generators is illegal and prevent future software development. The above bouncy castle java example search only lists software in full, demo and trial versions for free download. Download links are directly from our mirror sites or publisher sites, torrent files or links from rapidshare.com, yousendit.com or megaupload.com are not allowed