Skip to content

Commit 336bc3c

Browse files
author
Andy Till
committed
Fixed issue where not only some of the beam file would be read by the
input stream, giving an incomplete beam.
1 parent bed7f6a commit 336bc3c

File tree

3 files changed

+17
-11
lines changed

3 files changed

+17
-11
lines changed

src/main/java/erlyberly/node/NodeAPI.java

+17-7
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import java.io.InputStream;
1111
import java.time.LocalDateTime;
1212
import java.util.ArrayList;
13+
import java.util.Arrays;
1314
import java.util.HashMap;
1415
import java.util.concurrent.atomic.AtomicBoolean;
1516

@@ -151,11 +152,13 @@ public void run() {
151152

152153
private void loadRemoteErlyberly() throws IOException, OtpErlangException {
153154

154-
sendRPC("code", "load_binary",
155+
OtpErlangBinary otpErlangBinary = new OtpErlangBinary(loadBeamFile());
156+
System.out.println("binary size=" + otpErlangBinary.size());
157+
sendRPC("code", "load_binary",
155158
list(
156159
atom("erlyberly"),
157160
new OtpErlangString(ERLYBERLY_BEAM_PATH),
158-
new OtpErlangBinary(loadBeamFile())));
161+
otpErlangBinary));
159162

160163
OtpErlangObject result = receiveRPC();
161164

@@ -186,14 +189,21 @@ private OtpErlangObject receiveRPC() throws IOException, OtpErlangException {
186189

187190
private static byte[] loadBeamFile() throws IOException {
188191
InputStream resourceAsStream = OtpUtil.class.getResourceAsStream(ERLYBERLY_BEAM_PATH);
192+
189193
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) {
193203
throw new RuntimeException("erlyberly.beam file is too big");
194204
}
195-
196-
return b;
205+
206+
return Arrays.copyOf(b, total);
197207
}
198208

199209
public synchronized void retrieveProcessInfo(ArrayList<ProcInfo> processes) throws Exception {
-68 Bytes
Binary file not shown.

src/main/resources/erlyberly/beam/erlyberly.erl

-4
Original file line numberDiff line numberDiff line change
@@ -388,10 +388,6 @@ format_pid(Pid) when is_pid(Pid) ->
388388
format_pid(Port) when is_port(Port) ->
389389
erlang:port_to_list(Port).
390390

391-
%%
392-
log_seq_trace(Seq_trace) ->
393-
io:format("~s ~p~n", [format_utc_timestamp(), Seq_trace]).
394-
395391
%%
396392
format_utc_timestamp() ->
397393
TS = {_,_,Micro} = os:timestamp(),

0 commit comments

Comments
 (0)