Repository navigation
Expand file tree
/
Copy pathTMLRecStream.java
More file actions
227 lines (207 loc) · 7.31 KB
/
Copy pathTMLRecStream.java
File metadata and controls
227 lines (207 loc) · 7.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
/*
* libTML: A BEEP based Messaging Suite
* Copyright (C) 2015 wobe-systems GmbH
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1
* of the License, or (at your option) any later version.
*
* This program 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this program; if not, write to the Free
* Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
* 02111-1307 USA
*
* You may find a copy of the license under this software is released
* at COPYING file. This is LGPL software: you are welcome to develop
* proprietary applications using this library without any royalty or
* fee but returning back any change, improvement or addition in the
* form of source code, project image, documentation patches, etc.
*
* Homepage:
* http://www.libtml.org
*
* For professional support contact us:
*
* wobe-systems GmbH
*/
package com.tmlsidex.tml;
import java.nio.ByteBuffer;
import com.tmlsidex.jni.SidexErr;
import com.tmlsidex.jni.Tml;
import com.tmlsidex.jni.TmlJniRecStreamDldBlockHandlerIF;
import com.tmlsidex.jni.TmlJniRecStreamDldFinishHandlerIF;
import com.tmlsidex.jni.TmlSidexException;
/**
* @ingroup tmlClasses
* @brief TML stream receiver
*
* The TMLRecStream object provides an interface to a TML receiver stream and its data.
* It is connected to a sender stream on another peer.
*/
public class TMLRecStream extends Object implements TmlJniRecStreamDldBlockHandlerIF,
TmlJniRecStreamDldFinishHandlerIF{
// Member
long m_StreamID = 0;
Tml m_tml = null;
long m_coreHandle = 0;
String m_sProfile = null;
TMLProfile m_profile = null;
/**
* @brief stream download block handler implementation
*
* The handler implements the low level interface and calls the
* the high level handler method.
*
* @see com.tmlsidex.tml.TMLRecStreamDldBlockHandlerIF
*/
@Override
public int jniRecStreamDldBlockCB(long iID, Object cbData, byte[] buffer, int bytesRead, long totalBytesRead, long streamSize) {
int iRet = -1;
Object[] objArr = (Object[]) cbData;
if (null != objArr[0]){
iRet = ((TMLRecStreamDldBlockHandlerIF) objArr[0]).recStreamDldBlock(iID, objArr[1], buffer, bytesRead, totalBytesRead, streamSize);
}
return iRet;
}
/**
* @brief stream download finish handler implementation
*
* The handler implements the low level interface and calls the
* the high level handler method.
*
* @see com.tmlsidex.tml.TMLRecStreamDldFinishHandlerIF
*/
@Override
public void jniRecStreamDldFinishCB(long iID, int iError, Object cbData) {
Object[] objArr = (Object[]) cbData;
if (null != objArr[0]){
((TMLRecStreamDldFinishHandlerIF) objArr[0]).recStreamDldFinish(iID, iError, objArr[1]);
}
}
/**
* @brief constructs a TMLRecStream instance
*
* @param profile profile instance
* @param streamID clear stream identification
* @param sIP hostname or IP address
* @param sPort port number
*
* @throws TmlSidexException
*/
public TMLRecStream(TMLProfile profile, long streamID, String sIP, String sPort) throws TmlSidexException{
m_tml = new Tml();
m_StreamID = streamID;
m_profile = profile;
m_coreHandle = m_profile.getCHandle();
m_sProfile = m_profile.getProfileUrl();
m_tml.tml_RecStream_Open(m_coreHandle, m_StreamID, m_sProfile, sIP, sPort);
}
/**
* @brief destructor
*/
protected void finalize() throws Throwable {
// Internal destructrion:
m_tml.tml_RecStream_Close(m_coreHandle, m_StreamID, false);
m_tml = null;
super.finalize();
}
/**
* @brief get stream identification
*
* @return steamID
*/
public long getStreamID(){
return m_StreamID;
}
/**
* @brief get stream position
*
* @return actual stream position
*
* @throws TmlSidexException
*/
public long getPosition() throws TmlSidexException{
return m_tml.tml_RecStream_GetPosition(m_coreHandle, m_StreamID);
}
/**
* @brief get stream size in bytes
*
* @return stream size
*
* @throws TmlSidexException
*/
public long getSize() throws TmlSidexException{
return m_tml.tml_RecStream_GetSize(m_coreHandle, m_StreamID);
}
/**
* @brief read a buffer from the stream
*
* @param buffer returns the read content
* @param count number of bytes to read
*
* @return number of bytes read (can be smaller than count if stream ends)
*
* @throws TmlSidexException
*/
public int read(ByteBuffer buffer, int count) throws TmlSidexException{
return m_tml.tml_RecStream_Read(m_coreHandle, m_StreamID, buffer, count);
}
/**
* @brief move to stream position (seek)
*
* @param seekPos position in stream
* @param origin offset origin
*
* <br><br>soFromBeginning (0) / from start of stream / seekPos > 0
* <br>soFromCurrent (1) / from current position /
* <br>soFromEnd (2) / from end of stream / seekPos < 0
*
* @throws TmlSidexException
*/
public void seek(long seekPos, int origin) throws TmlSidexException{
m_tml.tml_RecStream_Seek(m_coreHandle, m_StreamID, seekPos, origin);
}
/**
* @brief write data to a stream
*
* @param buffer buffer containing data
* @param count number of bytes to write
*
* @throws TmlSidexException
*/
public void write(byte[] buffer, int count) throws TmlSidexException{
m_tml.tml_RecStream_Write(m_coreHandle, m_StreamID, buffer, count);
}
/**
* @brief start a full download of a stream
*
* @param buffersize size of download buffer
* @param cbDldBlockInstance instance of an implementation of the download block callback method interface
* @param pCBDataDld custom data or null / buffer reception handler
* @param cbDldFinishInstance instance of an implementation of the download finish callback method interface
* @param pCBDataDldFinish custom data or null / download finished handler
*
* @throws TmlSidexException
*/
public void downloadData(int buffersize, TMLRecStreamDldBlockHandlerIF cbDldBlockInstance, Object pCBDataDld,
TMLRecStreamDldFinishHandlerIF cbDldFinishInstance, Object pCBDataDldFinish) throws TmlSidexException{
if (null != cbDldBlockInstance && null != cbDldFinishInstance){
Object[] objArrDld = new Object[2];
objArrDld[0] = cbDldBlockInstance;
objArrDld[1] = pCBDataDld;
Object[] objArrDldFinish = new Object[2];
objArrDldFinish[0] = cbDldFinishInstance;
objArrDldFinish[1] = pCBDataDldFinish;
m_tml.tml_RecStream_DownloadData(m_coreHandle, m_StreamID, buffersize,
this, objArrDld,
this, objArrDldFinish);
}
}
}