diff options
author | Tom Tromey <tromey@gcc.gnu.org> | 2007-01-09 19:58:05 +0000 |
---|---|---|
committer | Tom Tromey <tromey@gcc.gnu.org> | 2007-01-09 19:58:05 +0000 |
commit | 97b8365cafc3a344a22d3980b8ed885f5c6d8357 (patch) | |
tree | 996a5f57d4a68c53473382e45cb22f574cb3e4db /libjava/java/net/natVMURLConnection.cc | |
parent | c648dedbde727ca3f883bb5fd773aa4af70d3369 (diff) | |
download | gcc-97b8365cafc3a344a22d3980b8ed885f5c6d8357.zip gcc-97b8365cafc3a344a22d3980b8ed885f5c6d8357.tar.gz gcc-97b8365cafc3a344a22d3980b8ed885f5c6d8357.tar.bz2 |
Merged gcj-eclipse branch to trunk.
From-SVN: r120621
Diffstat (limited to 'libjava/java/net/natVMURLConnection.cc')
-rw-r--r-- | libjava/java/net/natVMURLConnection.cc | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/libjava/java/net/natVMURLConnection.cc b/libjava/java/net/natVMURLConnection.cc new file mode 100644 index 0000000..3429bb6 --- /dev/null +++ b/libjava/java/net/natVMURLConnection.cc @@ -0,0 +1,56 @@ +/* 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> +#include <gcj/cni.h> +#include <java/lang/UnsupportedOperationException.h> + +#if defined (HAVE_MAGIC_H) && defined (HAVE_MAGIC_OPEN) + +#include <magic.h> + +static magic_t cookie; + +#endif /* HAVE_MAGIC_H && HAVE_MAGIC_OPEN */ + +void +java::net::VMURLConnection::init () +{ +#if defined (HAVE_MAGIC_H) && defined (HAVE_MAGIC_OPEN) + 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 && HAVE_MAGIC_OPEN */ +} + +::java::lang::String * +java::net::VMURLConnection::guessContentTypeFromBuffer (jbyteArray bytes, + jint valid) +{ +#if defined (HAVE_MAGIC_H) && defined (HAVE_MAGIC_OPEN) + 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 && HAVE_MAGIC_OPEN */ +} |