This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
[ecj] Patch: FYI: fix VMURLConnection
- From: Tom Tromey <tromey at redhat dot com>
- To: Java Patch List <java-patches at gcc dot gnu dot org>
- Date: 14 Aug 2006 12:07:17 -0600
- Subject: [ecj] Patch: FYI: fix VMURLConnection
- Reply-to: tromey at redhat dot com
I'm checking this in on the gcj-eclipse branch.
This is a straightforward port of Classpath's VMURLConnection native
code to CNI.
Tom
Index: ChangeLog
from Tom Tromey <tromey@redhat.com>
* Makefile.in: Rebuilt.
* Makefile.am (libgcj_la_LIBADD): Add LIBMAGIC.
* java/net/natVMURLConnection.cc: Wrote, based on Classpath.
* configure, config.h.in: Rebuilt.
* configure.ac: Check for magic.h and -lmagic.
Index: configure.ac
===================================================================
--- configure.ac (revision 116131)
+++ configure.ac (working copy)
@@ -1161,6 +1161,10 @@
AC_CHECK_LIB(z, deflate, ZLIBSPEC=-lz, ZLIBSPEC=)
fi
+ LIBMAGIC=
+ AC_CHECK_LIB(magic, magic_open, LIBMAGIC=-lmagic)
+ AC_SUBST(LIBMAGIC)
+
# Test for Gtk stuff, if asked for.
if test "$use_gtk_awt" = yes; then
PKG_CHECK_MODULES(GTK, gtk+-2.0 >= 2.4)
@@ -1321,7 +1325,7 @@
sys/ioctl.h sys/filio.h sys/stat.h sys/select.h \
sys/socket.h netinet/in.h arpa/inet.h netdb.h net/if.h \
pwd.h sys/config.h stdint.h langinfo.h locale.h \
- dirent.h sys/rw_lock.h])
+ dirent.h sys/rw_lock.h magic.h])
AC_CHECK_HEADERS(inttypes.h, [
AC_DEFINE(HAVE_INTTYPES_H, 1, [Define if <inttypes.h> is available])
AC_DEFINE(JV_HAVE_INTTYPES_H, 1, [Define if <inttypes.h> is available])
Index: java/net/natVMURLConnection.cc
===================================================================
--- java/net/natVMURLConnection.cc (revision 116131)
+++ java/net/natVMURLConnection.cc (working copy)
@@ -1,3 +1,11 @@
+/* Copyright (C) 2006 Free Software Foundation
+
+ This file is part of libgcj.
+
+This software is copyrighted work licensed under the terms of the
+Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
+details. */
+
#include <config.h>
#include <java/net/VMURLConnection.h>
@@ -4,15 +12,45 @@
#include <gcj/cni.h>
#include <java/lang/UnsupportedOperationException.h>
+#ifdef HAVE_MAGIC_H
+
+#include <magic.h>
+
+static magic_t cookie;
+
+#endif /* HAVE_MAGIC_H */
+
void
java::net::VMURLConnection::init ()
{
- throw new ::java::lang::UnsupportedOperationException (JvNewStringLatin1 ("java::net::VMURLConnection::init () not implemented"));
+#ifdef HAVE_MAGIC_H
+ cookie = magic_open (MAGIC_MIME);
+ if (cookie == (magic_t) NULL)
+ return;
+ if (magic_load (cookie, NULL) == -1)
+ {
+ magic_close (cookie);
+ cookie = (magic_t) NULL;
+ }
+#endif /* HAVE_MAGIC_H */
}
-
::java::lang::String *
-java::net::VMURLConnection::guessContentTypeFromBuffer (jbyteArray, jint)
+java::net::VMURLConnection::guessContentTypeFromBuffer (jbyteArray bytes,
+ jint valid)
{
- throw new ::java::lang::UnsupportedOperationException (JvNewStringLatin1 ("java::net::VMURLConnection::guessContentTypeFromBuffer (jbyteArray, jint) not implemented"));
+#ifdef HAVE_MAGIC_H
+ const char *result;
+
+ if (cookie == (magic_t) NULL)
+ return NULL;
+
+ result = magic_buffer (cookie, elements(bytes), valid);
+
+ if (result == NULL)
+ return NULL;
+ return _Jv_NewStringUTF (result);
+#else
+ return NULL;
+#endif /* HAVE_MAGIC_H */
}
Index: Makefile.am
===================================================================
--- Makefile.am (revision 116131)
+++ Makefile.am (working copy)
@@ -231,7 +231,7 @@
$(all_packages_source_files:.list=.lo) \
$(bc_objects) \
$(propertyo_files) \
- $(LIBFFI) $(ZLIBS) $(GCLIBS)
+ $(LIBMAGIC) $(LIBFFI) $(ZLIBS) $(GCLIBS)
libgcj_la_DEPENDENCIES = libgcj-$(gcc_version).jar \
$(all_packages_source_files:.list=.lo) \
$(LIBLTDL) $(libgcj_la_LIBADD)