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.
The library can transfer the following Java compatible types:
boolean values
bytes
arrays of bytes
UCS2 encoded unicode characters
signed and unsigned shorts
unsigned integers
unsigned longs
floats
doubles
UTF8 encoded strings (basic mapping plane only)
In addition it can transfer:
unsigned integers
unsigned longs
UCS4 encoded unicode characters
UTF8 encoded strings (complete wide character support)
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.
Function consolidation. Added utility functions.
Function consolidation and simplication. Bug fixes.
All functions and types renamed. The way jhton* and jntoh* functions worked changed completely. Lots of stupid bugs fixed. SPARC support.
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
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.
jbool jwriteByte(
FILE *fp, jbyte b );
Write a single byte.
jbool jwriteBytes(
FILE *fp, jbyte *b, juint cb );
Write an array of bytes.
jbool jwriteBoolean(
FILE *fp, jbool bool );
Write a 1 byte boolean value.
jbool jwriteShort(
FILE *fp, jshort n );
Write a 2 byte signed short value, most significant byte first.
jbool jwriteUnsignedShort(
FILE *fp, jushort n );
Write a 2 byte unsigned short value, most significant byte first.
jbool jwriteInt(
FILE *fp, jint n );
Write a 4 byte signed integer value, most significant byte first.
jbool jwriteUnsignedInt(
FILE *fp, juint n );
Write a 4 byte unsigned integer value, most significant byte first. This function is not compatable with Java.
jbool jwriteLong(
FILE *fp, jlong n );
Write a 8 byte signed long value, most significant byte first.
jbool jwriteUnsignedLong(
FILE *fp, julong n );
Write a 8 byte unsigned long value, most significant byte first. This function is not compatable with Java.
jbool jwriteFloat(
FILE *fp, jfloat f );
Writes a 4 byte float value, most significant byte first.
jbool jwriteDouble(
FILE *fp, jdouble d );
Writes a 8 byte double value, most significant byte first.
jbool jwriteCharsUCS2(
FILE *fp, jchar *c, juint count );
Writes count ISO Latin characters in UCS2 format.
jbool jwriteCharsUCS4(
FILE *fp, jchar *c, juint count );
Writes count ISO Latin characters in UCS4 format. This function is not Java compatable.
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.
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.
jbool jwriteWideCharsUCS4(
FILE *fp, jwchar *c, juint count );
Writes count wide characters in UCS4 format. This function is not compatable with Java.
jbool jwriteWideCharsUTF8(
FILE *fp, jwchar *c, juint count );
Writes count wide characters in UTF8 format. This function is not Java compatable. Use jwriteWideStringUTF8 instead.
jbool jwriteStringUTF8(
FILE *fp, jchar *sz, juint count );
Write a string of count ISO Latin characters in UTF8 format.
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.
jbool jreadByte(
FILE *fp, jbyte *b
);
Read a single byte.
jbool jreadBytes(
FILE *fp, jbyte *b, juint cb );
Read cb
bytes into the array pointed to by b
.
jbool jreadBoolean(
FILE *fp, jbool *bool
);
Reads a boolean value.
jbool jreadShort(
FILE *fp, jshort *n
);
Reads a 2 byte signed short integer.
jbool jreadUnsignedShort(
FILE *fp, jushort *n
);
Read a 2 byte unsigned short integer.
jbool jreadInt(
FILE *fp, jint *n
);
Read a 4 byte signed integer.
jbool jreadUnsignedInteger(
FILE *fp, juint *n
);
Read a 4 byte unsigned integer. This function is not Java compatible.
jbool jreadLong(
FILE *fp, jlong *n
);
Read a 8 byte signed integer.
jbool jreadUnsignedLong(
FILE *fp, julong *n
);
Read a 8 byte unsigned integer. This function is not Java compatible.
jbool jreadFloat(
FILE *fp, jfloat *f
);
Read a 4 byte float.
jbool jreadDouble(
FILE *fp, jdouble *d
);
Read a 8 byte double.
jbool jreadCharsUCS2(
FILE *fp, jchar *c, juint count );
Read a single USC2 unicode character.
jbool jreadCharsUCS4(
FILE *fp, jchar *c, juint count );
Read a single UCS4 unicode character. This function is not Java compatable.
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.
jbool jreadWideCharsUCS2(
FILE *fp, jwchar *c, juint count );
Reads count UCS2 encoded unicode wide characters into the array pointed to by c.
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.
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.
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.
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.
java.io.DataInputStream and java.io.DataOutputStream.
Paul Matthews