diff options
-rw-r--r-- | ChangeLog | 12 | ||||
-rw-r--r-- | configure.ac | 7 | ||||
-rw-r--r-- | include/Makefile.am | 3 | ||||
-rw-r--r-- | include/java_net_VMURLConnection.h | 22 | ||||
-rw-r--r-- | java/net/URLConnection.java | 10 | ||||
-rw-r--r-- | native/jni/java-net/Makefile.am | 3 | ||||
-rw-r--r-- | native/jni/java-net/java_net_VMURLConnection.c | 90 | ||||
-rw-r--r-- | vm/reference/java/net/VMURLConnection.java | 79 |
8 files changed, 219 insertions, 7 deletions
@@ -1,3 +1,15 @@ +2006-05-26 Tom Tromey <tromey@redhat.com> + + * configure.ac: Check for magic.h and -lmagic. + * vm/reference/java/net/VMURLConnection.java: New file. + * include/java_net_VMURLConnection.h: New file. + * include/Makefile.am (H_FILES): Add VMURLConnection.h. + ($(top_srcdir)/include/java_net_VMURLConnection.h): New target. + * native/jni/java-net/Makefile.am (libjavanet_la_SOURCES): + Mention new file. + (libjavanet_la_LIBADD): Add $(LIBMAGIC). + * native/jni/java-net/java_net_VMURLConnection.c: New file. + 2006-05-26 Thomas Fitzsimmons <fitzsim@redhat.com> * tools/Makefile.am (installcheck-binSCRIPTS): Do nothing. diff --git a/configure.ac b/configure.ac index bdd30893a..c4b8412dd 100644 --- a/configure.ac +++ b/configure.ac @@ -289,7 +289,8 @@ if test "x${COMPILE_JNI}" = xyes; then sys/select.h \ crt_externs.h \ fcntl.h \ - sys/mman.h]) + sys/mman.h \ + magic.h]) AC_EGREP_HEADER(uint32_t, stdint.h, AC_DEFINE(HAVE_INT32_DEFINED, 1, [Define to 1 if you have uint32_t])) AC_EGREP_HEADER(uint32_t, inttypes.h, AC_DEFINE(HAVE_INT32_DEFINED, 1, [Define to 1 if you have uint32_t])) @@ -307,6 +308,10 @@ if test "x${COMPILE_JNI}" = xyes; then mmap munmap mincore msync madvise getpagesize sysconf \ ]) + LIBMAGIC= + AC_CHECK_LIB(magic, magic_open, LIBMAGIC=-lmagic) + AC_SUBST(LIBMAGIC) + AC_HEADER_TIME AC_STRUCT_TM AC_STRUCT_TIMEZONE diff --git a/include/Makefile.am b/include/Makefile.am index 8b43e31cb..783ba18ee 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -135,6 +135,7 @@ $(top_srcdir)/include/java_lang_VMSystem.h \ $(top_srcdir)/include/java_lang_reflect_VMArray.h \ $(top_srcdir)/include/java_net_VMInetAddress.h \ $(top_srcdir)/include/java_net_VMNetworkInterface.h \ +$(top_srcdir)/include/java_net_VMURLConnection.h \ $(top_srcdir)/include/java_nio_VMDirectByteBuffer.h \ $(top_srcdir)/include/java_nio_MappedByteBufferImpl.h \ $(top_srcdir)/include/java_util_VMTimeZone.h @@ -196,6 +197,8 @@ $(top_srcdir)/include/java_net_VMInetAddress.h: $(top_srcdir)/vm/reference/java/ $(JAVAH) -o $@ java.net.VMInetAddress $(top_srcdir)/include/java_net_VMNetworkInterface.h: $(top_srcdir)/vm/reference/java/net/VMNetworkInterface.java $(JAVAH) -o $@ java.net.VMNetworkInterface +$(top_srcdir)/include/java_net_VMURLConnection.h: $(top_srcdir)/vm/reference/java/net/VMURLConnection.java + $(JAVAH) -o $@ java.net.VMURLConnection $(top_srcdir)/include/java_nio_VMDirectByteBuffer.h: $(top_srcdir)/vm/reference/java/nio/VMDirectByteBuffer.java $(JAVAH) -o $@ java.nio.VMDirectByteBuffer $(top_srcdir)/include/java_nio_MappedByteBufferImpl.h: $(top_srcdir)/java/nio/MappedByteBufferImpl.java diff --git a/include/java_net_VMURLConnection.h b/include/java_net_VMURLConnection.h new file mode 100644 index 000000000..270a14a75 --- /dev/null +++ b/include/java_net_VMURLConnection.h @@ -0,0 +1,22 @@ +/* DO NOT EDIT THIS FILE - it is machine generated */ + +#ifndef __java_net_VMURLConnection__ +#define __java_net_VMURLConnection__ + +#include <jni.h> + +#ifdef __cplusplus +extern "C" +{ +#endif + +JNIEXPORT void JNICALL Java_java_net_VMURLConnection_init (JNIEnv *env, jclass); +JNIEXPORT jstring JNICALL Java_java_net_VMURLConnection_guessContentTypeFromBuffer (JNIEnv *env, jclass, jbyteArray, jint); +#undef java_net_VMURLConnection_LENGTH +#define java_net_VMURLConnection_LENGTH 1024L + +#ifdef __cplusplus +} +#endif + +#endif /* __java_net_VMURLConnection__ */ diff --git a/java/net/URLConnection.java b/java/net/URLConnection.java index 86f449cfc..28142b10a 100644 --- a/java/net/URLConnection.java +++ b/java/net/URLConnection.java @@ -38,7 +38,6 @@ exception statement from your version. */ package java.net; -import gnu.classpath.NotImplementedException; import gnu.classpath.SystemProperties; import java.io.IOException; @@ -971,11 +970,12 @@ public abstract class URLConnection * @exception IOException If an error occurs */ public static String guessContentTypeFromStream(InputStream is) - throws IOException, NotImplementedException + throws IOException { - // See /etc/gnome-vfs-mime-magic or /etc/mime-magic for a reasonable - // idea of how to handle this. - return "application/octet-stream"; + String result = VMURLConnection.guessContentTypeFromStream(is); + if (result == null) + return "application/octet-stream"; + return result; } /** diff --git a/native/jni/java-net/Makefile.am b/native/jni/java-net/Makefile.am index e48173a16..26bb64f73 100644 --- a/native/jni/java-net/Makefile.am +++ b/native/jni/java-net/Makefile.am @@ -12,11 +12,12 @@ libjavanet_la_SOURCES = javanet.c \ javanet.h \ java_net_VMInetAddress.c \ java_net_VMNetworkInterface.c \ + java_net_VMURLConnection.c \ gnu_java_net_VMPlainDatagramSocketImpl.c \ gnu_java_net_VMPlainSocketImpl.c \ $(local_sources) -libjavanet_la_LIBADD = $(top_builddir)/native/jni/classpath/jcl.lo +libjavanet_la_LIBADD = $(top_builddir)/native/jni/classpath/jcl.lo $(LIBMAGIC) AM_LDFLAGS = @CLASSPATH_MODULE@ AM_CPPFLAGS = @CLASSPATH_INCLUDES@ diff --git a/native/jni/java-net/java_net_VMURLConnection.c b/native/jni/java-net/java_net_VMURLConnection.c new file mode 100644 index 000000000..d93cef2b4 --- /dev/null +++ b/native/jni/java-net/java_net_VMURLConnection.c @@ -0,0 +1,90 @@ +/* VMURLConnection.c - native bits for URLConnection + Copyright (C) 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +#include <config.h> + +#include <java_net_VMURLConnection.h> + +#ifdef HAVE_MAGIC_H + +#include <magic.h> + +static magic_t cookie; + +#endif /* HAVE_MAGIC_H */ + +void +Java_java_net_VMURLConnection_init (JNIEnv *env, jclass klass) +{ +#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 */ +} + +jstring +Java_java_net_VMURLConnection_guessContentTypeFromBuffer (JNIEnv *env, + jclass klass, + jbyteArray bytes, + jint valid) +{ +#ifdef HAVE_MAGIC_H + jbyte *elements; + const char *result; + + if (cookie == (magic_t) NULL) + return NULL; + + elements = (*env)->GetByteArrayElements (env, bytes, NULL); + result = magic_buffer (cookie, elements, valid); + + /* The mode we use doesn't matter, since we don't change the array. */ + (*env)->ReleaseByteArrayElements (env, bytes, elements, JNI_ABORT); + + if (result == NULL) + return NULL; + return (*env)->NewStringUTF (env, result); +#else + return NULL; +#endif /* HAVE_MAGIC_H */ +} diff --git a/vm/reference/java/net/VMURLConnection.java b/vm/reference/java/net/VMURLConnection.java new file mode 100644 index 000000000..e03396fef --- /dev/null +++ b/vm/reference/java/net/VMURLConnection.java @@ -0,0 +1,79 @@ +/* VMURLConnection - VM code for URLConnection + Copyright (C) 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package java.net; + +import gnu.classpath.Configuration; + +import java.io.IOException; +import java.io.InputStream; + +public class VMURLConnection +{ + public static final int LENGTH = 1024; + + static + { + if (Configuration.INIT_LOAD_LIBRARY) + System.loadLibrary("javanet"); + init(); + } + + private static native void init(); + + private static native String guessContentTypeFromBuffer(byte[] b, int valid); + + /** + * This is called from URLConnection to guess the mime type of a + * stream. This method may return null to indicate that it could + * not guess a type. + */ + static String guessContentTypeFromStream(InputStream is) + throws IOException + { + if (! is.markSupported()) + return null; + is.mark(LENGTH); + byte[] bytes = new byte[LENGTH]; + int r = is.read(bytes); + if (r < 0) + return null; + is.reset(); + return guessContentTypeFromBuffer(bytes, r); + } +} |