libextractor-java

GNU libextractor
Log | Files | Refs | README | LICENSE

commit 8fc12b309e3c9cb70b558585a429792a1e560584
parent cd1a4bf208c1f221d49f526546ed4c7b79549d75
Author: Christian Grothoff <christian@grothoff.org>
Date:   Sat, 21 Apr 2007 23:14:32 +0000

API update, releasing 0.5.18

Diffstat:
MChangeLog | 5+++++
MREADME.debian | 4+++-
Mconfigure.ac | 4++--
Mnative/extractor.c | 46++++++++++++++++++++++++++++++++++++++++++----
Mnative/org_gnunet_libextractor_Extractor.h | 10+++++++++-
Morg/gnunet/libextractor/Extractor.java | 81+++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------------
Morg/gnunet/libextractor/Xtract.java | 8++++----
7 files changed, 120 insertions(+), 38 deletions(-)

diff --git a/ChangeLog b/ChangeLog @@ -1,3 +1,8 @@ +Sat Apr 21 17:09:03 MDT 2007 + Added method to support extracting data from in-memory + byte array. Changed API to use ArrayList instead of Vector. + Releasing libextractor-java 0.5.18. + Mon Jul 4 16:58:53 CEST 2005 Moved Java code out of main libextractor tree. This ChangeLog started. diff --git a/README.debian b/README.debian @@ -1,5 +1,7 @@ This is a list of debian (sarge) packages that you may want to install -prior to compiling libextractor-java. +prior to compiling libextractor-java. You need a working Java +installation (set JAVA_HOME and possibly JAVA and JAVAC environment +variables). Naturally you also need libextractor itself. diff --git a/configure.ac b/configure.ac @@ -1,8 +1,8 @@ # Process this file with autoconf to produce a configure script. AC_PREREQ(2.57) -AC_INIT([libextractor-java], [0.5.6], [bug-libextractor@gnu.org]) +AC_INIT([libextractor-java], [0.5.18], [bug-libextractor@gnu.org]) AC_REVISION($Revision: 1.67 $) -AM_INIT_AUTOMAKE([libextractor-java], [0.5.6]) +AM_INIT_AUTOMAKE([libextractor-java], [0.5.18]) AM_CONFIG_HEADER(native/config.h) AH_TOP([#define _GNU_SOURCE 1]) diff --git a/native/extractor.c b/native/extractor.c @@ -14,8 +14,8 @@ You should have received a copy of the GNU General Public License along with libextractor; see the file COPYING. If not, write to the - Free Software Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. + Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. */ #include "config.h" @@ -74,10 +74,48 @@ Java_org_gnunet_libextractor_Extractor_extractInternal(JNIEnv * env, jlong ret; bo = JNI_FALSE; - fname = (*env)->GetStringUTFChars(env, f, &bo); + fname = (*env)->GetStringUTFChars(env, + f, + &bo); + if (fname == NULL) + return 0; ret = (jlong) (long) EXTRACTOR_getKeywords((EXTRACTOR_ExtractorList*) (long) arg, fname); - (*env)->ReleaseStringUTFChars(env, f, fname); + (*env)->ReleaseStringUTFChars(env, + f, + fname); + return ret; +} + +/* + * Class: org_gnunet_libextractor_Extractor + * Method: extractInternal + * Signature: (J[B)J + */ +JNIEXPORT jlong JNICALL +Java_org_gnunet_libextractor_Extractor_extractInternal2(JNIEnv * env, + jclass c, + jlong arg, + jbyteArray f) { + void * data; + jboolean bo; + jlong ret; + jsize asize; + + bo = JNI_FALSE; + asize = (*env)->GetArrayLength(env, f); + data = (*env)->GetPrimitiveArrayCritical(env, + f, + &bo); + if (data == NULL) + return 0; + ret = (jlong) (long) EXTRACTOR_getKeywords2((EXTRACTOR_ExtractorList*) (long) arg, + data, + (size_t) asize); + (*env)->ReleasePrimitiveArrayCritical(env, + f, + data, + JNI_ABORT); return ret; } diff --git a/native/org_gnunet_libextractor_Extractor.h b/native/org_gnunet_libextractor_Extractor.h @@ -28,11 +28,19 @@ JNIEXPORT void JNICALL Java_org_gnunet_libextractor_Extractor_unloadInternal * Method: extractInternal * Signature: (JLjava/lang/String;)J */ -JNIEXPORT jlong JNICALL Java_org_gnunet_libextractor_Extractor_extractInternal +JNIEXPORT jlong JNICALL Java_org_gnunet_libextractor_Extractor_extractInternal__JLjava_lang_String_2 (JNIEnv *, jclass, jlong, jstring); /* * Class: org_gnunet_libextractor_Extractor + * Method: extractInternal + * Signature: (J[B)J + */ +JNIEXPORT jlong JNICALL Java_org_gnunet_libextractor_Extractor_extractInternal__J_3B + (JNIEnv *, jclass, jlong, jbyteArray); + +/* + * Class: org_gnunet_libextractor_Extractor * Method: freeInternal * Signature: (J)V */ diff --git a/org/gnunet/libextractor/Extractor.java b/org/gnunet/libextractor/Extractor.java @@ -1,6 +1,6 @@ /* This file is part of libextractor. - (C) 2002, 2003, 2004 Vidyut Samanta and Christian Grothoff + (C) 2002, 2003, 2004, 2007 Vidyut Samanta and Christian Grothoff libextractor is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published @@ -19,7 +19,7 @@ */ package org.gnunet.libextractor; -import java.util.Vector; +import java.util.ArrayList; import java.io.File; /** @@ -31,13 +31,13 @@ import java.io.File; public final class Extractor { - private static boolean warn_; + private static final boolean warn_; /** * LE version. 0 if LE was compiled without JNI/Java support, in which * case we better not call any native methods... */ - private final static int version_; + private static final int version_; /** * Cached list of Strings describing keyword types. @@ -103,8 +103,7 @@ public final class Extractor { public static Extractor getDefault() { if (version_ > 0) return new Extractor(loadDefaultInternal()); - else - return new Extractor(0); + return new Extractor(0); } /** @@ -128,15 +127,16 @@ public final class Extractor { */ public static String getTypeAsString(int type) { if (version_ > 0) { - if ( (type >= 0) && (type <= typeCache_.length)) { + if ( (type >= 0) && + (type <= typeCache_.length) ) { if (typeCache_[type] == null) typeCache_[type] = getTypeAsStringInternal(type); return typeCache_[type]; - } else - throw new IllegalArgumentException("Type out of range [0,"+typeCache_.length+")"); - } else - return ""; + } + throw new IllegalArgumentException("Type out of range [0,"+typeCache_.length+")"); + } + return ""; } /** @@ -152,7 +152,7 @@ public final class Extractor { * to the list of plugins. 0 means no plugins. */ private Extractor(long pluginHandle) { - this.pluginHandle_ = pluginHandle; + pluginHandle_ = pluginHandle; } protected void finalize() { @@ -161,10 +161,9 @@ public final class Extractor { } public void unloadPlugin(String pluginName) { - if (pluginHandle_ != 0) { + if (pluginHandle_ != 0) pluginHandle_ = unloadPlugin(pluginHandle_, - pluginName); - } + pluginName); } /** @@ -184,28 +183,56 @@ public final class Extractor { * Extract keywords (meta-data) from the given file. * * @param f the file to extract meta-data from - * @return a Vector of Extractor.Keywords + * @return a ArrayList of Extractor.Keywords */ - public Vector extract(File f) { + public ArrayList extract(File f) { return extract(f.getAbsolutePath()); } - + /** * Extract keywords (meta-data) from the given file. * * @param file the name of the file - * @return a Vector of Extractor.Keywords + * @return a ArrayList of Extractor.Keywords */ - public Vector extract(String filename) { + public ArrayList extract(String filename) { if (pluginHandle_ == 0) - return new Vector(0); // fast way out + return new ArrayList(0); // fast way out long list = extractInternal(pluginHandle_, - filename); // toChars? + filename); // toChars? + ArrayList ret = convert(list); + freeInternal(list); + return ret; + } + + /** + * Extract keywords (meta-data) from the given block + * of data. + * + * @param data the file data + * @return a ArrayList of Extractor.Keywords + */ + public ArrayList extract(byte[] data) { + if (pluginHandle_ == 0) + return new ArrayList(0); // fast way out + long list + = extractInternal2(pluginHandle_, + data); + ArrayList ret = convert(list); + freeInternal(list); + return ret; + } + + /** + * Convert a list of keywords in C to an ArrayList + * in Java. + */ + private ArrayList convert(long list) { long pos = list; - Vector res - = new Vector(); + ArrayList res + = new ArrayList(); while (pos != 0) { int type = typeInternal(pos); @@ -214,10 +241,9 @@ public final class Extractor { res.add(new Keyword(type, keyword)); pos = nextInternal(pos); } - freeInternal(list); return res; } - + /* ********************* native calls ******************** */ @@ -228,6 +254,9 @@ public final class Extractor { private static native long extractInternal(long handle, String filename); + private static native long extractInternal2(long handle, + byte[] data); + // free memory allocated by extractInternal private static native void freeInternal(long list); diff --git a/org/gnunet/libextractor/Xtract.java b/org/gnunet/libextractor/Xtract.java @@ -1,6 +1,6 @@ /* This file is part of libextractor. - (C) 2002, 2003, 2004 Vidyut Samanta and Christian Grothoff + (C) 2002, 2003, 2004, 2007 Vidyut Samanta and Christian Grothoff libextractor is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published @@ -19,7 +19,7 @@ */ package org.gnunet.libextractor; -import java.util.Vector; +import java.util.ArrayList; /** * Java version of extract. This is just a tiny demo-application @@ -33,10 +33,10 @@ public final class Xtract { public static void main(String[] args) { Extractor ex = Extractor.getDefault(); for (int i=0;i<args.length;i++) { - Vector keywords = ex.extract(args[i]); + ArrayList keywords = ex.extract(args[i]); System.out.println("Keywords for " + args[i] + ":\n"); for (int j=0;j<keywords.size();j++) - System.out.println(keywords.elementAt(j)); + System.out.println(keywords.get(j)); } // no need to unload, finalizer does the rest... }