3
* ====================================================================
4
* Copyright (c) 2003-2004 CollabNet. All rights reserved.
6
* This software is licensed as described in the file COPYING, which
7
* you should have received as part of this distribution. The terms
8
* are also available at http://subversion.tigris.org/license-1.html.
9
* If newer versions of this license are posted there, you may use a
10
* newer version instead, at your option.
12
* This software consists of voluntary contributions made by many
13
* individuals. For exact contribution history, see the revision
14
* history and logs, available at http://subversion.tigris.org/.
15
* ====================================================================
19
* @brief Implementation of the class Outputer
24
#include "JNIByteArray.h"
27
* create an Outputer object
28
* @param jthis the java object to be stored
30
Outputer::Outputer(jobject jthis)
36
* destroy an Inputer object
40
// the m_jthis does not need to be destroyed, because it is the passed
41
// in parameter to the java method.
46
* create a svn_stream_t structure for this object. This will be used as an
47
* output stream by subversion
48
* @param pool the pool, from which the structure is allocated
49
* @return the output stream
51
svn_stream_t *Outputer::getStream(const Pool & pool)
53
// create a stream with this as the baton and set the write and close
55
svn_stream_t *ret = svn_stream_create(this, pool.pool());
56
svn_stream_set_write(ret, Outputer::write);
57
svn_stream_set_close(ret, Outputer::close);
62
* implements svn_write_fn_t to write data out from subversion
63
* @param baton an Outputer object for the callback
64
* @param buffer the buffer for the write data
65
* @param len on input the buffer len, on output the number of written
67
* @return a subversion error or SVN_NO_ERROR
69
svn_error_t *Outputer::write(void *baton, const char *buffer, apr_size_t *len)
71
JNIEnv *env = JNIUtil::getEnv();
72
// an object of our class is passed in as the baton
73
Outputer *that = (Outputer*)baton;
75
// the method id will not change during
76
// the time this library is loaded, so
78
static jmethodID mid = 0;
81
jclass clazz = env->FindClass(JAVA_PACKAGE"/OutputInterface");
82
if(JNIUtil::isJavaExceptionThrown())
86
mid = env->GetMethodID(clazz, "write", "([B)I");
87
if(JNIUtil::isJavaExceptionThrown() || mid == 0)
91
env->DeleteLocalRef(clazz);
92
if(JNIUtil::isJavaExceptionThrown())
98
// convert the data to a java byte array
99
jbyteArray data = JNIUtil::makeJByteArray((const signed char*)buffer, *len);
100
if(JNIUtil::isJavaExceptionThrown())
106
jint written = env->CallIntMethod(that->m_jthis, mid, data);
107
if(JNIUtil::isJavaExceptionThrown())
112
// return the number of bytes written
118
* implements svn_close_fn_t to close the output stream
119
* @param baton an Outputer object for the callback
120
* @return a subversion error or SVN_NO_ERROR
122
svn_error_t *Outputer::close(void *baton)
124
JNIEnv *env = JNIUtil::getEnv();
125
// an object of our class is passed in as the baton
126
Outputer *that = (Outputer*)baton;
128
// the method id will not change during
129
// the time this library is loaded, so
131
static jmethodID mid = 0;
134
jclass clazz = env->FindClass(JAVA_PACKAGE"/OutputInterface");
135
if(JNIUtil::isJavaExceptionThrown())
139
mid = env->GetMethodID(clazz, "close", "()V");
140
if(JNIUtil::isJavaExceptionThrown() || mid == 0)
144
env->DeleteLocalRef(clazz);
145
if(JNIUtil::isJavaExceptionThrown())
151
// call the java object, to close the stream
152
env->CallVoidMethod(that->m_jthis, mid);
153
if(JNIUtil::isJavaExceptionThrown())