|
10 | 10 | import java.io.InputStream;
|
11 | 11 | import java.time.LocalDateTime;
|
12 | 12 | import java.util.ArrayList;
|
| 13 | +import java.util.Arrays; |
13 | 14 | import java.util.HashMap;
|
14 | 15 | import java.util.concurrent.atomic.AtomicBoolean;
|
15 | 16 |
|
@@ -151,11 +152,13 @@ public void run() {
|
151 | 152 |
|
152 | 153 | private void loadRemoteErlyberly() throws IOException, OtpErlangException {
|
153 | 154 |
|
154 |
| - sendRPC("code", "load_binary", |
| 155 | + OtpErlangBinary otpErlangBinary = new OtpErlangBinary(loadBeamFile()); |
| 156 | + System.out.println("binary size=" + otpErlangBinary.size()); |
| 157 | + sendRPC("code", "load_binary", |
155 | 158 | list(
|
156 | 159 | atom("erlyberly"),
|
157 | 160 | new OtpErlangString(ERLYBERLY_BEAM_PATH),
|
158 |
| - new OtpErlangBinary(loadBeamFile()))); |
| 161 | + otpErlangBinary)); |
159 | 162 |
|
160 | 163 | OtpErlangObject result = receiveRPC();
|
161 | 164 |
|
@@ -186,14 +189,21 @@ private OtpErlangObject receiveRPC() throws IOException, OtpErlangException {
|
186 | 189 |
|
187 | 190 | private static byte[] loadBeamFile() throws IOException {
|
188 | 191 | InputStream resourceAsStream = OtpUtil.class.getResourceAsStream(ERLYBERLY_BEAM_PATH);
|
| 192 | + |
189 | 193 | byte[] b = new byte[BEAM_SIZE_LIMIT];
|
190 |
| - int read = resourceAsStream.read(b); |
191 |
| - |
192 |
| - if(read >= BEAM_SIZE_LIMIT) { |
| 194 | + int total = 0; |
| 195 | + int read = 0; |
| 196 | + |
| 197 | + do { |
| 198 | + total += read; |
| 199 | + read = resourceAsStream.read(b, total, BEAM_SIZE_LIMIT - total); |
| 200 | + } while (read != -1); |
| 201 | + |
| 202 | + if(total >= BEAM_SIZE_LIMIT) { |
193 | 203 | throw new RuntimeException("erlyberly.beam file is too big");
|
194 | 204 | }
|
195 |
| - |
196 |
| - return b; |
| 205 | + |
| 206 | + return Arrays.copyOf(b, total); |
197 | 207 | }
|
198 | 208 |
|
199 | 209 | public synchronized void retrieveProcessInfo(ArrayList<ProcInfo> processes) throws Exception {
|
|
0 commit comments