CJavaIPC

CJavaIPC is a simple C library that allows the transfer of primitive types between C and Java programs, as well as between C programs on different architectures.

This library works by emulating the internal function of Java's DataInputStream and DataOutputStream classes. The library compensates for different byte orders on different architectures.

This library was inspired by G.W. Lucas's C code snippet on sourceforge. Gary would like everyone to know about the Rossum Project (http://rossum.sourceforge.net)

Bug tracking, support management as well as the latest source code can be found at http://sourceforge.net/project/?group_id=6764

The CJavaIPC libraries are released under the terms of the LGPL.


Features

The library can transfer the following Java compatible types:

In addition it can transfer:


HISTORY

Version 0.5: 21 March 2000

Function names and types have been changed. Byte array, character an UTF8 functions have been added. Logic flow has been improved. In particular it is no longer required to know the if the machine is big endian or little endian as jhton32 etc should compile to nothing on correctly endian machines.

Version 0.6: 27 March 2000

Function consolidation. Added utility functions.

Version 0.7: 05 April 2000

Function consolidation and simplication. Bug fixes.

Version 0.8: 08 June 2000

All functions and types renamed. The way jhton* and jntoh* functions worked changed completely. Lots of stupid bugs fixed. SPARC support.


Types

These types have to be the same size on all platforms. Marshing code takes care of byte order problems when these types are sent over a socket or to a file.

 jbyte      8 bit unsigned       #java compatible
 jchar      8 bit signed         #subset
 jwchar    32 bit unsigned       #superset
 jshort    16 bit signed         #java compatible
 jushort   16 bit unsigned       #java compatible
 jint      32 bit signed         #java compatible
 juint     32 bit unsigned
 jlong     64 bit signed         #java compatible
 julong    64 bit unsigned
 jfloat    32 bit IEEE           #java compatible
 jdouble   64 bit IEEE           #java compatible
 jbool     32 bit signed (0&1)   #java compatible


Functions

N.B. None of the characters functions respect the current locale. A ``C'' or ``POSIX'' locale is assumed. User in other locales should use the iconv() before calling the jwrite*() functions and after calling the jread*() functions where appropriate. This issue will be addressed in a future release.

jwriteByte

jbool jwriteByte( FILE *fp, jbyte b );

Write a single byte.

jwriteBytes

jbool jwriteBytes( FILE *fp, jbyte *b, juint cb );

Write an array of bytes.

jwriteBoolean

jbool jwriteBoolean( FILE *fp, jbool bool );

Write a 1 byte boolean value.

jwriteShort

jbool jwriteShort( FILE *fp, jshort n );

Write a 2 byte signed short value, most significant byte first.

jwriteUnsignedShort

jbool jwriteUnsignedShort( FILE *fp, jushort n );

Write a 2 byte unsigned short value, most significant byte first.

jwriteInt

jbool jwriteInt( FILE *fp, jint n );

Write a 4 byte signed integer value, most significant byte first.

jwriteUnsignedInt

jbool jwriteUnsignedInt( FILE *fp, juint n );

Write a 4 byte unsigned integer value, most significant byte first. This function is not compatable with Java.

jwriteLong

jbool jwriteLong( FILE *fp, jlong n );

Write a 8 byte signed long value, most significant byte first.

jwriteUnsignedLong

jbool jwriteUnsignedLong( FILE *fp, julong n );

Write a 8 byte unsigned long value, most significant byte first. This function is not compatable with Java.

jwriteFloat

jbool jwriteFloat( FILE *fp, jfloat f );

Writes a 4 byte float value, most significant byte first.

jwriteDouble

jbool jwriteDouble( FILE *fp, jdouble d );

Writes a 8 byte double value, most significant byte first.

jwriteCharsUCS2

jbool jwriteCharsUCS2( FILE *fp, jchar *c, juint count );

Writes count ISO Latin characters in UCS2 format.

jwriteCharsUCS4

jbool jwriteCharsUCS4( FILE *fp, jchar *c, juint count );

Writes count ISO Latin characters in UCS4 format. This function is not Java compatable.

jwriteCharsUTF8

jbool jwriteCharsUTF8( FILE *fp, jchar *c, juint count );

Writes count ISO Latin characters in UTF8 format. This function is not Java compatable. Use jwriteStringUTF8 instead.

jwriteWideCharsUCS2

