-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDataInputStream.cs
More file actions
170 lines (143 loc) · 2.47 KB
/
DataInputStream.cs
File metadata and controls
170 lines (143 loc) · 2.47 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
using System;
using System.Threading;
using UnityEngine;
public class DataInputStream
{
public myReader r;
private const int INTERVAL = 5;
private const int MAXTIME = 500;
public static DataInputStream istemp;
private static int status;
private static string filenametemp;
public DataInputStream(string filename)
{
TextAsset textAsset = (TextAsset)Resources.Load(filename, typeof(TextAsset));
r = new myReader(ArrayCast.cast(textAsset.bytes));
}
public DataInputStream(sbyte[] data)
{
r = new myReader(data);
}
public static void update()
{
if (status == 2)
{
status = 1;
istemp = __getResourceAsStream(filenametemp);
status = 0;
}
}
public static DataInputStream getResourceAsStream(string filename)
{
return __getResourceAsStream(filename);
}
private static DataInputStream _getResourceAsStream(string filename)
{
if (status != 0)
{
for (int i = 0; i < 500; i++)
{
Thread.Sleep(5);
if (status == 0)
{
break;
}
}
if (status != 0)
{
Debug.LogError("CANNOT GET INPUTSTREAM " + filename + " WHEN GETTING " + filenametemp);
return null;
}
}
istemp = null;
filenametemp = filename;
status = 2;
int j;
for (j = 0; j < 500; j++)
{
Thread.Sleep(5);
if (status == 0)
{
break;
}
}
if (j == 500)
{
Debug.LogError("TOO LONG FOR CREATE INPUTSTREAM " + filename);
status = 0;
return null;
}
return istemp;
}
private static DataInputStream __getResourceAsStream(string filename)
{
try
{
return new DataInputStream(filename);
}
catch (Exception)
{
return null;
}
}
public short readShort()
{
return r.readShort();
}
public int readInt()
{
return r.readInt();
}
public int read()
{
return r.readUnsignedByte();
}
public void read(ref sbyte[] data)
{
r.read(ref data);
}
public void close()
{
r.Close();
}
public void Close()
{
r.Close();
}
public string readUTF()
{
return r.readUTF();
}
public sbyte readByte()
{
return r.readByte();
}
public long readLong()
{
return r.readLong();
}
public bool readBoolean()
{
return r.readBoolean();
}
public int readUnsignedByte()
{
return (byte)r.readByte();
}
public int readUnsignedShort()
{
return r.readUnsignedShort();
}
public void readFully(ref sbyte[] data)
{
r.read(ref data);
}
public int available()
{
return r.available();
}
internal void read(ref sbyte[] byteData, int p, int size)
{
throw new NotImplementedException();
}
}