-
-
Notifications
You must be signed in to change notification settings - Fork 142
Expand file tree
/
Copy pathStringConversionTest.java
More file actions
111 lines (81 loc) · 2.64 KB
/
StringConversionTest.java
File metadata and controls
111 lines (81 loc) · 2.64 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
package com.tns.tests;
import java.io.InputStream;
import android.content.Context;
import android.content.res.AssetFileDescriptor;
import android.content.res.AssetManager;
public class StringConversionTest {
public final String s;
public StringConversionTest() throws Exception {
this.s = readString();
}
public String getString() {
return this.s;
}
public String getString(int notUsed) {
return this.s;
}
public String getString(byte notUsed) {
return this.s;
}
public int getLength() {
return this.s.length();
}
public boolean equalsString(String other) throws Exception {
byte[] thisBytes = this.s.getBytes("UTF-8");
byte[] otherBytes = other.getBytes("UTF-8");
boolean isEqualsString = thisBytes.length == otherBytes.length;
int i = 0;
if (isEqualsString) {
for (; i < thisBytes.length; i++) {
isEqualsString = thisBytes[i] == otherBytes[i];
if (!isEqualsString) {
break;
}
}
}
return isEqualsString;
}
public String[] getStringArr() {
return new String[10];
}
public boolean equalsLength(String other) {
int thisLength = this.s.length();
int otherLength = other.length();
return thisLength == otherLength;
}
public void triggerCallback() {
this.callback(this.s);
}
public void callback(String str) {
}
private String readString() throws Exception {
String str = null;
Context context = com.tns.TestNativeScriptApplication.getInstance();
InputStream inputStream = null;
try {
String assetName = "app/tests/image.jpg";
int fileLength = 0;
AssetFileDescriptor fd = null;
try {
fd = context.getAssets().openFd(assetName);
fileLength = (int)fd.getLength();
} finally {
if (fd != null) {
fd.close();
}
}
inputStream = context.getAssets().open(assetName, AssetManager.ACCESS_STREAMING);
byte[] data = new byte[fileLength];
inputStream.read(data);
str = android.util.Base64.encodeToString(data, android.util.Base64.DEFAULT);
// This is not correct - the raw image data is NOT UTF-8 string
// TODO: Discuss
//str = new String(data, "UTF-8");
} finally {
if (inputStream != null) {
inputStream.close();
}
}
return str;
}
}