forked from stephenquan/DocumentDialogApp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInputStream.cpp
More file actions
138 lines (109 loc) · 3.35 KB
/
Copy pathInputStream.cpp
File metadata and controls
138 lines (109 loc) · 3.35 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
#include <QAndroidJniEnvironment>
#include "InputStream.h"
#include "JniExceptionCheck.h"
//----------------------------------------------------------------------
//
//----------------------------------------------------------------------
InputStream::InputStream(QAndroidJniEnvironment& env, QObject* parent, QAndroidJniObject inputStream) :
QObject(parent),
m_Env(env),
m_InputStream(inputStream)
{
}
//----------------------------------------------------------------------
//
//----------------------------------------------------------------------
InputStream::InputStream(InputStream &&other) :
QObject(nullptr),
m_Env(other.m_Env),
m_InputStream(other.m_InputStream)
{
other.m_InputStream = QAndroidJniObject();
}
//----------------------------------------------------------------------
//
//----------------------------------------------------------------------
InputStream::~InputStream()
{
if (!m_InputStream.isValid())
{
return;
}
close();
}
//----------------------------------------------------------------------
//
//----------------------------------------------------------------------
int InputStream::available()
{
JniExceptionCheck check(m_Env);
if (!m_InputStream.isValid())
{
return 0;
}
jint result = m_InputStream.callMethod<jint>("available", "()I");
return static_cast<int>(result);
}
//----------------------------------------------------------------------
//
//----------------------------------------------------------------------
void InputStream::close()
{
JniExceptionCheck check(m_Env);
if (!m_InputStream.isValid())
{
return;
}
m_InputStream.callMethod<void>("close", "()V");
m_InputStream = QAndroidJniObject();
}
//----------------------------------------------------------------------
//
//----------------------------------------------------------------------
QByteArray InputStream::read(int n)
{
JniExceptionCheck check(m_Env);
if (!m_InputStream.isValid())
{
return QByteArray();
}
QByteArray byteArray;
jbyteArray _byteArray = m_Env->NewByteArray(n);
jint size = m_InputStream.callMethod<jint>("read", "([BII)I", _byteArray, 0, n);
if (size > 0)
{
jboolean isCopy = false;
jbyte* _bytes = m_Env->GetByteArrayElements(_byteArray, &isCopy);
byteArray.append(reinterpret_cast<const char *>(_bytes), static_cast<int>(size));
}
return byteArray;
}
//----------------------------------------------------------------------
//
//----------------------------------------------------------------------
void InputStream::reset()
{
JniExceptionCheck check(m_Env);
if (m_InputStream.isValid())
{
return;
}
m_InputStream.callMethod<void>("reset", "()V");
m_InputStream = QAndroidJniObject();
}
//----------------------------------------------------------------------
//
//----------------------------------------------------------------------
qint64 InputStream::skip(qint64 n)
{
JniExceptionCheck check(m_Env);
if (!m_InputStream.isValid())
{
return 0;
}
jint result = m_InputStream.callMethod<jint>("skip", "(J)J", static_cast<jint>(n));
return static_cast<int>(result);
}
//----------------------------------------------------------------------
//
//----------------------------------------------------------------------