jbool jwriteWideCharsUCS2( FILE *fp, jwchar *c, juint count );

Writes count wide characters in UCS2 format. This function is only compatable with Java if all characters written are insided the basic mapping plane. That is all characters have a value less than or equal to 0x0000FFFF.

jwriteWideCharsUCS4

jbool jwriteWideCharsUCS4( FILE *fp, jwchar *c, juint count );

Writes count wide characters in UCS4 format. This function is not compatable with Java.

jwriteWideCharsUTF8

jbool jwriteWideCharsUTF8( FILE *fp, jwchar *c, juint count );

Writes count wide characters in UTF8 format. This function is not Java compatable. Use jwriteWideStringUTF8 instead.

jwriteStringUTF8

jbool jwriteStringUTF8( FILE *fp, jchar *sz, juint count );

Write a string of count ISO Latin characters in UTF8 format.

jwriteWideStringUTF8

jbool jwriteWideStringUTF8( FILE *fp, jwchar *sz, juint count );

Writes a string of count wide characters in UCS2 format. This function is only compatable with Java if all characters written are insided the basic mapping plane. That is all characters have a value less than or equal to 0x0000FFFF.

jreadByte

jbool jreadByte( FILE *fp, jbyte *b );

Read a single byte.

jreadBytes

jbool jreadBytes( FILE *fp, jbyte *b, juint cb );

Read cb bytes into the array pointed to by b.

jreadBoolean

jbool jreadBoolean( FILE *fp, jbool *bool );

Reads a boolean value.

jreadShort

jbool jreadShort( FILE *fp, jshort *n );

Reads a 2 byte signed short integer.

jreadUnsignedShort

jbool jreadUnsignedShort( FILE *fp, jushort *n );

Read a 2 byte unsigned short integer.

jreadInt

jbool jreadInt( FILE *fp, jint *n );

Read a 4 byte signed integer.

jreadUnsignedInteger

jbool jreadUnsignedInteger( FILE *fp, juint *n );

Read a 4 byte unsigned integer. This function is not Java compatible.

jreadLong

jbool jreadLong( FILE *fp, jlong *n );

Read a 8 byte signed integer.

jreadUnsignedLong

jbool jreadUnsignedLong( FILE *fp, julong *n );

Read a 8 byte unsigned integer. This function is not Java compatible.

jreadFloat

jbool jreadFloat( FILE *fp, jfloat *f );

Read a 4 byte float.

jreadDouble

jbool jreadDouble( FILE *fp, jdouble *d );

Read a 8 byte double.

jreadCharsUCS2

jbool jreadCharsUCS2( FILE *fp, jchar *c, juint count );

Read a single USC2 unicode character.

jreadCharsUCS4

jbool jreadCharsUCS4( FILE *fp, jchar *c, juint count );

Read a single UCS4 unicode character. This function is not Java compatable.

jreadCharsUTF8

jbool jreadCharsUTF8( FILE *fp, jchar *c, juint count );

Reads count characters into the array pointed to by c. This function is not Java compatable. Use jreadStringUTF8 instead.

jreadWideCharsUCS2

jbool jreadWideCharsUCS2( FILE *fp, jwchar *c, juint count );

Reads count UCS2 encoded unicode wide characters into the array pointed to by c.

jreadWideCharsUCS4

jbool jreadWideCharsUCS4( FILE *fp, jwchar *c, juint count );

Reads count UCS4 encoded unicode wide characters into the array pointed to by c. This function is not Java compatible.

jreadWideCharsUTF8

jbool jreadWideCharsUTF8( FILE *fp, jwchar *c, juint count );

Reads count characters into the array pointed to by c. This function is not Java compatable. Use jreadWideStringUTF8 instead.

jreadStringUTF8

jbool jreadStringUTF8( FILE *fp, jchar *sz, juint *count );

Reads a UTF8 string into the character array sz. The count parameter should contain the number of characters avaliable in the sz buffer. On return the count parameter will contain the number of characters actually read.

jreadWideStringUTF8

jbool jreadWideStringUTF8( FILE *fp, jwchar *sz, juint *count );

Reads a UTF8 string into the wide character array sz. The count parameter should contain the number of wide characters avaliable in the sz buffer. On return the count parameter will contain the number of characters actually read.


See Also

java.io.DataInputStream and java.io.DataOutputStream.


Author

Paul Matthews

PaulMatthews@yahoo.com