XD02 Read a binary file

Content outdated

We are in the process of migrating all content to impulse version 2.0.

In the reader below, a DataInputStream object is used to read the contents of a binary file. With functions like readInt and readByte you can read primitive types (java style). To apply to a given endianess, functions like Integer.reverseBytes() can be used.

// generator: of ISingleDomainRecordGenerator  (http://toem.de/index.php/projects/impulse/scripts/reference)
// inputStream: input stream of type java.io.InputStream
// console: console output of type MessageConsoleStream
// Init the record
generator.initRecord("Example Record", TimeBase.ns);
var a = generator.addSignal(null, "a", "", ProcessType.Discrete, SignalType.Integer, SignalDescriptor.DEFAULT);
var wa <:IIntegerSamplesWriter:> = generator.getWriter(a);
var current = 0;
try {
    var reader<:DataInputStream:> =  new DataInputStream(inputStream);
    while (true) {
        current += reader.readUnsignedByte(); // 1 byte
        var val = reader.readInt(); // 4 bytes  
        val = Integer.reverseBytes( val); // change endianess
        wa.writeInt(current, false,reader.readInt());
} catch (e) {
    console.println(e); // pass exception object to error handler
generator.close(current + 1);

About the scripted readerOpen JavaDoc Reference

technical software and tooling


Contact Us

This email address is being protected from spambots. You need JavaScript enabled to view it.