mirror of
git://gcc.gnu.org/git/gcc.git
synced 2025-01-12 09:44:57 +08:00
27e934d8ba
* configure: Rebuilt. * configure.in: Build include/Makefile. * Makefile.in: Rebuilt. * Makefile.am (SUBDIRS): Added gcj and include. (install-data-local): New target. (extra_headers): New macro. * include/Makefile.in: New file. * include/Makefile.am: New file. * interpret.cc: Don't include gcj/field.h or gcj/cni.h. * java/lang/reflect/natField.cc: Don't include gcj/field.h or gcj/cni.h. * boehm.cc: Don't include java-threads.h or gcj/field.h. * resolve.cc: Include config.h. * defineclass.cc: Include config.h. * include/java-interp.h: Don't include config.h. * include/jvm.h: Include java-threads.h, Object.h, java-gc.h, cni.h. * gcj/javaprims.h: Regenerated namespace decls. * classes.pl (scan): Don't put `;' after closing brace. * Makefile.in: Rebuilt. * Makefile.am (INCLUDES): Added -I for top_srcdir. * configure.in: Create gcj/Makefile. * gcj/Makefile.in: New file. * gcj/Makefile.am: New file. * java/lang/Object.h: Don't include any other headers. * gcj/array.h: Renamed from include/java-array.h. * gcj/field.h: Renamed from include/java-field.h. * gcj/method.h: Renamed from include/java-method.h. * gcj/cni.h, gcj/javaprims.h: Moved from include/. Updated all files to reflect new include structure. From-SVN: r29278
215 lines
4.6 KiB
C++
215 lines
4.6 KiB
C++
// natDeflater.cc - Implementation of Deflater native methods.
|
||
|
||
/* Copyright (C) 1999 Cygnus Solutions
|
||
|
||
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. */
|
||
|
||
// Written by Tom Tromey <tromey@cygnus.com>
|
||
|
||
#include <config.h>
|
||
|
||
#include <zlib.h>
|
||
#include <stdlib.h>
|
||
|
||
#include <gcj/cni.h>
|
||
#include <jvm.h>
|
||
|
||
#include <java/util/zip/Deflater.h>
|
||
#include <java/util/zip/DataFormatException.h>
|
||
|
||
#include <java/lang/InternalError.h>
|
||
#include <java/lang/NullPointerException.h>
|
||
#include <java/lang/ArrayIndexOutOfBoundsException.h>
|
||
|
||
extern void *_Jv_ZMalloc (void *, uInt nitems, uInt size);
|
||
extern void _Jv_ZFree (void *, void *addr);
|
||
|
||
|
||
|
||
jint
|
||
java::util::zip::Deflater::deflate (jbyteArray buf, jint off, jint len)
|
||
{
|
||
JvSynchronize sync (this);
|
||
z_streamp s = (z_streamp) zstream;
|
||
|
||
if (! buf)
|
||
_Jv_Throw (new java::lang::NullPointerException);
|
||
if (off < 0 || len < 0 || off + len > buf->length)
|
||
_Jv_Throw (new java::lang::ArrayIndexOutOfBoundsException);
|
||
|
||
if (len == 0)
|
||
return 0;
|
||
|
||
s->next_out = (Bytef *) (elements (buf) + off);
|
||
s->avail_out = len;
|
||
|
||
switch (::deflate (s, flush_flag))
|
||
{
|
||
case Z_STREAM_END:
|
||
is_finished = true;
|
||
if (s->avail_out == (unsigned int) len)
|
||
return -1;
|
||
break;
|
||
|
||
case Z_STREAM_ERROR:
|
||
case Z_BUF_ERROR:
|
||
// FIXME?
|
||
_Jv_Throw (new java::lang::InternalError);
|
||
break;
|
||
|
||
case Z_OK:
|
||
break;
|
||
}
|
||
|
||
return len - s->avail_out;
|
||
}
|
||
|
||
void
|
||
java::util::zip::Deflater::end ()
|
||
{
|
||
JvSynchronize sync (this);
|
||
// Just ignore errors.
|
||
deflateEnd ((z_streamp) zstream);
|
||
_Jv_Free (zstream);
|
||
zstream = NULL;
|
||
}
|
||
|
||
void
|
||
java::util::zip::Deflater::finish ()
|
||
{
|
||
JvSynchronize sync (this);
|
||
flush_flag = Z_FINISH;
|
||
}
|
||
|
||
jint
|
||
java::util::zip::Deflater::getAdler ()
|
||
{
|
||
JvSynchronize sync (this);
|
||
z_streamp s = (z_streamp) zstream;
|
||
return s->adler;
|
||
}
|
||
|
||
jint
|
||
java::util::zip::Deflater::getTotalIn ()
|
||
{
|
||
JvSynchronize sync (this);
|
||
z_streamp s = (z_streamp) zstream;
|
||
return s->total_in;
|
||
}
|
||
|
||
jint
|
||
java::util::zip::Deflater::getTotalOut ()
|
||
{
|
||
JvSynchronize sync (this);
|
||
z_streamp s = (z_streamp) zstream;
|
||
return s->total_out;
|
||
}
|
||
|
||
jboolean
|
||
java::util::zip::Deflater::needsInput ()
|
||
{
|
||
JvSynchronize sync (this);
|
||
z_streamp s = (z_streamp) zstream;
|
||
return s->avail_in == 0;
|
||
}
|
||
|
||
void
|
||
java::util::zip::Deflater::reset ()
|
||
{
|
||
JvSynchronize sync (this);
|
||
z_streamp s = (z_streamp) zstream;
|
||
// Just ignore errors.
|
||
deflateReset (s);
|
||
flush_flag = 0;
|
||
}
|
||
|
||
void
|
||
java::util::zip::Deflater::setDictionary (jbyteArray buf, jint off, jint len)
|
||
{
|
||
JvSynchronize sync (this);
|
||
z_streamp s = (z_streamp) zstream;
|
||
|
||
if (! buf)
|
||
_Jv_Throw (new java::lang::NullPointerException);
|
||
if (off < 0 || len < 0 || off + len > buf->length)
|
||
_Jv_Throw (new java::lang::ArrayIndexOutOfBoundsException);
|
||
|
||
// Ignore errors.
|
||
deflateSetDictionary (s, (Bytef *) (elements (buf) + off), len);
|
||
}
|
||
|
||
void
|
||
java::util::zip::Deflater::setInput (jbyteArray buf, jint off, jint len)
|
||
{
|
||
JvSynchronize sync (this);
|
||
z_streamp s = (z_streamp) zstream;
|
||
|
||
if (! buf)
|
||
_Jv_Throw (new java::lang::NullPointerException);
|
||
if (off < 0 || len < 0 || off + len > buf->length)
|
||
_Jv_Throw (new java::lang::ArrayIndexOutOfBoundsException);
|
||
|
||
s->next_in = (Bytef *) (elements (buf) + off);
|
||
s->avail_in = len;
|
||
}
|
||
|
||
void
|
||
java::util::zip::Deflater::update ()
|
||
{
|
||
JvSynchronize sync (this);
|
||
z_streamp s = (z_streamp) zstream;
|
||
|
||
int strat = Z_DEFAULT_STRATEGY;
|
||
switch (strategy)
|
||
{
|
||
case DEFAULT_STRATEGY:
|
||
strat = Z_DEFAULT_STRATEGY;
|
||
break;
|
||
case FILTERED:
|
||
strat = Z_FILTERED;
|
||
break;
|
||
case HUFFMAN_ONLY:
|
||
strat = Z_HUFFMAN_ONLY;
|
||
break;
|
||
default:
|
||
JvFail ("unexpected strategy");
|
||
}
|
||
|
||
// Ignore errors.
|
||
deflateParams (s, level, strat);
|
||
}
|
||
|
||
void
|
||
java::util::zip::Deflater::init (jint level, jboolean no_header)
|
||
{
|
||
z_stream_s *stream = (z_stream_s *) _Jv_Malloc (sizeof (z_stream_s));
|
||
stream->next_in = Z_NULL;
|
||
stream->avail_in = 0;
|
||
stream->zalloc = _Jv_ZMalloc;
|
||
stream->zfree = _Jv_ZFree;
|
||
stream->opaque = NULL;
|
||
|
||
// Handle NO_HEADER using undocumented zlib feature.
|
||
int wbits = MAX_WBITS;
|
||
if (no_header)
|
||
wbits = - wbits;
|
||
|
||
#define DEFAULT_MEM_LEVEL 8
|
||
if (deflateInit2 (stream, level, Z_DEFLATED, wbits,
|
||
DEFAULT_MEM_LEVEL, Z_DEFAULT_STRATEGY) != Z_OK)
|
||
{
|
||
jstring msg = NULL;
|
||
if (stream->msg != NULL)
|
||
msg = JvNewStringLatin1 (stream->msg);
|
||
_Jv_Throw (new java::lang::InternalError (msg));
|
||
}
|
||
|
||
zstream = reinterpret_cast<gnu::gcj::RawData *> (stream);
|
||
is_finished = false;
|
||
flush_flag = 0;
|
||
}
|